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.

This entry was posted in Programming, Tech and tagged , , , , . Bookmark the permalink.

11 Responses to iOS launch-on-boot apps: fact or fiction?

  1. diogo says:

    hi lithium
    congratulations for the code!!
    it’s working just fine in an ipod/5.0.1 .

    have you succeed launching another app from updateAppLaunchTime?
    I’ve tried, without success to use URLScheme. I’m no sure, but it seems that “BootLaunch updateAppLaunchTime” is not allowed to execute the “UIApplication openURL”, or it doesn’t have time enough for that.

    Do you have any idea how could we launch an app that stays in foreground?
    thanks

    [ ref URLScheme: http://bit.ly/ossPqy ]

    • lithium3141 says:

      Diogo,

      Thanks for your comment! Unfortunately, you’ll note that the voip key is listed under “required background modes” – I don’t think that you’re allowed to bring any app to the foreground during that time, using URLSchemes or otherwise. The only reason apps launch in the background to begin with is to listen for incoming VoIP connections, not to actually present a UI to the user.

      If you find a way to accomplish what you want, please let me know; however, I don’t think it’s possible, at least as far as I know. Best of luck!

  2. Ed says:

    Thank you for the code!

    Would it be possible to show app’s UI on startup only for development purposes? Not releasing to the app store?

    • lithium3141 says:

      You’re welcome, and sorry I took so long to get back to you!

      You can certainly try, but as I said to Diogo, I simply don’t think it’s possible. It’s the OS that brings up the app’s main window and other related UI components, and it doesn’t look like that happens for a background launch. You’ll note that the app delegate even creates a UIWindow and assigns some properties to it, and the OS never displays that window.

      Again, if you figure it out, please let me know – I’m curious myself.

  3. FFS says:

    Seriously? This is your solution? You think no one on Stack Overflow thought of that? Wow, what arrogance.

    Before you start giving bad advice, warn people that this workaround is going to get their applications REMOVED from the market if they declare ‘voip’ property, and are not actual voip applications.

    • lithium3141 says:

      Yep, this is my solution! I link clearly to the documentation, where the voip key is explained to be for VoIP applications only. I meant this post to be more of a proof-of-concept than anything else, and I hope that developers seriously intending to submit App Store apps with this key would take the time to read that documentation, rather than having me hand-hold them through the whole process.

      At the time I posted this, the questions and answers on StackOverflow had been leaning pretty heavily towards either “it’s impossible” or “you have to jailbreak.” I found a different solution, and thought it was interesting, so I wrote it up. It turns out other people have come up with similar solutions in questions that are close to the one that I linked, but on that exact topic, nobody seemed to be speaking up with the right info. I apologize if that seemed arrogant to you.

    • JustAguy says:

      very sorry about this, FFS. But lithium3141 is 120% correct. I do not know either of you and you both did a great job to take your time to “write” something about this. …..people like me, who simply need an answer, love straight answers. Like lithium3141′s.

  4. TTT says:

    Hi lithium

    actually, I cannot get this to work. I started the app, reset the launches, directly turn off my device, wait a bit, turn it on again (Time A), wait again, turn the app on (Time B) and it shows me Time B, not A (and the counter is set to 1)

    Any idea? I’m using an iPad2 with 5.0.1

    • TTT says:

      ah, I got it to work. I had to add the ‘App registers for location updates’ to the .plist as well, and now it works as intended

  5. Georg says:

    hey,

    maybe someone is interested into some additional thing..
    I did an notification app which still works once your device was switched of and switched on again… The only thing I discovered was that in case you switch off the device your app shouldnt be “terminated” by the user before restarting. If you start up our idevice the app will start automatical….

    Setup was easy: I setup a standard window application… All the logic I put into the ViewController.m in addition I add one Key to the Projectname-Info.plist
    the key has the name “Require background modes” -> this will include item0 which gets the value “voip” -> you need to set it… Also add this code

    UIBackgroundTaskIdentifier task = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ //add needed code here Code; }

    The code will be exceeded once your application reaches more than 10 min… so you can make sure it is running longer. iOS is automatical terminating the application after ~10 min. UIBAckgroundTaskIdentifier is called after ~10 mins are reached

    Just for your information even the timer works :D
    Conclusion… App is working in the background fine
    in case of a restart and app was not totally closed (it was not terminated) the app starts to work after restart without open it manually. It still working in the background…

    maybe it helps you
    regards

  6. NJ says:

    The app starts automatically only if it was running prior to system restart. If the user kills the app and reboots the device, the app is not started by the platform automatically.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>