问题:
出于某种原因,我正在开发的应用并未请求使用定位服务的许可。这曾经工作过。此外,我创建了一个新项目,在该项目中,我完全按照下面描述的步骤进行操作,并在其中立即生效。
一个区别是我知道我正在处理的主应用程序中的授权状态是.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/