如果requestWhenInUseAuthorization失败,则通知

时间:2016-01-31 19:21:47

标签: ios swift

我正在尝试创建一种locationServices权限身份验证,只有具有locationServices权限才能使用该应用程序。因此,如果用户拒绝locationManager.requestWhenInUseAuthorization(),它应该向viewController提供有关此信息的信息。但是,如果用户拒绝通知,我似乎无法收到通知。什么是最好的解决方案?或者应该考虑以另一种方式实现这一目标?

func determinePermission() {

    switch CLLocationManager.authorizationStatus() {

    case .AuthorizedAlways, .AuthorizedWhenInUse:
        if CLLocationManager.locationServicesEnabled() {

        }

    case .NotDetermined:
        locationManager.requestWhenInUseAuthorization()

    case .Restricted, .Denied:

        let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let vc: UIViewController = storyboard.instantiateViewControllerWithIdentifier("PermissionController") as! PermissionViewController

        self.parentViewController!.tabBarController!.presentViewController(vc, animated: true, completion: nil)

    }
}

1 个答案:

答案 0 :(得分:1)

实施 try { var xmlDoc = XDocument.Load(_url); return xmlDoc; } catch (XmlException) { HttpClient http = new HttpClient(); HttpResponseMessage response = await http.GetAsync(new Uri(_url)); var webresponse = await response.Content.ReadAsStringAsync(); var content = XmlCharacterWhitelist(webresponse); var xmlDoc = XDocument.Parse(content); return xmlDoc; } 协议。CLLocationManagerDelegate具有CLLocationManagerDelegate方法,在授权状态更改时会调用该方法。

locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus)