问题描述
根据Apple,如果您要求核心位置"应用在未确定"授权时获得始终"授权,则用户会看到使用中"授权对话框,但实际上您的应用是临时获得始终"授权的对话框.
According to Apple, if you ask for your Core Location app to get Always authorization when the authorization is "not determined", the user sees the dialog for When In Use authorization but in fact your app gets Always authorization — provisionally.
这应该意味着,如果您实际上没有使用您的始终"电源,您将失去它们,恢复为使用时".
This is supposed to mean that if you don't actually use your Always powers, you will lose them, reverting to When In Use.
好的,但是什么时候会恢复原状?我似乎无法实现.即使 user 认为它只是使用中"授权,我的应用仍处于始终"授权状态.
Okay, but when will that reversion happen? I can't seem to make it happen. My app just stays at Always authorization, even though the user thinks it is only When In Use authorization.
这是我的测试应用(iOS 14)的全部代码:
Here's the entire code of my test app (iOS 14):
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var label: UILabel!
let locman = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locman.delegate = self
}
@IBAction func doAskForAlways(_ sender: Any) {
self.checkForLocationAccess(always:true)
}
func checkForLocationAccess(always:Bool = false, andThen f: (()->())? = nil) {
let status = self.locman.authorizationStatus()
switch status {
case .authorizedWhenInUse:
if always { // try to step up
self.locman.requestAlwaysAuthorization()
} else {
f?()
}
case .authorizedAlways:
f?()
case .notDetermined:
if always {
self.locman.requestAlwaysAuthorization()
} else {
self.locman.requestWhenInUseAuthorization()
}
case .restricted:
break
case .denied:
break
default: fatalError()
}
}
fileprivate func updateStatus(_ status: CLAuthorizationStatus) {
self.label.text = {
switch status {
case .authorizedAlways: return "Always"
case .authorizedWhenInUse: return "When In Use"
default: return ""
}
}()
}
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
let status = manager.authorizationStatus()
print("authorization is", status.rawValue)
updateStatus(status)
}
@IBAction func doStatus(_ sender: Any) {
self.updateStatus(self.locman.authorizationStatus())
}
}
您需要两个按钮和一个标签.当您无权以(未确定")开头时,轻按第一个按钮以询问总是授权".您会看到使用中授权"对话框.授予授权.现在使用该应用程序,并继续观察标签中的状态显示.如果需要,您可以点击第二个按钮以更新状态.
You need two buttons and a label. Tap the first button to ask for Always authorization when you have no authorization to start with ("not determined"). You see the When In Use authorization dialog. Grant authorization. Now play with the app and keep watching the status display in the label. You can tap the second button to update the status if needed.
问题在于它停留在Always(始终)状态.我的准备"何时会提交给您?终止,以便授权恢复为何时使用"?我如何鼓励这种情况发生?
The problem is that it stays at Always. When will my "provision" come to an end so that the authorization reverts to When In Use? How can I encourage this to happen?
推荐答案
在WWDC 2019的核心位置的新功能" ,它们概述了iOS 13.0的基本过程:
In WWDC 2019's What's New in Core Location, they outline the basic process in iOS 13.0:
-
您的应用请求始终"许可.
Your app requests "always" permission.
用户看到使用中"权限警报,而不是始终"权限警报:
The user sees "when in use" permissions alert, not an "always" permission alert:
如果用户授予使用时",则该应用程序将始终处于临时设置"状态.
If the user grants "when in use" the app is in "provisional always" state.
在这种情况下(有些令人困惑),当您处于始终设置为临时"状态时,authorizationStatus
将返回.authorizedAlways
,并且手机上的设置"应用会建议其处于正在使用"状态.但实际上,它处于这种始终为临时"状态,不完全可以从authorizationStatus
或从您在设置"应用中看到的内容中推断出来.
In this case, and somewhat confusingly, the authorizationStatus
will return .authorizedAlways
when you are in this "provisional always" state and the Settings app on the phone will suggest it’s in "when in use" state. But in reality, it’s in this "provisional always" state, not quite what one might infer from authorizationStatus
nor from what you see in the Settings app.
不用说,如果用户甚至不授予使用时"(例如,他们拒绝或选择仅一次"),那么显然您将不会处于总是临时"状态.
Needless to say, if the user doesn't even grant "when in use" (e.g. they deny or chose "only once"), then obviously you won’t be in "provisional always" state.
它会一直保持这种临时状态,直到视频中所说的那样,您开始使用总是"使用电源"为止.例如,如果您启动重大更改服务并移动足以触发重大更改的距离.
It remains in this provisional state until, as the video says, you "start using ‘always’ powers". For example, if you start significant change service and move a distance sufficient to trigger a significant change.
当应用确实开始使用'总是'使用"电源时,操作系统将询问用户是否愿意将使用时"升级为始终". (它不会总是立即发生,而是会等到用户不忙于做其他事情时,以降低他们为了恢复到正在做的事情而放弃警报的风险.)
When the app does "start using ‘always’ powers", the OS will ask the user if they are is willing to upgrade "when in use" to "always". (It won't always happen immediately, but will wait until the user is not busy doing other things, to reduce the risk that they'll dismiss the alert just to get back to what they were doing.)
因此,这不是恢复"到其他状态的问题.该应用程序将一直处于始终临时设置"状态,直到达成最终协议"(用户看到第二个警报并同意升级到.authorizedAlways
或拒绝并设置为.authorizedWhenInUse
).
So, it’s not a question of "reverting" to some other state. The app will remain in this "provisional always" state until there is final "agreement" (where the user sees the second alert and either agrees to upgrade to .authorizedAlways
or denies and it is set to .authorizedWhenInUse
).
我知道您知道这一点,但是为了将来的读者:
I know you know this, but for the sake of future readers:
在WWDC 2020视频位置的新变化中,他们描述了iOS 13.4中引入的更改. iOS 13.4引入了一种替代方法,而不是上面的流程(您要求始终",用户会看到使用时"权限,并且在实际触发始终"服务之前他们不会看到升级到始终"权限).新流程,您可以在其中要求何时使用"(而不是始终")并假设用户已授予它,则可以稍后在应用程序中的适当位置要求始终",然后用户会收到第二次警报(这次询问用户是否要升级到始终").您只需要适当的权限字符串即可.
In WWDC 2020 video What's new in location, they describe a change introduced in iOS 13.4. Instead of the flow above (where you ask for "always", the user sees "when in use" permissions, and they don’t see the "upgrade to always" until "always" services are actually triggered), iOS 13.4 introduced a new flow, where you can ask for "when in use" (rather than "always") and assuming the user granted it, you can ask for "always" later, where appropriate in the app, and the user get the second alert (this time asking if the user would like to upgrade to "always" or not). You just need the appropriate permissions strings.
这篇关于是什么使临时授权始终为临时授权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!