Search code examples
objective-ccllocationmanagerupdatingupstart

CLLocation Manager work only for the application first run


CLLocation Manager work only for the application first run. This is my code.

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
    [self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];

Solution

  • I found the solution, the probleme was from simulator when you restart the application the location turn to the default location which is none.

    So when i restart my app i got the the error didFailWithError: Error Domain=kCLErrorDomain Code=0.

    You should when reopen the application choose a new location from debug -> location, or use a device for test.