CLLocationManager startUpdatingLocation not calling locationManager:didUpdateLocations: or locationManager:didFailWithError:
Just 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
Fbsopenapplicationerrordomain Code =4 Error
Swift Framework: Umbrella Header '[...].H' Not Found
Avcapturevideopreviewlayer Orientation - Need Landscape
iOS Autolayout Vertically Equal Space to Fill Parent View
iOS Autolayout to Center My View Between Two Views
This Certificate Was Signed by an Unknown Authority
Stretch Background Image for Uibutton
How to Animate Tab Bar Tab Switch with a Crossdissolve Slide Transition
The Identity Used to Sign the Executable Is No Longer Valid
How to Check Where My App Is Using Idfa
Multiline Uilabel with Adjustsfontsizetofitwidth
Our App Crashed in iOS 9 Which Upload by Xcode 10
Detect If a User Has Typed an Emoji Character in Uitextview
Location Update Even When App Is Killed/Terminated
How to Make Both Header and Footer in Collection View with Swift