iphone定位服务警报回叫允许并且不允许处理

Raj*_*ari 1 iphone objective-c mapkit cllocationmanager ios8

我有一个按钮,其中点击我授权我的应用程序启用位置服务.我想从警报中捕获允许按钮事件.当用户按下允许时,我的按钮颜色将变为其他颜色.我无法捕获允许按钮的回调.但是,我可以通过此链接捕获不允许按钮事件

位置服务iOS提醒回电

请任何人都可以告诉我如何捕获允许按钮点击并成功我想要我的代码.

Kli*_*akM 7

实现这个:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
        //allowed - do your logic
    }
    else if (status == kCLAuthorizationStatusDenied) {
        //denied
    }
}
Run Code Online (Sandbox Code Playgroud)

Swift 2.2:

self.locationManager.requestAlwaysAuthorization()
Run Code Online (Sandbox Code Playgroud)

Swift 3.0:

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
    switch status {
    case .notDetermined:
        manager.requestAlwaysAuthorization()
    case .restricted, .denied:
        // location services unauthorized
    case .authorizedAlways, .authorizedWhenInUse:
        manager.startUpdatingLocation()
    @unknown default:
        print("New CLLocationManager.authorizationStatus() not handled!")
    }    
}
Run Code Online (Sandbox Code Playgroud)

记得设置你的代表:

self.locationManager.delegate = self;
Run Code Online (Sandbox Code Playgroud)

并由您的班级实现: locationManager