11

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?

Abdalrahman Shatou
  • 4,285
  • 6
  • 45
  • 72

3 Answers3

1

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 ;
    }
jevo
  • 53
  • 1
  • 5
0

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.

Paul Ardeleanu
  • 6,153
  • 2
  • 36
  • 38
  • mmmmmm....that leads to another question, may sound silly, but does Region Monitoring device require specifying that in info.plist? In this case my app won't be installed on 3Gs while this feature is not essential (it's not a location based app). – Abdalrahman Shatou Jun 21 '11 at 21:06
  • Yes, you still need to enable location tracking. – Paul Ardeleanu Jun 22 '11 at 22:08
  • I think you're right. I tried many times but I never get notified that I entered the region. I will consider modifying info.plist. This however, will sadly lower my sales!. Thank you. – Abdalrahman Shatou Jun 22 '11 at 22:34
  • Nothing! Nada!...Didn't get any notification of any kind. – Abdalrahman Shatou Jun 23 '11 at 15:02
  • I meant if I require that location service to be active in BG in plist, then my app won't be installed on either iPod and iPad WiFi. Any ho, I found out I don't have to... I will try that, I will keep the app running (won't even lock the screen) and test it. I am sure that the region is registered by iOS and I checked that by code...Let's see how it will work...Thanks for keeping up... – Abdalrahman Shatou Jun 28 '11 at 20:46
  • It worked! but it's not accurate and not in background mode...I had to leave my app open and prevent screen locking. If the app is in background mode, it doesn't work...don't know why.. – Abdalrahman Shatou Jul 01 '11 at 11:47
  • I think for it to work in background mode - you need to add the correct plist entry to support background location. Region monitoring isn't very accurate, as it relies on cell tower + wifi locations I believe. – wows Aug 29 '11 at 10:29
  • @Shatou, I am facing the exact same problem in my app....RM works in foreground, but in background, the results are spotty. This totally goes against the advice that Apple gives about using it to save battery life... Sure it saves battery life, but your app may not work. The users are going to say that the App is not working. I am going to warn the users and let them make a choice if they want to use RM.. my 2 cents.... – Sam Dec 08 '11 at 05:47
  • @wow, I have the option in plist file to allow location updates in the background - that's not the reason for not getting updates in bg... it is something else that I can't put my finger on yet. – Sam Dec 08 '11 at 05:49
  • Did you ever get to the bottom of this? – Undistraction May 30 '12 at 07:20
  • @ShatouDev, did you ever resolve things? I'd ask Bill Burgess (who commented to your question) as he's more than decent on this subject. Also, regarding your problem with foreground & background mode - see my [question](http://stackoverflow.com/questions/12360386/didenterregion-works-in-foreground-but-not-background-or-other-vcs) – ari gold Sep 15 '12 at 19:06
-1

enter image description here

enable Background Modes in that enable Location updates and Background Fetch