CLError.DeferredFailed 错误(kCLErrorDomain 代码=11)延迟 GPS 更新失败
CLError.DeferredFailed Error (kCLErrorDomain Code=11) Deferred GPS Updates Failing
我有一个应用程序会定期更新位置以映射用户路径。
我正在使用延迟更新。
if (CLLocationManager.deferredLocationUpdatesAvailable() == true && _isDeferingUpdates == false)
{
print("Doing refresh")
_isDeferingUpdates = true
_locationManager.allowDeferredLocationUpdatesUntilTraveled(C_GPS.ACTIVITY_UPDATE_DISTANCE, timeout: C_GPS.ACTIVITY_UPDATE_TIME)
} else
{
print("Could not refresh")
// iPhone 4S does not have deferring so must keep it always on
_locationManager.startUpdatingLocation()
}
当应用程序打开时,我每秒都会收到 "doing refresh" 电话。
我的设置:
在我的 pList NSLocationWhenInUseUsageDescription && NSLocationAlwaysUsageDescription 上有 2 个键
打开后台模式,用于远程通知和位置更新。
将地图设置为使用自行车和行人。
将我的 phone 的所有权限设置为是。
当我的应用进入后台时,您是否知道我的延迟更新失败的任何其他原因?
它从不工作,苹果文档也没什么用
DeferredFailed The location manager did not enter deferred mode for an
unknown reason. This error can occur if GPS is unavailable, not
active, or is temporarily interrupted. If you get this error on a
device that has GPS hardware, the solution is to try again.
这是我的错误处理程序:
func locationManager(manager: CLLocationManager, didFinishDeferredUpdatesWithError error: NSError?)
{
print("FINISHED BACKGROUND UPDATE with error \(error)")
if (error != nil)
{
print("ERROR IS VALID as CLError")
if (error!.code == CLError.LocationUnknown.rawValue)
{
print("Error: Location Unknown")
} else if (error!.code == CLError.DeferredAccuracyTooLow.rawValue)
{
print("Error: Accuracy too low")
} else if (error!.code == CLError.DeferredFailed.rawValue)
{
print("Error: Deferring Failed")
} else if (error!.code == CLError.Denied.rawValue)
{
print("Error: Denied")
} else
{
print("Error not handled")
}
}
_isDeferingUpdates = false
}
iOS 9.2,Xcode 7.2,启用 ARC
问题很可能与您为延期选择的距离和时间间隔有关。尝试利用 CLLocationDistanceMax
和 CLTimeIntervalMax
来解决函数调用问题。例如,将距离设置为 CLLocationDistanceMax
,然后改变时间间隔,反之亦然。
但我看到还有其他您可能想要更改的内容...
- 删除 if 语句中的
CLLocationManager.deferredLocationUpdatesAvailable() == true
条件以允许延迟位置更新。
- 延迟更新可用 iOS6.0+,大多数 iPhone 4S 可以更新到 iOS7.2.1,具体取决于硬件。您不需要单独调用
_locationManager.startUpdatingLocation()
.
- 如果您在 iOS9.0+ 中进行测试,请确保您为位置管理器设置了
allowsBackgroundLocationUpdates
。
- 确保初始
_locationManager.startUpdatingLocation()
是在 - (void)applicationWillResignActive:(UIApplication *)application
方法中生成的,等同于 Swift 而不是在 - (void)applicationDidEnterBackground:(UIApplication *)application
方法中。
- 确保您在调用
_locationManager.allowDeferredLocationUpdatesUntilTraveled(C_GPS.ACTIVITY_UPDATE_DISTANCE, timeout: C_GPS.ACTIVITY_UPDATE_TIME)
时相当于 Swift 的 - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
方法。
另外请注意,在检查错误是否存在之前打印错误,这可能会导致一些不正确的错误报告。
希望这对您有所帮助,我还不算太晚!干杯。
P.S。如果这不起作用,请 post 更多您的代码,即您在何处调用与应用相关的这些功能。委托 *.m 文件。
该错误具有误导性。问题是4S不支持后台更新。因此,对于 4S,我手动引用更新如下:
private func refreshUpdateDeferral()
{
if (CLLocationManager.deferredLocationUpdatesAvailable() == false && _isDeferingUpdates == false)
{
print("Doing deferred referral refresh")
_isDeferingUpdates = true
_locationManager.allowDeferredLocationUpdatesUntilTraveled(C_GPS.ACTIVITY_UPDATE_DISTANCE, timeout: C_GPS.ACTIVITY_UPDATE_TIME)
}
}
问题是我有 CLLocationManager.deferredLocationUpdatesAvailable() == true
这意味着我在已经允许推迟的情况下推迟更新。这似乎导致了上面的错误。
因此,如果您遇到此错误,请检查您是否 allowDeferredLocationUpdatesUntilTraveled
而 deferredUpdates
已经处于活动状态!
如果您的精度和距离过滤器设置不正确,您可能 运行 遇到延迟更新的麻烦。假设您的设备支持延迟更新 (CLLocationManager.deferredLocationUpdatesAvailable),您必须先将位置管理器设置为以下内容:
desiredAccuracy = kCLLocationAccuracyBest
distanceFilter = kCLDistanceFilterNone
然后您可以启动位置管理器并允许延迟更新。
我有一个应用程序会定期更新位置以映射用户路径。
我正在使用延迟更新。
if (CLLocationManager.deferredLocationUpdatesAvailable() == true && _isDeferingUpdates == false)
{
print("Doing refresh")
_isDeferingUpdates = true
_locationManager.allowDeferredLocationUpdatesUntilTraveled(C_GPS.ACTIVITY_UPDATE_DISTANCE, timeout: C_GPS.ACTIVITY_UPDATE_TIME)
} else
{
print("Could not refresh")
// iPhone 4S does not have deferring so must keep it always on
_locationManager.startUpdatingLocation()
}
当应用程序打开时,我每秒都会收到 "doing refresh" 电话。
我的设置:
在我的 pList NSLocationWhenInUseUsageDescription && NSLocationAlwaysUsageDescription 上有 2 个键
打开后台模式,用于远程通知和位置更新。
将地图设置为使用自行车和行人。
将我的 phone 的所有权限设置为是。
当我的应用进入后台时,您是否知道我的延迟更新失败的任何其他原因?
它从不工作,苹果文档也没什么用
DeferredFailed The location manager did not enter deferred mode for an unknown reason. This error can occur if GPS is unavailable, not active, or is temporarily interrupted. If you get this error on a device that has GPS hardware, the solution is to try again.
这是我的错误处理程序:
func locationManager(manager: CLLocationManager, didFinishDeferredUpdatesWithError error: NSError?)
{
print("FINISHED BACKGROUND UPDATE with error \(error)")
if (error != nil)
{
print("ERROR IS VALID as CLError")
if (error!.code == CLError.LocationUnknown.rawValue)
{
print("Error: Location Unknown")
} else if (error!.code == CLError.DeferredAccuracyTooLow.rawValue)
{
print("Error: Accuracy too low")
} else if (error!.code == CLError.DeferredFailed.rawValue)
{
print("Error: Deferring Failed")
} else if (error!.code == CLError.Denied.rawValue)
{
print("Error: Denied")
} else
{
print("Error not handled")
}
}
_isDeferingUpdates = false
}
iOS 9.2,Xcode 7.2,启用 ARC
问题很可能与您为延期选择的距离和时间间隔有关。尝试利用 CLLocationDistanceMax
和 CLTimeIntervalMax
来解决函数调用问题。例如,将距离设置为 CLLocationDistanceMax
,然后改变时间间隔,反之亦然。
但我看到还有其他您可能想要更改的内容...
- 删除 if 语句中的
CLLocationManager.deferredLocationUpdatesAvailable() == true
条件以允许延迟位置更新。 - 延迟更新可用 iOS6.0+,大多数 iPhone 4S 可以更新到 iOS7.2.1,具体取决于硬件。您不需要单独调用
_locationManager.startUpdatingLocation()
. - 如果您在 iOS9.0+ 中进行测试,请确保您为位置管理器设置了
allowsBackgroundLocationUpdates
。 - 确保初始
_locationManager.startUpdatingLocation()
是在- (void)applicationWillResignActive:(UIApplication *)application
方法中生成的,等同于 Swift 而不是在- (void)applicationDidEnterBackground:(UIApplication *)application
方法中。 - 确保您在调用
_locationManager.allowDeferredLocationUpdatesUntilTraveled(C_GPS.ACTIVITY_UPDATE_DISTANCE, timeout: C_GPS.ACTIVITY_UPDATE_TIME)
时相当于 Swift 的- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
方法。
另外请注意,在检查错误是否存在之前打印错误,这可能会导致一些不正确的错误报告。
希望这对您有所帮助,我还不算太晚!干杯。
P.S。如果这不起作用,请 post 更多您的代码,即您在何处调用与应用相关的这些功能。委托 *.m 文件。
该错误具有误导性。问题是4S不支持后台更新。因此,对于 4S,我手动引用更新如下:
private func refreshUpdateDeferral()
{
if (CLLocationManager.deferredLocationUpdatesAvailable() == false && _isDeferingUpdates == false)
{
print("Doing deferred referral refresh")
_isDeferingUpdates = true
_locationManager.allowDeferredLocationUpdatesUntilTraveled(C_GPS.ACTIVITY_UPDATE_DISTANCE, timeout: C_GPS.ACTIVITY_UPDATE_TIME)
}
}
问题是我有 CLLocationManager.deferredLocationUpdatesAvailable() == true
这意味着我在已经允许推迟的情况下推迟更新。这似乎导致了上面的错误。
因此,如果您遇到此错误,请检查您是否 allowDeferredLocationUpdatesUntilTraveled
而 deferredUpdates
已经处于活动状态!
如果您的精度和距离过滤器设置不正确,您可能 运行 遇到延迟更新的麻烦。假设您的设备支持延迟更新 (CLLocationManager.deferredLocationUpdatesAvailable),您必须先将位置管理器设置为以下内容:
desiredAccuracy = kCLLocationAccuracyBest
distanceFilter = kCLDistanceFilterNone
然后您可以启动位置管理器并允许延迟更新。