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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12992380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:53:00  来源:igfitidea点击:

How to work with deferred location iOS 6?

xcodelocationios6

提问by user1762103

I am trying to use the new iOS 6 feature of deffered location updates but keep on getting this error :

我正在尝试使用延迟位置更新的新 iOS 6 功能,但不断收到此错误:

didFinishDeferredUpdatesWithError :Error Domain=kCLErrorDomain Code=11 "The operation couldn't be completed. (kCLErrorDomain error 11.)"

didFinishDeferredUpdatesWithError :Error Domain=kCLErrorDomain Code=11 “操作无法完成。(kCLErrorDomain 错误 11。)”

I am using the following code:

我正在使用以下代码:

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

    return self;
 }

And this callbackfunction :

而这个callback功能:

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

Any help?

有什么帮助吗?

回答by Jen Leech

According to the Apple Developer Forums for the iOS 6.0 SDK, deferred location updates are only available:

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

  • on iPhone 5 hardware
  • running iOS 6.0 or higher
  • desired accuracy set to kCLLocationAccuracyBestor kCLLocationAccuracyBestForNavigationbecause this requiresa GPS chip. An iPad without cellular data does not have a GPS Chip.
  • call the "startUpdatingLocation" method
  • wait for location updates to come in at approximately 1 per second
  • then begin deferring updates
  • 在 iPhone 5 硬件上
  • 运行 iOS 6.0 或更高版本
  • 期望精度设置为kCLLocationAccuracyBestkCLLocationAccuracyBestForNavigation因为这需要GPS 芯片。没有蜂窝数据的 iPad 没有 GPS 芯片。
  • 调用“startUpdatingLocation”方法
  • 等待位置更新以大约每秒 1 次的速度进入
  • 然后开始推迟更新

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

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

See docs: allowDeferredLocationUpdates(untilTraveled:timeout:)

查看文档: allowDeferredLocationUpdates(untilTraveled:timeout:)

So sounds like you need iPhone 5 hardware, and to wait for location updates to come in at 1Hz.

所以听起来你需要 iPhone 5 硬件,并等待位置更新以 1Hz 的频率进入。

Additionally, as another poster mentioned, you'd need to implement the locationManager:didUpdateLocations:method in your delegate.

此外,正如另一位海报所提到的,您需要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 docs. I've added notes inside [].

调用此 [ allowDeferredLocationUpdates] 方法的最常见位置是在您的委托 locationManager(_:didUpdateLocations:)方法中。处理任何新位置后,如果您想推迟未来更新,直到满足距离或时间标准,请调用此方法。如果新事件到达并且您的应用程序在后台,则事件会被缓存并适当延迟它们的交付。

文档。我在里面添加了注释[]

回答by Eric Collins

Did you set location in your info.plist UIBackgroundModes field?

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

回答by Mike Gottlieb

In my testing I have found that deferred updates only work in iOS 6.0.1 or greater, but not 6.0. I tested on 2 phones 1 which I updated and 1 which I left using 6.0 for testing reasons. I believe this is the reason why the simulator doesn't work and if your phone isn't updated yet it is likely why that isn't working either.

在我的测试中,我发现延迟更新仅适用于 iOS 6.0.1 或更高版本,但不适用于 6.0。我在 2 部手机上进行了测试,1 部是我更新的,1 部是出于测试原因使用 6.0 离开的。我相信这就是模拟器不工作的原因,如果你的手机还没有更新,很可能是因为它也不起作用。

Also make sure you implement

还要确保你实施

– locationManager:didUpdateLocations:

– locationManager:didUpdateLocations:

rather than the now deprecated

而不是现在已弃用

– locationManager:didUpdateToLocation:fromLocation:

– locationManager:didUpdateToLocation:fromLocation:

as it is required for use with deferred location updates.

因为它需要用于延迟位置更新。

回答by Paul King

Before you call allowDeferredLocationUpdatesUntilTraveled:timeout: set the distance filter to kCLDistanceFilterNone, then it will work.

在调用 allowDeferredLocationUpdatesUntilTraveled:timeout: 之前,将距离过滤器设置为 kCLDistanceFilterNone,然后它将起作用。

回答by vedrano

I found this description in one Framework sample for [CLRegion initCircularRegionWithCenter] call:

我在 [CLRegion initCircularRegionWithCenter] 调用的一个框架示例中找到了此描述:

"If the overlay's radius is too large, registration fails automatically, so clamp the radius to the max value."

“如果叠加的半径太大,注册会自动失败,因此将半径限制为最大值。”