【发布时间】:2015-10-02 21:49:25
【问题描述】:
我有一个应用程序会定期更新位置以映射用户路径。
我正在使用延迟更新。
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()
}
当应用打开时,我每秒都会收到“正在刷新”的调用。
我的设置:
在我的 pList NSLocationWhenInUseUsageDescription && NSLocationAlwaysUsageDescription 上有 2 个键
为远程通知和位置更新开启后台模式。
设置地图以使用自行车和行人。
将我手机上的所有权限设置为是。
您知道当我的应用进入后台时延迟更新失败的任何其他原因吗?
它从不工作,而且苹果文档也没有什么帮助
DeferredFailed 位置管理器没有进入延迟模式 不明原因。如果 GPS 不可用,则可能会发生此错误,而不是 激活,或暂时中断。如果您收到此错误 具有 GPS 硬件的设备,解决方法是重试。
这是我的错误处理程序:
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 10 stackoverflow.com/questions/39498899/…
-
我发现这个正在寻找 iOS 10 stackoverflow.com/questions/39498899/…
标签: ios gps mapkit core-location