加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:59:06 所属栏目:百科 来源:网络整理
导读:我正在尝试使用新的iOS 6功能的自定义位置更新,但继续收到此错误: didFinishDeferredUpdatesWithError :Error Domain=kCLErrorDomain Code=11 “The operation couldn’t be completed. (kCLErrorDomain error 11.)” 我使用以下代码: - (DeviceAPI *) ini
我正在尝试使用新的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 [].

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读