需求: 点击按钮的时候,判断是否可以弹出系统的地址权限弹窗,如果可以则弹出,如果不可以则跳转到系统设置
我们需要根据当前的 CLAuthorizationStatus来判断是否能弹出弹窗
当状态为kCLAuthorizationStatusNotDetermined的时候可以弹出
- (void)clickLocation
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusNotDetermined) {
self.manager = [[CLLocationManager alloc] init];
[self.manager requestWhenInUseAuthorization];
self.manager.delegate = self;
} else {
[self goSyemtmSetting];
}
}
然后我们要遵循 CLLocationManagerDelegate 代理并实现代理方法 didChangeAuthorizationStatus 是
权限有改动的代理
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
[self reloadData];
}