Swift2 如何知道用户是否拒绝Swift 2中的定位服务

Swift2 如何知道用户是否拒绝Swift 2中的定位服务,swift2,cllocationmanager,Swift2,Cllocationmanager,我正在尝试创建位置服务应用程序,我有以下代码,因此当用户转到该视图控制器时,他将收到获取当前位置的警报 这是密码 override func viewDidLoad() { super.viewDidLoad() // 1. status is not determined if CLLocationManager.authorizationStatus() == .NotDetermined { locationManager.reque

我正在尝试创建位置服务应用程序,我有以下代码,因此当用户转到该视图控制器时,他将收到获取当前位置的警报

这是密码

override func viewDidLoad() {
        super.viewDidLoad()
// 1. status is not determined
        if CLLocationManager.authorizationStatus() == .NotDetermined {
            locationManager.requestAlwaysAuthorization()
        }
            // 2. authorization were denied
        else if CLLocationManager.authorizationStatus() == .Denied {



            SwiftSpinner.hide()
            let alert = UIAlertController(title: "Error with Your Location" , message: "Location services were previously denied. Please enable location services for this app in Settings.", preferredStyle: UIAlertControllerStyle.Alert)
            let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) {
                UIAlertAction in
                UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)


            }
            alert.addAction(ok)
            let cancel = UIAlertAction(title: "Back", style: UIAlertActionStyle.Default) {
                UIAlertAction in

                self.movenav("arxiki")

            }
            alert.addAction(cancel)
            self.presentViewController(alert, animated: true, completion: nil)

        }
            // 3. we do have authorization
        else if CLLocationManager.authorizationStatus() == .AuthorizedAlways {
            locationManager.startUpdatingLocation()
        }


        self.navigationController?.setNavigationBarHidden(false, animated: true)

       self.eventsTable.backgroundColor = UIColor.lightGrayColor()

       // self.locationManager.requestAlwaysAuthorization()

        if CLLocationManager.locationServicesEnabled() {
            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
            locationManager.startUpdatingLocation()
        } 

    }
我的问题如下。
如果用户按下“请勿授权”按钮,我如何获取他的选项,以便将他发送回上一个视图控制器,或向他发送我收到的消息?

为了捕获用户选择,您需要声明CLLocationManager对象并实现其委托(CLLocationManagerDelegate)并使用以下方法捕捉它

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if status == .Denied || status == .NotDetermined{
       // User selected Not authorized
    }       
}
我假设您已经使用合适的位置参数配置了info.plist


希望有帮助

为了捕获用户选择,您需要声明一个CLLocationManager对象并实现其委托(CLLocationManagerDelegate),并使用以下方法捕获它

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if status == .Denied || status == .NotDetermined{
       // User selected Not authorized
    }       
}
我假设您已经使用合适的位置参数配置了info.plist


希望有帮助

Thx。这确实有帮助。Swift 5中的命令已更改为:func locationManager(umanager:CLLocationManager,didChangeAuthorization状态:CLAuthorizationStatus)Thx。这确实有帮助。Swift 5中的命令已更改为:func locationManager(u-manager:CLLocationManager,didChangeAuthorization状态:CLAuthorizationStatus)