时间:2021-08-10 09:25:35 | 栏目:iOS代码 | 点击:次
当编码如下的时候,进入页面的时候可以看到UIAlertView弹出框出现一下,刚想点击的时候,他不见了,这个郁闷
CLLocationManager* _locationManager = [[CLLocationManager alloc] init]; _locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8) { //由于IOS8中定位的授权机制改变 需要进行手动授权 //获取授权认证 [_locationManager requestWhenInUseAuthorization]; } [_locationManager startUpdatingLocation];
究其原因是在arc下用完就被释放了,为了确保用户可以点击权限,只需要将 _locationManager 设置为属性即可,如下:
@property (strong, nonatomic) CLLocationManager* locationManager; self.locationManager = [[CLLocationManager alloc] init]; _locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8) { //由于IOS8中定位的授权机制改变 需要进行手动授权 //获取授权认证 [_locationManager requestWhenInUseAuthorization]; } [_locationManager startUpdatingLocation];
如此再测试,完全没问题!