Running in the background

Discussion in 'iOS Programming' started by Bardal, Mar 16, 2015.

  1. Bardal macrumors newbie

    Joined:
    Mar 16, 2015
    #1
    Hello,
    I'd like my app to always run in the background (from the time the iPhone is turned on, with no manual action required). Is that possible?
    If not, can an app be launched whenever a specific event occurs, such as a bluetooth connection?

    Thanks in advance,
    B.
     
  2. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #2
    In general, NO.

    There are specific modes that can be specified by the app that allow the app to run specific tasks in the background, such as continuous audio playing or recording or a bluetooth connection to an active and nearby BTLE/4.0 device. However, even those can be killed by the OS (for instance if the user starts another music player that won't mix, or runs out of memory playing a gigantic game). Only certain types of intermittent VOIP and geolocation tasks will survive a reboot, but even those have to be started by the user at least once, and can be locked out in privacy settings.

    You can have an app monitor for certain kinds of Bluetooth connections (BTLE iBeacons) in the background, but whether that happens after a reboot might depend on which iOS version.

    Only Apple's built-in apps will stay running after a pure restart, and they can't be modified on a stock device.
     
  3. theSeb macrumors 604

    theSeb

    Joined:
    Aug 10, 2010
    Location:
    Poole, England
    #3
  4. Bardal thread starter macrumors newbie

    Joined:
    Mar 16, 2015
    #4
    Thanks for the info and link - it's very useful.
    However, I still don't understand what's the bottom line for my use-case.
    I'm writing an app that samples GPS, accelerometer and other data in certain times/locations, e.g., whenever I'm home, at the office or in my car. I'd like the app to start sampling automatically (ie, without having to manually start the app), so I thought it could wake up whenever one of the following relevant events occurs: my home wi-fi or a bluetooth device in my car are detected; my location changes by more than X meters; the accelerometer records a value larger than Y; etc. Once it starts sampling, the app could determine by itself when it should stop sampling (until the next relevant event occurs).
    So... is this possible?
    Another option is to have the app continue sampling all the time, from the moment the phone is turned on. This shouldn't affect user experience, since the sampling rate would remain low most of the time (eg, once every several seconds/minutes). The app could change the sampling rate based on the location, existence of wifi/BT connection, etc. Is this option possible / recommended?

    Thanks again for your advice!
     
  5. AppDiggity macrumors member

    Joined:
    Feb 24, 2015
    #5
    One of the inherent roadblocks with wanting to do that is running on iOs in general. Just by being on iOs, you are succumbing to Apples rules, which would mean that your app can be closed out at will.
     
  6. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #6
    iOS aggressively kills any background monitoring apps unless they fall within very narrow guidelines, or run for more a tiny amount of time. I suggest a careful reading of what is allowed and what is already approved and in the apps store. Anything else is likely to get rejected by Apple or killed by the OS.

    Certain BLTE device detection and geolocation events can wake up apps in the background. None for WiFi or accelerometer in the current public APIs. Sampling all the time is impossible except for audio recorders (which put up an ugly red bar when in the background).
     
  7. Dranix macrumors 6502a

    Dranix

    Joined:
    Feb 26, 2011
    Location:
    Gelnhausen, Germany

Share This Page