xcode – 如何使用延迟位置iOS 6?

前端之家收集整理的这篇文章主要介绍了xcode – 如何使用延迟位置iOS 6?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用新的iOS 6功能自定义位置更新,但继续收到此错误

didFinishDeferredUpdatesWithError :Error Domain=kCLErrorDomain Code=11 “The operation couldn’t be completed. (kCLErrorDomain 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;
 }

而这个回调函数

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

有帮助吗?

解决方法

根据适用于iOS 6.0 SDK的Apple Developer论坛,延迟位置更新仅适用于:

>在iPhone 5硬件上
>运行iOS 6.0或更高版本
>所需精度设置为kCLLocationAccuracyBest或kCLLocationAccuracyBestForNavigation,因为这需要GPS芯片.没有手机数据的iPad没有GPS芯片.
>调用“startUpdatingLocation”方法
>等待位置更新以大约每秒1进入
>然后开始推迟更新

见:https://devforums.apple.com/message/751974#751974

见文档:allowDeferredLocationUpdates(untilTraveled:timeout:)

所以听起来你需要iPhone 5硬件,等待位置更新以1Hz的速度进入.

另外,正如另一张海报所提到的,您需要在委托中实现locationManager:didUpdateLocations:方法.

The most common place to call this [allowDeferredLocationUpdates] method is in your delegate’s
locationManager(_:didUpdateLocations:) method. After processing any
new locations,call this method if you want to defer future updates
until the distance or time criteria are met. If new events arrive and
your app is in the background,the events are cached and their
delivery is deferred appropriately.

From 07002. I’ve added notes inside [].

猜你在找的Xcode相关文章