2

The Cardcase application lets you know if you approach a shop which you have a previous relationship with (if you've set up a tab for payments there etc.).

If background running applications cannot be started automatically on device boot, how does this app therefore work?

Edited to make my question clearer: I am not asking how to monitor for location changes or how to monitor for location changes in the background. My question is, if the user install this app, then adds some tabs for some locations, then they reboot their iPhone, then how can this app subsequently notify them when they approach a location if application launch on boot is not supported?

Must this application (and indeed any other application) be dependent upon it being launched explicitly by the user following every device reboot?

progrmr
  • 75,956
  • 16
  • 112
  • 147
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • I've never heard of an application being able to launch automatically on iPhone power-up, so Cardcase is most likely doing minimal server reporting (based on significant location changes) while running in the background. – Michael Dautermann Dec 29 '11 at 22:33
  • What I am wondering is how does it get to run in the background in the first place in order to register for location changes. If a user installs this app and creates tabs with various shops then reboots, then is it impossible for the app to notify them when they approach the shop? – Gruntcakes Dec 29 '11 at 22:44
  • are you saying Cardcase magically launches when the iPhone is rebooted? without the user's explicitly launching it? – Michael Dautermann Dec 29 '11 at 22:50
  • @MichaelDautermann Registration survives the reboot. The user must have run the app at least once for it to have registered the region(s) – Firoze Lafeer Dec 29 '11 at 22:54
  • I haven't had the chance to try it myself but a couple of people are saying it does - maybe they must be mistaken? – Gruntcakes Dec 29 '11 at 22:55

2 Answers2

4

You can do this with region monitoring. You register regions that you would like to monitor with this method on CLLocationManager:

- (void)startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy

Then even if your app is not running, it will be launched in the background as the user enters or leaves the region.

From Apple's docs:

If you begin monitoring a region and your application is subsequently terminated, the system automatically relaunches it into the background if the region boundary is crossed. In such a case, the options dictionary passed to the application:didFinishLaunchingWithOptions: method of your application delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your application was launched because of a location-related event. In addition, creating a new location manager and assigning a delegate results in the delivery of the corresponding region messages.

EDIT

Just tested this with my own app. Rebooted my phone before leaving the office, and the app was launched on my drive home as usual. So yes, this definitely survives a reboot.

Hope that helps.

Firoze Lafeer
  • 17,133
  • 4
  • 54
  • 48
  • Thanks but I don't think I explained my question very well - my question is how can the app run in the first place in order to make a call to startMonitoringForRegion following a device reboot. I've updated the question to make it clearer. – Gruntcakes Dec 29 '11 at 22:45
  • Well, in the Casecard case, the user has run the app at least once, yes? We use this feature in an app and registration does survive reboot of the device. – Firoze Lafeer Dec 29 '11 at 22:48
  • If the app registers with startMonitoringForRegion I presume that will not survive a reboot? Are you saying it does? – Gruntcakes Dec 29 '11 at 22:51
  • 1
    Yes, I'm pretty sure it survives the reboot even on iOS4. – Firoze Lafeer Dec 29 '11 at 22:55
  • 1
    @Piepants, I rebooted my own phone to confirm this works. Updated my answer. – Firoze Lafeer Dec 29 '11 at 23:41
  • Great news. Thanks for doing so. – Gruntcakes Dec 29 '11 at 23:46
  • Firoze - how fine grained can a region be? – Gruntcakes Jan 04 '12 at 06:27
  • @Piepants, You might have figured this out by now but you set the radius for regions before you start monitoring them. Also, you can define the accuracy of the reporting - so that didEnterRegion (or didExitRegion) is not called too much around the border of the region. – ari gold Sep 12 '12 at 21:06
0

This works for geo-fencing apps (apps that use startMonitoringForRegion).

My guess is that when you install apps using this class, the responsible iOS framework automatically registers an launchd script for the app background service startup inside iOS.

Of course this is all done automatically as you don't have fine control on iOS launch services unless you're jailbroken.

You can use the startMonitoringForRegion on your app, jailbreak your device and check on launchd to check how this works under the hood.

ygbr
  • 752
  • 9
  • 14