【问题标题】:Region monitoring and background区域监控和后台
【发布时间】:2017-03-10 22:56:40
【问题描述】:

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

这里有一些代码 sn-p。

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

App plist configuration

【问题讨论】:

    标签: ios objective-c background cllocationmanager region-monitoring


    【解决方案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];
    

    【讨论】:

    • 你。你能帮我交叉检查代码吗?请参阅 UPDATE1
    • 附上 PLIST 屏幕截图。
    猜你喜欢
    • 2015-02-07
    • 2011-09-19
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2018-08-04
    相关资源
    最近更新 更多