问题
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