IOS 9 Error Domain=kCLErrorDomain Code=0 “(null)”

2019-01-08 21:59发布

Code below should get current location. But above error is generated. Function didUpdateLocations never gets called.

Running this on a device (iPhone 5s)iOS 9.1. Info.plist has Required device capabilities and Privacy - Location usage description configured as shown in the attached image. Please help!

let locationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()
    locationManager.delegate = self
    locationManager.requestAlwaysAuthorization()
    locationManager.requestLocation()
}


func locationManager(manager: CLLocationManager,
    didFailWithError error: NSError) 
    print(error.description)
}

func locationManager(manager: CLLocationManager, didUpdateLocations
      locations: [CLLocation]) {        
 print(“got location”)
}

Info.plist

6条回答
【Aperson】
2楼-- · 2019-01-08 22:05

searching google true the answers this seems to be a problem since IOS4.0.

in XCODE 7.1 under Project => scheme => edit scheme.

under Run => Options => Core location / disable Allow Location Simulation.

in your IOS Simulator under Debug => Location select a location. This fixed the problem for me.

查看更多
3楼-- · 2019-01-08 22:09

If the location authorization alert is not popping up for you, try adding NSLocationAlwaysUsageDescription to your plist as type string. Also, do the same for NSLocationWhenInUseUsageDescription.

查看更多
地球回转人心会变
4楼-- · 2019-01-08 22:14

I was having the same issue with an app that I was moving from 8.0 -> 9.0/9.1. I tried a couple of things like write the CLLocationManager portion only in Swift and a new Obj-C project as well. I also tested it on different devices. To solve the issue on the device, I removed the didFailWithError func. Which stops the error altogether. This may not seem the best idea but in IOS9 you can limit your application to devices that have GPS or Location-Services. Android has been doing this for a really long time. I also noticed in your .plist your don't have the permissions enabled for NSLocationALwaysUsageDescription or the NSLocationWhenInUseUsageDescrtiption properties included.

Just for reference I have attached what my current .plist looks like that does not fire this error as well as a code chunk in obj-c the controller file. The code starts at the very end of a previous function and then has the commented out didFailWithError delegate and the didUpdateLocations. Currently this is working successfully in IOS 9.1

       //Get map authorization
    [CLLocationManager locationServicesEnabled];
    locationManager = [[CLLocationManager alloc]init];
    locationManager.delegate = self;
    locationManager.allowsBackgroundLocationUpdates = YES;
    if(nil == locationManager) locationManager = [[CLLocationManager alloc]init];
    if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        [locationManager requestAlwaysAuthorization];
    }
    //locationManager.distanceFilter=10;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];



//- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
//{
//    NSLog(@"didFailWithError: %@", error);
//    UIAlertView *errorAlert = [[UIAlertView alloc]
//                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
//    [errorAlert show];
//}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{


    NSLog(@"LocationUpdated: %@",[locations lastObject]);
    [self updateMapMarkers];

//    NSDate* eventDate = location.timestamp;
//    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
//    if(fabs(howRecent) < 15.0){
//        [self updateMapMarkers];
//    }

}

.plist image

查看更多
beautiful°
5楼-- · 2019-01-08 22:19

Please try this :

Go to :

  • Product -> Scheme -> Edit Scheme -> Options -> Allow Location Simulation must be checked and try providing a default location, don't leave it set to "none"

EDIT : As mentionned in the comments, also restart Xcode and you're done !

Hope this helps.

查看更多
Lonely孤独者°
6楼-- · 2019-01-08 22:19

Try this from the Simulator --> Debug --> Location

enter image description here

查看更多
再贱就再见
7楼-- · 2019-01-08 22:22

I have these suggestions for people using apple maps in their app

  1. Don't relay on results of simulator, because always it will not give exact results.
  2. For all map related debugging and execution test on real devices.
  3. As in xcode 8(with my knowledge) you can just connect your iOS device to system and and run the app directly.
  4. Even for above problem the solution is same, just try with real devices your problem will be solved.
查看更多
登录 后发表回答