MKMapview
current user location not fire in iOS-8
,previous iOS-7
& iOS-6
are working fine.
self.mapView.delegate = self;
self.mapView.showsUserLocation =YES;
In this line to call automatically the user current location delegate methods
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
}
but it not fire in iOS-8
.
In iOS8, you need to request user's authorization before getting their location.
There are two kinds of request:
-[CLLocationManager requestWhenInUseAuthorization]
lets you get users' location only when the app is awaken.
-[CLLocationManager requestAlwaysAuthorization]
lets you get users' location even when it's in the background.
You can choose between them accordingly.
For example, put this before you start updating location:
// ask for authorization
CLLocationManager * locationManager = [[CLLocationManager alloc] init];
// check before requesting, otherwise it might crash in older version
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
Furthermore, don't forget to add two keys
NSLocationWhenInUseUsageDescription
and
NSLocationAlwaysUsageDescription
into your info.plist.
Leave the values empty to use the default messages or you can customize your own by inputting the values.
In ios 8 Authorization is required as below
NSString * osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue]>= 8.0 ) {
[_CLLocationManager requestAlwaysAuthorization]; //Requests permission to use location services whenever the app is running.
// [_CLLocationManager requestWhenInUseAuthorization]; //Requests permission to use location services while the app is in the foreground.
}
[_CLLocationManager startUpdatingLocation];
And you need to add two keys in the plist
1.NSLocationAlwaysUsageDescription
2.NSLocationWhenInUseUsageDescription
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With