我的应用程序与持续的后台位置更新一起工作。 当然它有所有的权限和其他东西,比如
allowsBackgroundLocationUpdates = true
最初我想在后台使用 NSProcessInfoPowerStateDidChange
通知响应 LowPowerMode
更改。并在不调用 stopUpdatingLocation
的情况下禁用 allowsBackgroundLocationUpdates
停止更新位置。
但是收到通知和设置后才发现
allowsBackgroundLocationUpdates = false
在后台应用程序正在运行。
所以我走得更远,确定了 disabling allowsBackgroundLocationUpdates
甚至 in foreground 在它最初设置为 true
根本不起作用。应用程序继续在后台运行。
Apple 关于此事的文档
you use this property to enable and disable the behavior based on your app’s behavior
来自 CLLocationManager 类,allowsBackgroundLocationUpdates
属性的描述
With UIBackgroundModes set to include "location" in Info.plist, you must also set this property to YES at runtime whenever calling -startUpdatingLocation with the intent to continue in the background. Resetting this property to NO is equivalent to omitting "location" from the UIBackgroundModes value.
Simple project在 GitHub 上显示了我提到的行为。
那么问题来了,这是属性(property)的故意行为吗?
最佳答案
When the value of this property is false, apps receive location updates normally while running in either the foreground or background based on its current authorization. Updates stop only when the app is suspended, thereby preventing the app from being woken up to handle those events.Apple API Discussion.
我认为属性(property)讨论可以解决你的问题。
关于ios - 启用后禁用 allowsBackgroundLocationUpdates (CLLocationManager) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41704302/