iphone位置服务提醒回拨允许并且不允许处理

时间:2015-01-30 12:05:13

标签: objective-c iphone ios8 mapkit cllocationmanager

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

Location service iOS alert call back

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

1 个答案:

答案 0 :(得分:6)

实施这个:

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

Swift 2.2:

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if status == .AuthorizedAlways || status == .AuthorizedWhenInUse {
        //allowed - do your logic
    }
    else if status == .Denied {
        //denied
    }
}

Swift 3.0:

func locationManager(_ manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if status == .AuthorizedAlways || status == .AuthorizedWhenInUse {
        //allowed - do your logic
    }
    else if status == .Denied {
        //denied
    }
}

请记住设置您的代理:

self.locationManager.delegate = self;

并由您的班级实施:CLLocationManagerDelegate