If you are using Location Manager to get user's current location then you have ask Location Permission first. iOS provides you access to user's location if user accepts it. Here is the code :-
Below code will return you location manager object.
-(CLLocationManager*) getLocation{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
return locationManager;
}
After implementing above code just open your .plist file and add two properties to display permission alert with custom message.
- NSLocationWhenInUseUsageDescription
- Privacy - Location Usage Description
See attached screenshot for help.
Happy Coding!!!
0 Comment(s)