Ad

Our DNA is written in Swift
Jump

CoreLocation Background Update Messaging

Two years ago I put together revolutionary chart that detailed the flow of delegate messages when sending an app into background. This was even featured by Erica Sadun of TUAW because it for the first time visualized the whole process in a easy to understand way.

Based on this chart Carl Brown from PDAgent made an addendum to deal with the special case of background region updates and sent it to me. To my shame I have to admit that it was sitting at the bottom of my inbox for 4 months now and it is only now that in my effort to reach Inbox Zero I am dealing with this and putting it up here for your viewing pleasure.

This is the original flow as it was current with iOS 4 and I think it is also mostly true for iOS 5.

And here is Carl’s CoreLocation addendum. I had originally planned to merge this flow chart with the original one, but it was not immediately obvious to me how I could achieve that in a visually pleasing way.

Though maybe it would be smarter to keep them separate because they deal with different subsystems.

Carl reported these findings from his experiments:

The weird thing about the Core Location Delegate events is that you get application:didFinishLaunchingWithOptions: but it isn’t followed by applicationDidBecomeActive: or applicationWillEnterForeground: or applicationDidEnterBackground: – which is something I didn’t expect.

The other odd thing is that if you double-tap the home button and use the task manager to Kill-9 the App, the next Core Location notification will launch the App again, but the App will not  re-appear in the recently used Apps list (as revealed by double-tapping the home button), so the user can’t kill the app again (at least not without launching it by hand first). So it becomes an effectively unkillable App (which makes your memory leaks way worse).

So the most important info here seems to be that an app activated from a background location update neither becomes active nor enters any fore- or background. Which makes sense because we don’t want the app to pop to the front just because we have moved. It should be the user’s decision whether he would want to reopen the app. The OS will then make sure to take either the already running (or restarted) instance from the background or launch the app if it got terminated.

Out of curiosity I still would love to merge both flow charts into one “ultimate” one. If you’re good with OmniGraffle then you can take a shot if you like to try, email me and I’ll send you the graffle files.


Categories: Q&A

3 Comments »

  1. I’m assuming you can post a local notification in your locationManager callbacks .. that would make it relatively easy for the user to get to your app when they get to or leave the location you’re interested in. (This is what the Reminders app does).

  2. Or you can download RSS feeds/news when you get to a certain location, as some apps like Instapaper do it.