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

当用户在Swift中禁用位置时,如何显示警报?,swift,ios8,xcode6,core-location,cllocationmanager,Swift,Ios8,Xcode6,Core Location,Cllocationmanager,我的Swift应用程序要求允许通过CLLocationManager访问当前位置。当用户点击“不允许”时,如何显示警报消息?您要查看 func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) 及 第一个在用户更改授权状态时调用,第二个将允许您随时确定当前状态 然后,显示消息,例如: let alert = UIAlertControl

我的Swift应用程序要求允许通过CLLocationManager访问当前位置。当用户点击“不允许”时,如何显示警报消息?

您要查看

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

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

然后,显示消息,例如:

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

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

救命啊,@MirekE!谢谢:)“authorizationStatus()”在iOS 14.0中被弃用。。。见主题:
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)!)
            }))