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

前端 未结 2 930
北海茫月
北海茫月 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.

提交回复
热议问题