iOS launch-on-boot apps: fact or fiction?
Hanging out on StackOverflow the other day, I came across this little gem of a question: Can iPhone apps start on start-up?
I was a bit surprised at the rather unequivocal answers most people were giving: one comment says,
I don’t think they do, look at Skype for example. There are even “jailbreak” apps that start these kind of apps for you.
An answerer to the question even posted almost immediately, garnering a number of upvotes and becoming (for a short time) the top answer:
Without jailbreaking the device, it is not possible to automatically start an app on start-up - except for Apps from Apple. I have no official reference for this, but just ask the mentioned person to demonstrate how to do this (he likely won’t).
First off, that’s a terrible reason to assert something: the fact that some given person won’t sit down and hold your hand to an answer that should be well-documented is no indicator that the answer isn’t true, or reliable, or anything less than solid. It’s not really an indicator of the reverse, either, but doubting something documented explicitly and only because it’s rather time-consuming to prove is rather arrogant.
More to the point, though, what’s the answer? Common wisdom in this situation seems to say that iOS won’t start apps automagically at boot time, but Apple’s documentation mentions a very specific circumstance that’s an exception: adding the voip
key to the application’s property list, under the “required background modes” array key. In this one instance, the iOS documentation says that the app will be launched so that it can negotiate a background connection and handle incoming calls as soon as the device is turned on.
From that little piece of information, it should be pretty trivial to make an app that contains the necessary keys and hack it to track its own startup time. Right?
So to test this little theory, I started with the Utility app template, with Core Data enabled (but without unit tests - shame on myself). The only entity needed was an AppLaunch class with one attribute: a timestamp. After that, it was trivial to add a tiny method in the app delegate that inserted a new instance of the AppLaunch entity into Core Data with the current time as the timestamp, and hook up the main view controller to display the most recent AppLaunch instance’s timestamp in a label. (Please don’t judge me on my UI design.)
Turns out the documentation is accurate (surprise!), and apps with the voip
key do start with the system - the sample app I tested updated its own launch time after a phone reboot, but before I had the chance to open the app myself. I gave each action about a minute of wait time, so there’s little chance of fuzzing a second here or there and messing up the results. All the same, I encourage other developers interested in the app/system boot relationship to clone the code and try it out.