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)")
}
}
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.