我在info.plist
中设置了NSLocationAlwaysUsageDescription
和NSLocationWhenInUseUsageDescription
,当应用想要使用位置服务时会出现警告,但是警报只出现了一小段时间,我无法单击此警报。此警报自动消失!
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)
{
}
尝试以下代码。它对我有用
关于ios - iOS 9 中定位服务权限提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35865831/