Discuss the problem of iOS location permission pop up box flashing in detail
- 2021-12-19 07:03:39
- OfStack
When the code is as follows, when you enter the page, you can see that UIAlertView pop-up box appears under 1. When you just want to click, he is gone. This is depressed
CLLocationManager* _locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8) {
// Due to IOS8 Change of authorization mechanism located in Manual authorization is required
// Obtain authorization authentication
[_locationManager requestWhenInUseAuthorization];
}
[_locationManager startUpdatingLocation];
The reason is that it is released after being used up under arc. In order to ensure that users can click permissions, they only need to set _ locationManager as an attribute, as follows:
@property (strong, nonatomic) CLLocationManager* locationManager;
self.locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8) {
// Due to IOS8 Change of authorization mechanism located in Manual authorization is required
// Obtain authorization authentication
[_locationManager requestWhenInUseAuthorization];
}
[_locationManager startUpdatingLocation];
It's no problem to test again like this!