Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Region Monitoring in Background Mode

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?

like image 564
Abdalrahman Shatou Avatar asked Jun 21 '11 19:06

Abdalrahman Shatou


People also ask

How do I geofence my location on iPhone?

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.

What is geofencing in iOS?

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.

How do I get a background location update every n minutes in my iOS application?

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.

What is background location on iPhone?

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.


1 Answers

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 ;
    }
like image 160
jevo Avatar answered Sep 23 '22 10:09

jevo