问题描述:

didUpdateLocations is never called, instead didFailWithError is called with denied code kCLErrorDenied.

Here are the things that i did:

#import "ViewController.h"

@import CoreLocation;

@interface ViewController () <CLLocationManagerDelegate>

@property (strong, nonatomic) CLLocationManager *locationManager;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

self.locationManager = [[CLLocationManager alloc] init];

self.locationManager.delegate = self;

// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {

[self.locationManager requestWhenInUseAuthorization];

}

[self.locationManager startUpdatingLocation];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(nonnull NSArray<CLLocation *> *)locations

{

NSLog(@"update");

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(nonnull NSError *)error

{

NSLog(@"error");

}

@end

Inserted NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription to the info.plist of the app. Enabled Background Modes in Capabilities with Location updates selected. Get help from the very famous blog post. I receive Location Access Request popup and allow the app to access location.

But i couldnt managed to get location updates. It works in IPAD with IOS 8 but not work at ipad with IOS version 9.3.2. How can i make location updates work in IOS 9.3.2?

网友答案:

trying following thing may resolve your issue:

  • go to settings and reset your location services
  • reset your network settings
  • restarting the simulator

also, if you have Scheme/Edit Scheme/Options/Allow Location Simulation checked but don't have a default location set.

Add NSLocationAlwaysUsageDescription to your plist as type string if using Always authorization. Also, do the same for NSLocationWhenInUseUsageDescription same way if using WhenInUse authorization.

For detail check answers here:

didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

and IOS 9 Error Domain=kCLErrorDomain Code=0 "(null)"

相关阅读:
Top