requestAlwaysAuthorization not showing permission alert

前端 未结 17 1145
我寻月下人不归
我寻月下人不归 2020-12-29 20:19

I\'m trying to use some fancy iBeacons without success, kCLAuthorizationStatusNotDetermined all time. According to other questions it\'s a requirement to add those keys to

17条回答
  •  無奈伤痛
    2020-12-29 20:57

    I have noticed that if your instance of CLLocationManager is destroyed before the alert shows, you will never see the alert. In my case I was creating a local variable of the location manager in the AppDelegate to ask for permission.

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        [locationManager requestAlwaysAuthorization];
    }
    

    Changing the local variable to an instance variable made the alert to display:

    @interface AppDelegate () {
        CLLocationManager *_locationManager;
    }
    @end
    
    _locationManager = [[CLLocationManager alloc] init];
    if ([_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        [_locationManager requestAlwaysAuthorization];
    }
    

提交回复
热议问题