Solution with backward compatibility which doesn't produce Xcode warnings:
SEL requestSelector = NSSelectorFromString(@"requestWhenInUseAuthorization");
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined &&
[self.locationManager respondsToSelector:requestSelector]) {
((void (*)(id, SEL))[self.locationManager methodForSelector:requestSelector])(self.locationManager, requestSelector);
[self.locationManager startUpdatingLocation];
} else {
[self.locationManager startUpdatingLocation];
}
Setup NSLocationWhenInUseUsageDescription
key in your Info.plist
.
For iOS version 11.0+ :
Setup NSLocationAlwaysAndWhenInUseUsageDescription
key in your Info.plist
. along with other 2 keys.