启用后禁用allowBackgroundLocationUpdates(CLLocationManager)不起作用 [英] Disabling allowsBackgroundLocationUpdates (CLLocationManager) doesn't work after is was enabled

查看:102
本文介绍了启用后禁用allowBackgroundLocationUpdates(CLLocationManager)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序可连续进行后台位置更新。
当然,它具有所有权限和其他内容,例如

My Application works with continuous background location updates. Of course it has all the permissions and other stuff like

allowsBackgroundLocationUpdates = true

最初,我想做出反应 LowPowerMode 更改在后台使用 NSProcessInfoPowerStateDidChange 通知。并禁用 allowsBackgroundLocationUpdates 停止更新位置,而无需调用 stopUpdatingLocation

Initially I wanted to react to LowPowerMode changes while in background using NSProcessInfoPowerStateDidChange notification. And to disable allowsBackgroundLocationUpdates to stop updating locations without calling stopUpdatingLocation.

但是,我发现收到通知并设置

However, I found out that after receiving the notification and setting

allowsBackgroundLocationUpdates = false

后台应用程序正在运行。

in background application is going on working.

所以我走得更远,发现,禁用 允许BackgroundLocationUpdates 甚至在前台设置为 true 根本不起作用。应用程序将继续在后台运行。

So I went farther and identified, that disabling allowsBackgroundLocationUpdates even in foreground after it was initially set to true doesn't work at all. Application continues working in background.

Apple对此事的文档

Apple's documentation on the matter


此属性可根据您的
应用的行为启用和禁用行为

you use this property to enable and disable the behavior based on your app’s behavior






从CLLocationManager类中,对 allowsBackgroundLocationUpdates 属性


的描述将UIBackgroundModes设置为包括在Info.plist中的位置中,每次调用
-startUpdatingLocation并打算在后台继续运行时,您
还必须在运行时将此属性设置为YES。将此属性重置为NO等效于从UIBackgroundModes值中省略位置

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.

GitHub上的简单项目,显示了我提到的行为。

Simple project on GitHub that shows the behavior I mentioned.

那么问题是,该属性是否为故意行为?

So the question, is it intentional behavior of the property?

推荐答案


何时该属性的值为假,应用根据其当前授权 在前台或 后台运行时正常接收位置更新。仅当应用程序暂停时更新才会停止,从而防止唤醒应用程序以处理这些事件。 Apple API讨论

我认为属性讨论可以解决您的问题。

I think the property discussion can solve your problem.

这篇关于启用后禁用allowBackgroundLocationUpdates(CLLocationManager)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆