I\'m trying to use the CLLocationManager
framework in my iOS project to access the user\'s location but when I call
[locationManager startUpdat
Just add this in info.plist
NSLocationAlwaysUsageDescription --- I need Location
NSLocationWhenInUseUsageDescription --- I need Location
privacy - location usage description --- I need Location
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
So if you are running in simulator don't forget to set location in simulator menu. It looks like if it is set to none nothing is called in delegate... I am not sure than if this can happen on real device too but probably it's simulator specific.
You need to add below things to your project,
In plist of your project add these things:
Key: NSLocationAlwaysUsageDescription Type:String
Key: NSLocationWhenInUseUsageDescription Type:String
In the .m file with [locationManager startUpdatingLocation]
add this condition :
if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
[locationManager requestAlwaysAuthorization];`
Then only your CLLocationManager
delegate methods will get called.
Location Services work a bit differently starting in iOS 8.
Mainly, you need to add a key NSLocationWhenInUseUsageDescription
to your Info.plist file, and add a description why your app need Location, such as "Location needed to ...".
Note that you might also have to check for iOS version. Only iOS 8 and up have the Location Manager listen to the requestWhenInUseAuthorization
call.
The link below shows more details: http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/
Good luck!
With iOS 8.0 you need to call -[CLLocationManager requestWhenInUseAuthorization
]
or -[CLLocationManager requestAlwaysAuthorization]
first so the user gets asked to give your app permission to use the location.
You strongly need to check that you initialize CLLocationManager on main thread. In other case you will not get updateLocation event.
I can't find such info in Apple docs but it works for me anyway.