CLLocation didupdatetolocation not called

I tried to solve this problem for several days, but could not find any solutions that work. I checked all the posts in stackoverflow and tried all of their solutions, and nothing seems to work. I also tried the Apple test project for CLLocation, which works great for me. I used bits and pieces from the Apple Test Project

https://developer.apple.com/library/ios/samplecode/LocateMe/Listings/README_md.html

But my code doesn't work at all. Unable to get the name DidupdateToLocation.

Here is my code (in viewDidLoad)

_locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // This is the most important property to set for the manager. It ultimately determines how the manager will // attempt to acquire location and thus, the amount of power that will be consumed. self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; // Once configured, the location manager must be "started" // // for iOS 8, specific user level permission is required, // "when-in-use" authorization grants access to the user location // // important: be sure to include NSLocationWhenInUseUsageDescription along with its // explanation string in your Info.plist or startUpdatingLocation will not work. // if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; } [self.locationManager startUpdatingLocation]; [self performSelector:@selector(stopUpdatingLocationWithMessage:) withObject:@"Timed Out" afterDelay:30]; 

I checked to make sure locationServicesEnabled is enabled.

I added the NSLoationWhenInUseUsageDescription property to the info.plist file. Is there any other property that I need to add or enable any services?

For the sake of love for God, I cannot find out what I did wrong. Can someone please help me with this.

+6
source share
5 answers

Stupid to me. I added keywords to the wrong plist file. Now it works for me. Thanks for helping the guys.

0
source

You should call startUpdatingLocation after you received the didChangeAuthorizationStatus callback on iOS8.

 //iOS 8 API change if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){ [self.locationManager requestWhenInUseAuthorization]; }else{ [self.locationManager startUpdatingLocation]; } 

implement this delegate method:

 -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { switch (status) { case kCLAuthorizationStatusNotDetermined: case kCLAuthorizationStatusRestricted: case kCLAuthorizationStatusDenied: { // do some error handling } break; default:{ [self.locationManager startUpdatingLocation]; } break; } } 
+6
source

First, do not forget that with iOS 8 you need to do [locationManager requestWhenInUseAuthorization] plus [locationManager requestAlwaysAuthorization];

 _locationManager = [CLLocationManager new]; if(SYSTEM_IS_OS_8_OR_LATER) { [_locationManager requestWhenInUseAuthorization]; [_locationManager requestAlwaysAuthorization]; } _locationManager.delegate = self; _locationManager.desiredAccuracy = kCLLocationAccuracyBest; //and the problem with your code : don't forget to start _locationManager startUpdatingLocation]; 

and in didUpdateLocations

  - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ _currentLocation = [locations objectAtIndex:0]; //do your stuff with the location } 
+6
source

I'll just spend the whole night on it [to be honest, I'm a relatively new OOC], anyway the problem ..

didUpdateLocation compiles and is never called didUpdateLocations compiles and works!

Not the answer in this case, it would seem, but it is easy to make a mistake in this question. Using iOS 8.1.3 and Xcode 6.1.1

0
source

Just add three properties to Info.plist.

To get the current location if it does not call the doUpdateToLocation method

NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription privacy - location usage description type String.

0
source

Source: https://habr.com/ru/post/976300/


All Articles