1

我毫无疑问,想知道是否有必要再次将所有区域重新分配给位置经理,如果它收到发布通知appEnterInBackGround

这是一些代码片段。

- (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:监控

更新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 配置

4

1 回答 1

1

不,当您的应用进入后台时,您无需重新启动区域监控。如果您已配置,它将自动监视区域。

您需要在 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];
于 2016-10-28T06:07:50.290 回答