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

IphoneCllocationmanagerIos9

Iphone Problem Overview


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

Iphone Solutions


Solution 1 - Iphone

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.

Solution 2 - Iphone

In XCode 11.5 and up...

Open your Simulator:

Features => Location => CustomLocation

enter image description here

Solution 3 - Iphone

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.

Solution 4 - Iphone

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.

Solution 5 - Iphone

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

enter image description here

Solution 6 - Iphone

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

Solution 7 - Iphone

I am using XCode 12.5/IOS 14. This is what I have done to resolve the issue

  1. In XCode, go to menu "Product -> Scheme -> Edit scheme" OR press "Shift+Command+<"
  2. Click on "Run" from the left pane and then "Options"
  3. You will find "Core Location" field, make sure "Allow Location Simulation" is checked
  4. Also, do not leave "Default Location" drop-down to "None". Select any city
  5. Close. No need to restart XCode

Solution 8 - Iphone

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.

Solution 9 - Iphone

In my case I was assigning the return of CLLocationManager() to a variable inside of the ViewControllers viewDidLoad override.

As soon as that lifecycle method completes the object reference is released; dismissing the dialog before a user has a chance to respond, also causing issues with logic else where that may depend on that reference.

I just had to move the assignment out of the life cycle method override to the root of the class I was using it in.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTusshuView Question on Stackoverflow
Solution 1 - IphoneH4HugoView Answer on Stackoverflow
Solution 2 - IphoneRoberto RodriguezView Answer on Stackoverflow
Solution 3 - Iphoneuser5516570View Answer on Stackoverflow
Solution 4 - IphoneDustPhyteView Answer on Stackoverflow
Solution 5 - IphonePrimeDimeView Answer on Stackoverflow
Solution 6 - IphoneBig KahunaView Answer on Stackoverflow
Solution 7 - IphoneAmit BaderiaView Answer on Stackoverflow
Solution 8 - Iphoneuser6698531View Answer on Stackoverflow
Solution 9 - IphoneDonaldView Answer on Stackoverflow