iOS13有没有办法主动触发.always coreLocation权限?

Is there a way to trigger the .always coreLocation permission proactively in iOS13?

在 iOS13 下,当您请求 coreLocation 的 .always 权限(以启用后台位置,例如地理围栏或 iBeacons)时,该应用仅被授予 "provisional always" 权限,这不允许它在后台使用 coreLocation。在后期,原则上 OS 应该弹出权限请求以切换到 .always 权限。我还没有体验过,似乎(查看 Apple 开发者论坛)没有人找到一种方法来持续触发此对话框弹出窗口。

我已经申请了.always(只能提供无用的"provisional always"权限),然后尝试"upgrade"到真正的.always权限,但是没有任何反应(没有弹出,没有权限更改)

我也尝试按照书中的 WWDC 推荐,要求 .always,总是接收临时文件,然后相信 OS 会在某个阶段显示对话框 - 没有运气。

更麻烦的是,即使我手动将权限设置更改为我的应用程序的真实 .always 权限,该应用程序仍然无法在后台测距。

如果请求 .always 并获得 "provisional" always 权限,我希望 OS 显示位置对话框在某个阶段提出 "real" .always 权限。尽管在后台进入地理围栏 10 次,但 2 周内没有发生这种情况。

我还希望许可 "upgrade" 流程能够正常工作,尽管在 WWDC 视频和文档中对 coreLocation 进行了解释,但情况并非如此。

如果 Apple 按原样继续使用 iOS 13,我预计许多在后台合法定位的应用程序将完全停止工作。

有人在这方面取得了进展吗?我已向 Apple 提交 "feedback",但预计在 9 月 iOS 13 GM 之前不会收到他们的及时回复。

我不知道有任何直接的方法可以将权限设置为始终。从 WWDC 视频和实验中,locationManager.requestAlwaysAuthorization() 将提供一个不包含 [Always Allow] 选项的对话框。选择 [Allow While Using App] 会将其置于 "Provisional Always" 模式,但对于用户和应用程序来说,这会造成混淆。用户刚刚设置为"Allow While Using App",但是app认为是"Always",但是还没有,App没有获取到事件,直到第二次提示。非常混乱。我能够得到第二个提示,但不是在事件发生后立即,它取决于 iOS。我也发到Apple Feedback了,希望他们能为需要Always的App提供一些规定。

要查看带有 Allow Always 提示的第二个对话框,您必须:

  1. 禁用蓝色指示灯。
  2. 转到后台。
  3. 至少等待 5 秒。
  4. 尝试获取位置更新或使用任何其他核心位置服务。
  5. 等到用户锁定和解锁设备。

为此,您可以将距离过滤器设置为 none 并开始获取连续的位置更新。

如果您希望在后台传送位置更新,则必须显示蓝色指示器。然后第二个对话框请求 Allow Always 永远不会出现。

当您在 iOS 13 请求用户的 "Always" 位置权限时:

locationManager.requestAlwaysAuthorization()

1) 用户将收到此警报:

2) 如果您请求始终许可并且您的用户选择 Allow While in Use 您的应用会认为它获得了 .authorizedAlways 许可,但这是 provisional .authorizedAlways 许可。

3) 接下来,当您的应用程序通常会在后台接收位置事件时 iOS 不会直接在后台启动带有事件的应用程序,而是等到它认为用户没有做任何事情并且它然后会出现这个对话框:

根据视频,这可能需要一段时间 (6:39):

The prompt that the user can grant your app always authorization from will occur later. {...} Core Location waits for a time when we think that the user is not busy in order to maximize their ability to understand what's going on and minimize the chance that they'll give a get-out-of-my-way kind of response.

在此期间(在应用程序进入后台和显示提示之间)您将不会收到位置更新事件:

They'll be delivered if you app receives always authorization ultimately and not if it receives a when in use authorization. But they also won't be delivered if the user just hasn't chosen yet.

So, during this time, if more events are generated on that basis, if you're monitoring requests, then those events will displace the ones that came earlier, and the earlier ones will be dropped. And then finally Core Location will drop the event part for anything that's become just too old.

4)然后当用户选择Change to Always Allow时,.authorizedAlways权限将成为最终权限(除非用户在将来的某个地方更改它)。您将开始接收位置事件。

除非(5)用户选择Keep Only While Using最终权限会变成.authorizedWhenInUse.

这是演示文稿的概述(我的数字):

完整视频的另一个 link:https://developer.apple.com/videos/play/wwdc2019/705

这是否回答了您的问题?

If I change manually the permission setting to a real .always permission for my app, the app continues to be unable to range locations in the background.

不应该是这样的。你是不是在系统偏好里改了?

试试 GM 种子,也许他们修复了有关此流程的一些错误。