gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 23:00:03 27 4
gpt4 key购买 nike

我的 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 中禁用位置时如何显示警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32001403/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com