【问题标题】:GPS location/Region monitoring recap + how to switch on/off the gps signal (icon) in background [iOS]GPS位置/区域监控回顾+如何在后台打开/关闭gps信号(图标)[iOS]
【发布时间】:2012-03-07 15:07:32
【问题描述】:

我想知道

A) 如果可以在应用程序处于后台模式时完全关闭 gps 的使用并且我终止它(长按“主页按钮”,点击相应任务的“X”),即使“区域监控”处于活动状态,App .plst 中有相应的活动标志。

我还想回顾一下如何监控设备位置;我认为有三种方式: - [locationManager startUpdatingLocation] - [locationManager startMonitoringSignificantLocationChanges]; - [locationManager startMonitoringForRegion:region desiredAccuracy:accuracy];

B) 我不明白它们是否“可以”/“可能不能”/“必须”同时运行。例如: startUpdatingLocation 和 startMonitoringSignificantLocationChanges 是互斥的,这没关系,但是 startMonitoringForRegion 呢?

C) 我可以只使用 startMonitoringForRegion 而不使用 startMonitoringSignificantLocationChanges 吗?

D) 如果我同时使用两者,我可以在进入/退出受监控区域时收到两个通知吗?我怎样才能避免它? 在这种情况下,我认为我应该实现这样的东西:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation   {
 BOOL crossedBoundary = [self checkIfNewLocationHasCrossedMyMonitoredRegionBoundary:newLocation ];
if (crossedBoundary) NSLog(@"Crossed the boundary");
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region  {  NSLog(@"Crossed the boundary"); }

E) 我如何在应用程序处于后台时关闭/打开 startMonitoringForRegion?

非常感谢。 我从“Regions”和“breadCrumb”Apple 示例开始 https://developer.apple.com/library/ios/#samplecode/Breadcrumb/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010048-Intro-DontLinkElementID_2

https://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.html

【问题讨论】:

    标签: iphone objective-c gps cllocationmanager region


    【解决方案1】:

    按顺序回答您的问题

    Ans A) 就我而言,您无法关闭定位服务。

    Ans B) startMonitoringForRegion 正在应用程序外部运行服务,监控区域进入/退出状态。它的位置不是通过 CLLocationManager 更新的,该 CLLocationManager 从位置服务更新当前位置。它只存储应用程序的监控区域。

    Ans C) 是的,您可以单独使用它们,因为 startMonitoringForRegion 在位置服务上添加了要监控的区域,其中 startMonitoringSignificantLocationChanges 是监控位置变化较大的技术使用 locationManager:didUpdateLocations: 处理并更新到 CLLocationManager。但如上一个回答中提到的 startMonitoringForRegion 会将要监控的区域添加到区域监控位置服务中

    Ans D) 是的,您将收到单独的位置更新。但请记住,startMonitoringSignificantLocationChanges 会将位置更新为 CLLocationManger。其中 startMonitoringForRegion 仅在边界交叉处更新而不更新位置。

    Ans E)您必须将 stopMonitoringRegion 添加到应用程序的 AppDelegate 中的 appEnterBackground

    【讨论】:

      【解决方案2】:

      它将停止呼叫 GPS

      -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*) newLocation
                 fromLocation:(CLLocation *)oldLocation
      {
      [manager stopUpdatingLocation];
      
      }
      

      【讨论】:

      • 部分...我认为它只会停止正常的本地化。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-09
      相关资源
      最近更新 更多