区域监控及后台

Region monitoring and background

我毫不怀疑,想知道是否有必要将所有区域重新分配给位置管理器,如果它收到 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];
    }
  }

那么app进入后台的时候是否需要重新重新分配区域到location manger?或者,一旦该区域在 startAction: 操作

上分配给位置管理器,它就会自动监控

更新 1:

+ (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:

App plist configuration

不需要,当您的应用程序进入后台时,您不需要重新启动区域监控。如果你配置了它会自动监控区域。

您需要在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];