- (void) isLocationEnabled: (CDVInvokedUrlCommand*)command
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSLog(@"Loading Location status...");
CDVPluginResult* pluginResult;
if([self isLocationEnabled] && [self isLocationAuthorized]) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:1];
}
else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:0];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
dispatch_async(dispatch_get_main_queue(), ^{
});
});
}
- (BOOL) isLocationEnabled
{
if([CLLocationManager locationServicesEnabled]) {
NSLog(@"Location is enabled.");
return true;
} else {
NSLog(@"Location is disabled.");
return false;
}
}
- (BOOL) isLocationAuthorized
{
if([CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) {
NSLog(@"This app is authorized to use location.");
return true;
} else {
NSLog(@"This app is not authorized to use location.");
return false;
}
}
调用isLocationEnabled并查看日志,执行isLocationEnabled需要2秒,执行isLocationAuthorized需要6秒。当我们从后台状态恢复应用时会发生这种情况。任何的想法?
Xcode log:
2015-11-18 15:13:30:840 AppName [4538:60036] Loading Location status...
2015-11-18 15:13:32:103 AppName [4538:60036] Location is enabled.
2015-11-18 15:13:38:345 AppName [4538:60036] This app is authorized to use location.