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

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

概述我的 Swift应用程序要求允许通过CLLocationManager访问当前位置.当用户点击“不允许”时,如何显示警告消息? 你想看看 func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) 和 CLLocationManager.au 我的 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)!)            }))

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

总结

以上是内存溢出为你收集整理的如何在Swift中用户禁用位置时显示警报?全部内容,希望文章能够帮你解决如何在Swift中用户禁用位置时显示警报?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1007913.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存