Cllocationmanager Startupdatinglocation Not Calling Locationmanager:Didupdatelocations: or Locationmanager:Didfailwitherror:

CLLocationManager startUpdatingLocation not calling locationManager:didUpdateLocations: or locationManager:didFailWithError:

Sample ImageJust add this in info.plist

NSLocationAlwaysUsageDescription --- I need Location

NSLocationWhenInUseUsageDescription --- I need Location

privacy - location usage description --- I need Location

Note that "I need Location" should be changed to describe your actual app's designed usage. It is communicated to the end user in the authorization message. (thanks @devios1)

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

Now it will call your didUpdateToLocation definitely.

for more details click here

Why is locationManager (:didUpdateLocations) not called

You need to make

let locManager = CLLocationManager()

an instance var to hold a strong reference for the delegate , also you either need 1 of these

locManager.startUpdatingLocation()
locManager.requestLocation()

CLLocationManager requestLocation not calling didUpdateLocations

Without seeing your full main window code, I bet that the problem is with the scope and lifecycle of your controller:

override func viewDidLoad() {
let weather = DarkSkyWeatherController()
weather.weatherGetterDelegate = self
weather.getLocation()
// Function exits. The weather constant dies off.
// This is why you don't get callbacks.
}

Do the following, instead.

let weather = DarkSkyWeatherController()
override func viewDidLoad() {
weather.weatherGetterDelegate = self
weather.getLocation()
// Function exits, but the weather constant lives on as a field of your main ViewController. You'll get your callbacks now.
}

App crashes when using locationManager.requestLocation()

You may need to implement

func locationManager(_ manager: CLLocationManager, 
didFailWithError error: Error) { --- }

Delegate method of CLLocationManagerDelegate

CLLocationManager not calling didUpdateLocations

Perhaps it's just the result of a typo.

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

should be

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

You forgot the "r" at the end of "locationManager".

CLLocationManager startUpdatingLocation not working

Assign the CLLocationManager to a (strong) property on your class. (I assume you're using ARC BTW.) Right now the CLLocationManager doesn't live past the end of the viewDidLoad method, so it won't get to call your delegate method either.



Related Topics



Leave a reply



Submit