我毫无疑问,想知道是否有必要再次将所有区域重新分配给位置管理器,如果它收到appEnterInBackGround
的post通知?
下面是一些代码片段
- (IBAction)startAction:(id)sender
{
for (Geofencing *gObjects in plotingArrays) {
CLCircularRegion *getRegion = [self dictToRegion:gObjects];
[monitorLocationManager startMonitoringForRegion:getRegion];
}
}
所以当应用程序进入后台时,我这样做:
# pragma mark - BackGround Notification
-(void)applicationEnterBackground
{
monitorLocationManager = [selectRouteController sharedLocationMonitor];
monitorLocationManager.delegate = self;
for (Geofencing *gObjects in plotingArrays) {
CLCircularRegion *getRegion = [self dictToRegion:gObjects];
[monitorLocationManager startMonitoringForRegion:getRegion];
}
}
所以当应用程序进入后台时,是否有必要重新分配区域给位置管理器?或者,一旦将该区域分配给startAction:
操作上的位置管理器,它将自动监视
UPDATE1:
+ (CLLocationManager *)sharedLocationMonitor {
static CLLocationManager *locationMonitor;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
locationMonitor = [[CLLocationManager alloc] init];
locationMonitor.desiredAccuracy =
kCLLocationAccuracyBestForNavigation;
locationMonitor.activityType =
CLActivityTypeAutomotiveNavigation;
[locationMonitor requestAlwaysAuthorization];
if(IS_OS_9_OR_LATER){
locationMonitor.allowsBackgroundLocationUpdates = YES;
}
if(SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(@"8.4")){
locationMonitor.pausesLocationUpdatesAutomatically = NO;
}
});
return locationMonitor;
}
PLIST:
应用程序列表配置
不,当你的应用程序进入后台时,你不需要重新启动区域监控。如果您已配置该区域,它将自动监视该区域。
您需要在info.plist中配置以下内容:
<key>NSLocationAlwaysUsageDescription</key>
<string>I want to get your location Information in background</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
你还需要设置AllowsBackgroundLocationUpdates为yes。
[monitorLocationManager setAllowsBackgroundLocationUpdates:YES];