If background applications can't launch automatically how does Cardcase launch on a location change?

前端 未结 2 906
北海茫月
北海茫月 2021-01-01 07:17

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 backg

相关标签:
2条回答
  • 2021-01-01 07:47

    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.

    0 讨论(0)
  • 2021-01-01 07:47

    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.

    0 讨论(0)
提交回复
热议问题