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?
Setting up geofencing on an iPhone (iOS)Turn on Geofencing in the Home Center app (Application Settings > Geofencing). Go to the iPhone's Settings, scroll down and choose Home Center from the list. Tap Location and set Always (and make sure you have Precise Location enabled). Done.
Region monitoring (also known as geofencing) is a way for your app to be alerted when the user enters or exits a geographical region. You might use region monitoring to perform location-related tasks.
You can use an NSTimer to request a location every minute with this method now and don't have to work with startUpdatingLocation and stopUpdatingLocation methods.
Background location use. If you give an app permission to access your location while it's in use, the app can then ask to know where you are at all times.
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 ;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With