Cocoa Broke My Brain

Just another Blog on iOS development

Please avoid singletons for network requests

I was recently in a situation where I was trying to work out why my multiple async tasks had one of them being killed mid flight. Well it turns out the singleton that was created to manage requests to multiple URL’s was killing all inflight requests it was managing in it’s own queue. The moral of the story when you are using code that was previously built only for iPhone and is now being used in iPad be prepared for odd things like this. On iPad you can have multiple async web calls going on one screen which you most likely wouldn’t have on iPhone. So anyway now I am using my View controller to manage the lifecycle of that web request post creation. Instead of relying on a singleton to do it.

My rant over!

Working on an opensource project

I was a little bored and thought I would invest some time in an opensource project. There was a project on github which was replicating the Instragram photo picker. I created a fork of the project on github and implemented Album browsing and selecting. Also updated the styling a bit. Originally it just looked at an aggregated list of photo’s.

Screenshot02iOS Simulator Screen Shot 5 Jun 2015 9.33.25 am


Enjoy the project. It is available at InstagramPhotoPicker

Jenkins not able to start iOS Simulator on Yosemite

Recently I was involved in getting calabash automation tests running on Jenkins and ran into a problem with the simulator. If you see this error:

Failed to authorize rights (0x1) with status: -60007. 2015-05-27 11:06:32.998 instruments[89714:3936018] -[XRSimulatorDevice prepareConnection:]: Unable to authorize simulated daemon (89737): 8

It basically means that you have configured your Jenkins instance to be started up as either a LaunchDaemon or LaunchAgent this didn’t use to cause a problem but on yosemite it does. The only way I found to get around this was to create an Automation application which runs the Jenkins process on user login. The bad thing is if you reboot your CI Mac box you will need to make sure you log the user in to get Jenkins to startup.

The following are the steps to perform this:

  1. Launch Applications -> Automator
  2. On Launch select New Document
  3. Choose the Application options
    Screen Shot 2015-05-27 at 2.22.32 pm
  4. Then under Library select Utilities and then Run Shell Script
    Screen Shot 2015-05-27 at 2.23.31 pm
  5. Then in the Shell script box enter your run details. I have included an example:
    Screen Shot 2015-05-27 at 2.24.15 pm
    export JENKINS_HOME=/Users/Shared/Jenkins/Home
    /Library/Application\ Support/Jenkins/ &> /var/log/jenkins/jenkins.log &

  6. Then save it via File -> Save and give it a name
  7. Then goto System Preferences -> Users & Groups
  8. Select your user in the list and then click on Login Items tab
  9. From there click the + and add your automation script and enable it
  10. From there the jenkins application will always startup on user login.

Global UIKeyboard Dismiss

I recently ran into this problem where my user had brought up the keyboard on a field in a totally different view on my screen. They then went on to click on a button to bring up a UIPopover. The keyboard remained up which pushed the whole UIPopover up. To get around this problem I found like a top level resign responder method. This will dismiss the keyboard no matter how deep I am in the view hierarchy of my app.


Once your App is in the App Store

So you have finished testing your app out in the wild and you are ready to get it submitted into the App Store. There are a few tools that you can use once you are out in the wild which will let you know when things have gone wrong and what people are doing in your App and how often.

When things go wrong
When an application crashes out in the wild and you need to know why. There is a awesome tool called Crashlytics. It will log the details of the error and how often it is happening. It will also let you know things like:

  • Device it happened on
  • Battery Status
  • Orientation of Device
  • Jailbreak status
  • Were they on a Wi-Fi Network

This tool is invaluable to debug those nasty crashes out in the App wild. The tool is even free to use. All data that is broadcast over the network is SSL encrypted. Standard obfuscation rules apply to your iOS apps if you are dealing with private user data.

Know how and when your App is used
Okay so you want to know, how and when a user uses your App. You are going to need some analytics embedded in there. Analytics are very important to a Mobile App and will let you know now only how a user engages with your application but also if you have any In-App purchases what is being bought, when and what type of device was it bought on.

These are just a few of the things you can do with in App analytics. When adding analytics to your App it is very important that you don’t just tack it in. You really need to sit down and work out what you want to track and how you want to track it. Also what is important for you to measure the success of the App or have you can make your App succeed.

So I guess onto the choice of platforms for mobile analytics. There are two that come to my mind Google Analytics and Flurry. Google Analytics has come a long way and I would recommend it. Also it seems to better visually represent the data. Anyway check the two out and make what you think is the best choice.

Some Links to What was mentioned

  • (Is free to use, keeps track of when things go wrong, give great detail around it)
  • Google Mobile Analyics (Is free to use and can even track In-App purchases, also can do some crash analytics stuff.)

Wearable Devices it is heating up in 2013

What is happening now?

2013 has been the year of the wearable device. The market is really hotting up and a lot of different products are coming out. Wearable devices are no longer for your IT techie geeks out there. Businesses are now investing some of there R&D into turning there product into a stylish fashion accessory. This has made wearable devices stylish and made them not seen as just a IT techie must have.

You might ask yourself now, where does this momentum come from? A lot of this wearable device goodness has come from crowd funding websites like:

These sites have allowed what were just concepts and prototypes to get the kind of funding they needed to become a commercially viable and sellable product. As well as provide backers feedback on the progress of what they have backed. A good example of this is the second most highly crowd-funded project of all time as of now the “Pebble‘ which got $10 million from kickstarter. The “Pebble” is a smart watch which uses bluetooth on your Android or iPhone to:

  • Control music
  • Upload custom watch faces
  • Integrate with native Apps
  • Provide Caller ID and Message notifications


A picture of Pebble controlling music

The next question is where is all this tech going?

A lot of the wearable devices that are coming out to market at the moment are focused mainly at the health and fitness industry. They allow people to wear devices on there body which can track:

  • How they exercise
  • distance travelled
  • calories burned
  • Monitor how long and how well you sleep

A good example of this is Fitbit which recently received $43 million in venture capital funding to further grow there digital fitness tracker and health devices product catalog beyond just Fitbit.


A picture of Fitbit device

But we are starting to see a lot of devices coming out which are focused more in the visionary area (Google glass, Meta glasses) and are using concepts like AR to overlay relevant information to the consumer. Examples of this are:

  • Overlaid navigation
  • Virtual tourism
  • POV (Point of View) videography and photography
  • Information Overlay

Finally what can you as a developer do with these devices?
A lot of these devices don’t necessarily have a software ecosystem accompanying them. Instead the businesses behind them are providing SDK’s for developers (in most cases free) to create there own applications or integrate into existing ones which can easily tap into the features of the devices they are building. This means they can focus on the core product and allow the developer community out there to create there software ecosystem for them and build some interesting software based concepts utilising the technology.

You may ask what types of languages will I need to learn to develop for these devices. Just a few are:

  • C
  • C++
  • Javascript
  • Python
  • Java
  • Unity 3D

As you can see because you are getting potentially to such a low level in some cases you will need to brush up on your C and C++ coding abilities. This just means the usual advantages that other languages give you may not be able to be enabled on such a small and potentially not very powerful device.

Well that is a wrap for the article. If you have anymore questions around Wearable Devices or how any devices which exist on the market now could be integrated into your business somehow. Don’t hesitate in getting in contact with me.

My Development and Continuous Delivery Process

I have been working as a iOS developer for a few years now and the question that has always hit me remains. How do you do continuous integration with Mobile Apps and how do you keep track of code quality in iOS like they do in the Java world? Well there are a lot of tools out there now which can help you not only automate the buildtestdeploy phase but also give you some static code analysis while at it. One other question that I constantly ponder is what tools can I use as an iOS developer to improve my ability to not only code but also produce code to a specific standard? Below I have separated into categories what makes up the end to end production of a iOS application, the tools and how I use them in each category.
There are even a few tools that I use to assist me with iOS development. I use Alcatraz which is an Awesome package management tool for Xcode. It allows you to centrally install iOS project templates, Xcode Themes and extra plugins based on ruby specs. I use Uncrustify to beautify my code and keep it inline to a certain coding style. That way all code is in the same format and anyone else using Uncrustify will keep there code in check with the decided upon style. I use CocoaPods to manage library dependencies very similar to Maven in the Java world. CocoaPods is an alternative to using git submodules so if you are still stuck on SVN you should probable use it as opposed to checking in libraries to the source. Also CocoaPods creates a nice workspace and lays out your Libraries in a nice manner in your project file. While using git submodules it is up to you to do this. The only problem I have with it is that sometimes the maintainer of the Pod might delete there version which you are linking to or even the library in question. So you might have to manage library updates more frequently. Or as an alternative create your own fork of that library in somewhere like github and link your project to it via git submodules. So sometimes a mashed up approach isn’t bad.
Some Xcode plugins I use are:
  • DerivedData Eliminator (Allows you to add a button to the IDE to remove derived data as opposed to the multiple key strokes required)
  • VVDocumentor (Creates a Javadoc style comment template for methods etc. Usual for if you use doxygen)
  • Uncrustify Plugin (Allows you to apply uncrustify to current active file or entire project)
  • JDPluginManager (Allows you to easily update your plugins. Alcatraz doesn’t support this yet)
Links to the Tools
The build phase is usually when you look at running some code analysis and failing out if there are any errors. Some useful tools that I have been playing around with as part of the CI process which is OClint. It is a really good tool which can be used to output some reports around your code. The reports can be setup to output into PMD format so that they can be easily viewable in your build plans via Jenkins or Bamboo CI servers.
Also Gradle is a really good alternative to a Rakefile if you want to create a really powerful build script which can automate OClint usage and automation of building the code on a Mac mini build server.
Links to Tools
Testing is the most overlooked part of iOS development and is usually not to a high level on a majority of projects I have worked on. Especially if your projects budget is finite. I have a swag load of tools which I have used or looked at which can not only help you better Unit Test your code but also output those tests in a meaningful way which can be easily visualised in your CI servers build console. OCMock is a great tool which allows you to create mock interfaces and test out the the behaviour of your application under different cases. OCUnit2JUnit is a must use tool which can convert the output of your unit tests from Xcode into JUnit XML format so that it can be displayed in your CI server. The Sonar Objective C plugin is another good plugin. It allows you to run some analytics on your codebase and have them displayed in Sonar which is normally for Java projects. It doesn’t cover all the metrics but covers enough to fill in the gaps around your source code. Zucchini is a testing tool which allows you to integrate with Apples UIAutomation framework easily. This can then all run on your CI server. Test reports are generated in TAP format. So you will want the right plugin for you CI server.
The fun part of the process is getting your app out there into the wild. My tool of choice would be test flight app which also supports android now. It has some really good features like remote logging and also in app checkpoints. You can setup gradle to auto deploy up to test flight as well. So if all your quality checks have passed you can auto upload to test flight.
Links to Tools

Fix Duplicate/Old Items on “Open with…” on Mountain Lion

While deciding to move from textmate to sublime as my text editor of choice. I noticed that I now had multiple open with options appearing in my right-click menu.

I went on the internet and found this snippet that can fix the problem. By using a terminal window:

LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local\
-domain system -domain user

All you have to do is copy and paste this into Terminal and run it… (note: it takes a little bit of time for it to run so be patient)

Relaunch Finder (control+option+click on Finder icon in the Dock)…

Ta-da! The duplicate or old items are now gone!

Fixing Microsoft Communicator/Lync Support on Adium 1.5.4 with Mac OS 10.8 Mountain Lion

The following are steps that I used to fix my support for Microsoft Communicator on my install of Adium on my Mac. Enjoy!

  1. Delete SIPE plugin if you already have it installed
  2. Quit Adium
  3. Download and Unzip SIPE Plugin Located here:
  4. Double Click Plugin which will automatically install Plugin and start up Adium
  5. Quit Adium again
  6. Create the following Symlinks with in the /Applications/ directory:
    ln -s Current /Applications/
    ln -s Current /Applications/
    ln -s Current /Applications/
  7. Add your Office Communicator Account settings back and you should be able to connect again.

How do you build the UI when the API doesn’t exist yet?

Recently I have been involved on a project where we needed to build a mobile application within 2 weeks. The project needs to access an API which doesn’t exist yet and it all needs to come together at the end with minimal testing and minimal integration refactoring.

You are probably thinking this is all impossible. Well it can be done but not easily. All you need to do is be persistant.

  1. First create an initial API contract and data model
  2. Create code from initial API contract and mock the call backs.
  3. Generate mock data as close as possible to what the API will provide.
  4. Try not to make changes to the API as much as possible. (Adding fields is easier then complete redesign)
  5. Keep probing the API developer on when they have finished so you can start testing integration.

Following this pattern although not fool proof can make it doable to develop an API and UI at the same time.


Get every new post delivered to your Inbox.

Join 302 other followers