用户拒绝位置服务后再次请求权限? [英] Request permissions again after user denies location services?

查看:426
本文介绍了用户拒绝位置服务后再次请求权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟踪用户的位置,并在我的加载首次加载时请求权限:

I track the user's location and ask for permission when my load first loads using this:

locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()

如果用户拒绝,但后来改变主意通过启用我的应用程序中的配置选项,我该怎么再问?例如,我有一个自动检测用户位置的开关,所以当他们启用它时,我正在尝试这样做:

If the user denies, but later changes their mind by enabling the configuration option in my app, how do I ask again? For example, I have a switch for auto detecting the user's location so when they enable it, I am trying to do this:

@IBAction func gpsChanged(sender: UISwitch) {
    // Request permission for auto geolocation if applicable
    if sender.on {
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()
    }
}

但此代码似乎没有做任何事情。我希望它能再次询问用户是否允许该应用程序跟踪用户的位置。这可能吗?

But this code doesn't seem to do anything. I was hoping it would ask the user again if they want to allow the app to track the user's location. Is this possible?

推荐答案

操作系统只会提示用户一次。如果他们拒绝允许,就是这样。您可以做的是通过将 UIApplicationOpenSettingsURLString 传递给 UIApplication openURL:方法。从那里,他们可以根据需要重新启用位置服务。也就是说,你可能不应该过于咄咄逼人地批评它们以获得许可。

The OS will only ever prompt the user once. If they deny permission, that's it. What you can do is direct the user to the Settings for your app by passing UIApplicationOpenSettingsURLString to UIApplication's openURL: method. From there, they can re-enable location services if they wish. That said, you probably shouldn't be too aggressive about bugging them for the permission.

这篇关于用户拒绝位置服务后再次请求权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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