If background applications can't launch automa

2019-02-07 14:26发布

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?

2条回答
一纸荒年 Trace。
2楼-- · 2019-02-07 15:13

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.

查看更多
对你真心纯属浪费
3楼-- · 2019-02-07 15:21

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.

查看更多
登录 后发表回答