I am using Region Monitoring in my app and I faced a question that I couldn't find any answer to it. How does region monitoring work in background mode?
According to Location Awareness PG:
Every time the user’s current location crosses a boundary region, the system generates an appropriate region event for your application. If your application is already running, these events go directly to the delegates of any current location manager objects. If your application is not running, the system launches it in the background so that it can respond.
Now, this question is: my app is in the suspended mode, a region has been entered and a trigger should be delivered, does this event will be send "directly" to the delegate's:
locationManager:didEnterRegion:
?? Same question if the app is in background mode. In other words, is there any code I should consider in suspend and background mode to receive this event? or the iOS will first launch the application, then send the event to the delegate directly without any need to BG code?
Region monitoring Relaunches your application when you enter the monitored region if you are in background .
however you have to again configure your location manager after the app relaunches .
something like this -
if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey] )
{
NSLog(@"Relaunched due to location update");
NSLog(@"app woke up times ---- %d",ForTest);
NSLog(@"Starting the location manager");
self.locmanager = [[CLLocationManager alloc] init];
[self.locmanager startMonitoringForRegion:(CLRegion)*region];
// self.locmanager.pausesLocationUpdatesAutomatically = YES ;
}
As far as I know region monitoring only works with iPhone4 and it's based on the device changing the communication towers. This way it uses way less battery than the standard background location update. Make sure you enabled the appropriate background modes. As long as you implement that delegate, you should be ready to go.
enable Background Modes in that enable Location updates and Background Fetch
来源:https://stackoverflow.com/questions/6430836/ios-region-monitoring-in-background-mode