CLLocationManager startMonitoringForRegion: not relaunching app after device restart

两盒软妹~` 提交于 2019-12-24 05:06:22

问题


Ok, so I currently have an app where I register a geofence to be monitored using the CLLocationManager startMonitoringForRegion method. This works fine when the app is in the foreground and background.

I also have the appropriate plist values set:

UIBackgroundModes :{location}
UIRequiredDeviceCapabilities: {location-services}

What doesn't work

After a device restart, the app is not being relaunched. I can force this to happen if I set startMonitoringSignificantLocationChanges before entering background. But this method uses much more battery life and I don't need the location all the time, just whenever I break a geofence.

The docs for regions say:

In iOS, the regions you register with the location manager persist between launches of your application. If a region crossing occurs while your iOS app is not running, the system automatically wakes it up (or relaunches it) in the background so that it can process the event. When relaunched, all of the regions you configured previously are made available in the monitoredRegions property of any location manager objects you create.

Question

Is it possible (when using geofencing regions) to have the system restart my app AFTER a system reboot, WITHOUT using startMonitoringSignificantLocationChanges ?

Edit: I am targeting iOS6 & iOS7


回答1:


Answering my own question here.

While you do need to use the startMonitoringSignificantLocationChanges to get the system to wake up the app after a device reboot. Nothing will wake up the app if the user has force closed it.

For my purposes, I did not need to set UIBackgroundModes to location. This setting is usually used for applications that only need fine-grained location updates (E.g. using startUpdatingLocation). Setting the background mode is not required when using startMonitoringSignificantLocationChanges.



来源:https://stackoverflow.com/questions/20432971/cllocationmanager-startmonitoringforregion-not-relaunching-app-after-device-res

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!