我正在使用我的应用委托来请求我的应用用户授权使用位置服务。如果用户接受,这一切都正常,但如果用户不接受应用程序将在需要位置服务时进入一个持续的崩溃循环,并且不会给他们另一个接受权限的机会。我没有看到导致它崩溃的原因,但我会在下面发布应用代理代码,错误和视图代码。
ERROR
[5091:2158600] *因未捕获的异常而终止应用 'NSInvalidArgumentException',原因:' - [__ NSCFConstantString objectForKey:]:无法识别的选择器发送到实例0x1000981a0' * 第一次抛出调用堆栈:(0x18176ee38 0x180dd3f80 0x181775ccc 0x181772c74 0x181670d1c 0x100083158 0x18699e844 0x18699de88 0x18699dc44 0x18699da50 0x186c08930 0x1869a39b0 0x1868b39c8 0x1868d9220 0x1868b36ac 0x1868b2c40 0x1820a0d50 0x1868b2ac4 0x1868c0578 0x1872570a8 0x1868f0e90 0x1869089c8 0x1869b9544 0x186c18740 0x186b6afd8 0x186b78990 0x1868aa4a4 0x1817247b0 0x181722554 0x181722984 0x18164cd10 0x182f34088 0x186921f70 0x100082a14 0x1811ea8b8)libc ++ abi.dylib:以未捕获终止 NSException类型的异常
appdelegate.m
@synthesize locationManager = _locationManager;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager requestWhenInUseAuthorization];
return YES;
}
view.m
- (void)viewDidLoad {
[super viewDidLoad];
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(@"test1");
_locationManager = [[CLLocationManager alloc]init]; //initializing locationManager
_locationManager.delegate = self;
[_locationManager requestWhenInUseAuthorization]; //iOS 8 MUST
_locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
_locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[_locationManager startUpdatingLocation]; //requesting location updates
[self downloadorders];
}
else{
NSLog(@"test2");
_locationManager = [[CLLocationManager alloc] init];
[_locationManager requestWhenInUseAuthorization];
latitude=0;
longitude=0;
}
}