如何使用延期位置iOS 6



我正在尝试使用部门位置更新的新iOS 6功能,但继续遇到此错误:

didfinishdeferredupdateswitherror:错误域= kclorrordomain code = 11"操作无法完成。(kclorrordomain error 11。)

我正在使用以下代码:

- (DeviceAPI *) init
    {
     locationManager = [[CLLocationManager alloc] init];
     [locationManager setDelegate:self];
     [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
     [locationManager startUpdatingLocation];
     [locationManager allowDeferredLocationUpdatesUntilTraveled:(CLLocationDistance)100000     timeout:(NSTimeInterval)100000];
    return self;
 }

和此callback功能:

- (void)locationManager:    (CLLocationManager *)   manager
                        didFinishDeferredUpdatesWithError:(NSError *)error
{
    NSLog(@"didFinishDeferredUpdatesWithError :%@", [error description]);
}

有帮助吗?

根据iOS 6.0 SDK的Apple开发人员论坛,延期位置更新仅可用:

  • 在iPhone 5硬件上
  • 运行iOS 6.0或更高
  • 所需的精度设置为kCLLocationAccuracyBestkCLLocationAccuracyBestForNavigation,因为此需要GPS芯片。没有蜂窝数据的iPad没有GPS芯片。
  • 调用" startupdatinglocation"方法
  • 等待位置更新大约每秒1个
  • 然后开始推迟更新

请参阅:https://devforums.apple.com/message/751974#751974

参见文档:allowDeferredLocationUpdates(untilTraveled:timeout:)

听起来您需要iPhone 5硬件,并且要等待位置更新以1Hz。

另外,正如另一位海报所述,您需要在委托中实现locationManager:didUpdateLocations:方法。

最常见的地方称此[allowDeferredLocationUpdates]方法在您的代表中 locationManager(_:didUpdateLocations:)方法。处理后 新位置,如果您想推迟未来的更新,请致电此方法 直到满足距离或时间标准。如果新事件到来,并且 您的应用在后台,活动被缓存,他们 交货适当地推迟。

来自文档。我已经在[] 中添加了笔记。

您是否在info.plist uibackgroundmodes字段中设置了位置?

在我的测试中,我发现递延更新仅在iOS 6.0.1或更大的情况下工作,但不工作6.0。由于测试原因,我在2部手机1上进行了测试,并使用6.0保留了1个手机1。我相信这就是模拟器不起作用的原因,如果您的手机尚未更新,这可能是为什么也无法正常工作的原因。

还确保您实现

- 位置管理器:didupdatelecations:

而不是现在不弃用的

- 位置管理器:didupdateTolocation:fromlocation:

是与延期位置更新所必需的。

在调用allowdeferredlocationupdatesuntiltraveled之前:超时:将距离过滤器设置为kcldistancefilternone,然后将其工作。

我在一个框架样本中找到了此描述,用于[cligion initcircularregionwithcenter]呼叫:

"如果覆盖层的半径太大,则注册会自动失败,因此将半径固定为最大值。"

最新更新