iOS Region Monitoring in Background Mode

北慕城南 提交于 2019-12-04 17:46:04

问题


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?


回答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 ;
    }



回答2:


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.




回答3:


enable Background Modes in that enable Location updates and Background Fetch



来源:https://stackoverflow.com/questions/6430836/ios-region-monitoring-in-background-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!