Reputation: 45
I have set the NSLocationAlwaysUsageDescription
and NSLocationWhenInUseUsageDescription
in info.plist
, the alert appears when the app wants to use the location service, but the alert just appear for a little time and I can't click on this alert. This alert disappear automatically!
func showLocation(sender: UIButton)
{
let manager = CLLocationManager()
manager.delegate = self
if CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedAlways
{
manager.requestWhenInUseAuthorization()
}
manager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
for location in locations {
print("The location is (location)")
}
}
Upvotes: 0
Views: 2958
Reputation: 1895
self.locationManager = [[CLLocationManager alloc]init];
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] && [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
[self.locationManager requestWhenInUseAuthorization];
}
}
else if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied)
{
//Location Services is off from settings
}
else if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted)
{
}
Try Following code. It worked for me
Upvotes: 2