微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我的 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)!)
            }))

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

@H_502_33@

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐