ios - iOS 9 中定位服务权限提醒

标签 ios xcode swift cllocationmanager

我在info.plist中设置了NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription,当应用想要使用位置服务时会出现警告,但是警报只出现了一小段时间,我无法单击此警报。此警报自动消失!

 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/

相关文章:

ios - 如何快速解析 TVos 中返回的 CKSubscription 用户信息字段

swift - iOS JSON 的设计模式

arrays - Swift 4 按值复制内部有数组的对象数组

ios - 在后台检测应用程序是否已启动

ios - 如何在 Swift 中打印出核心数据保存错误

ios后台下载完成但 View 已被破坏

ios - 更新解析值

ios - 如何在导航栏 Swift 右侧添加自定义 View ?

ios - iOS 9 及更低版本的 UIApplication.shared().open() 的替代方法是什么?

iOS 如何在没有设备的情况下创建开发配置?