ios - 核心位置不征求许可

标签 ios swift core-location

问题:

出于某种原因,我正在开发的应用并未请求使用定位服务的许可。这曾经工作过。此外,我创建了一个新项目,在该项目中,我完全按照下面描述的步骤进行操作,并在其中立即生效。

一个区别是我知道我正在处理的主应用程序中的授权状态是.Denied,在测试项目中是.NotDetermined。

我在堆栈溢出时读到了这个答案:

Core Location not requesting user permission ' 没有多少人知道这一点,但在您卸载应用程序后,该应用程序的文档和首选项仍存储在设备上,此处:

/var/mobile/Library/安全港/myappidentifier/Container/ 在我看来,这不是苹果的明智之举,因为这可能存在安全风险,正如您在上面所解释的那样。

如果重新安装应用程序,iOS 会自动将这些首选项复制回相应的文件夹中。这就是您所看到的行为的原因。 ' 这可以解释它,因为我确实重新安装了该应用程序,但它没有说明如何解决它。

谢谢

这是我在应用程序中编写的相关代码:

我在 info.plist 中设置了 NSLocationAlwaysUsageDescription 键

我导入的核心位置:

import CoreLocation

实现正确的协议(protocol):

CLLocationManagerDelegate

设置这个属性:

var locationManager  = CLLocationManager()

在 ViewDidLoad 中设置委托(delegate)

locationManager.delegate = self

并写了一个测试函数来测试这个:

        if CLLocationManager.locationServicesEnabled() {
println("Location Services Enabled")
        if CLLocationManager.authorizationStatus() == .Authorized {
            println("Location Services Authorized")
        } else if CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse {
            println("Location Services Authorized WHEN IN USE")
        } else if CLLocationManager.authorizationStatus() == .NotDetermined {
            println("Location Services NOT Authorized: NOT DETERMINED")
        } else if CLLocationManager.authorizationStatus() == .Restricted {
            println("Location Services NOT Authorized: RESTRICTED")
        } else if CLLocationManager.authorizationStatus() == .Denied {
            println("Location Services NOT Authorized: DENIED")
        } else {
            println("Location Services NOT Authorized")
            locationManager.requestAlwaysAuthorization()
        }

    } else {
        println("!!! Location Services NOT Enabled !!!")
    }

控制台输出:

Location Services Enabled
Location Services NOT Authorized

最佳答案

您可以进入“设置”应用、“常规”并重置“位置和隐私”以再次获取您的应用的初始权限对话框。否则,iOS 会保存第一个答案而不再询问。

关于ios - 核心位置不征求许可,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26747533/

相关文章:

iphone - 如何等到位置完全找到? (核心位置)

swift - 从异步完成处理程序获取数据

ios - 如何忽略 SwiftUI 模态背景,或使模态背景清晰/透明?

ios - 这种设计模式称为什么,其中方法是实例方法而不是类方法?

ios - 停止/暂停在 tableview 单元格类中创建的 avplayer

ios - 如何从 iOS (Swift) 连接到 MongoDB

ios - 如何访问 MKMapItem 的类别或类型

ios - 链接 GPUImage 过滤器仅应用最后一个过滤器

ios - 如何使用 Xamarin 在 iOS 中更改 NavigationBar 的标题字距值

Swift:Corelocation 处理 didFailWithError 中的 NSError