加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在Swift中用户禁用位置时显示警报?

发布时间:2020-12-14 04:44:01 所属栏目:百科 来源:网络整理
导读:我的 Swift应用程序要求允许通过CLLocationManager访问当前位置.当用户点击“不允许”时,如何显示警告消息? 解决方法 你想看看 func locationManager(manager: CLLocationManager,didChangeAuthorizationStatus status: CLAuthorizationStatus) 和 CLLocati
我的 Swift应用程序要求允许通过CLLocationManager访问当前位置.当用户点击“不允许”时,如何显示警告消息?

解决方法

你想看看

func locationManager(manager: CLLocationManager,didChangeAuthorizationStatus status: CLAuthorizationStatus)

CLLocationManager.authorizationStatus()

第一个是在用户更改授权状态时调用的,第二个是允许您随时确定当前状态.

然后,显示消息,例如:

let alert = UIAlertController(title: "Your title",message: "GPS access is restricted. In order to use tracking,please enable GPS in the Settigs app under Privacy,Location Services.",preferredStyle: UIAlertControllerStyle.Alert)
            alert.addAction(UIAlertAction(title: "Go to Settings now",style: UIAlertActionStyle.Default,handler: { (alert: UIAlertAction!) in
                print("")
                UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)
            }))

上面的代码显示警报,并允许用户直接进入设置以启用位置.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读