ios - 无法获取 CLLocationManager 的权限提示

标签 ios core-location

这是我在实现 CLLocationManagerDelegate 的 ViewController 中的代码:

func startLocationManager() {
    let locationManager = CLLocationManager()

    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters


    println("I'm called")


    locationManager.requestAlwaysAuthorization()
    // locationManager.startMonitoringSignificantLocationChanges()
    locationManager.startUpdatingLocation()

    let status = CLLocationManager.authorizationStatus()
    println(status.rawValue) // This print 0 which stands for kCLAuthorizationStatusNotDetermined

    println(CLLocationManager.locationServicesEnabled()) // true
}

func locationManager(manager: CLLocationManager!,
    didUpdateLocations locations: [AnyObject]!) {
    println("nobody call me ever, and I'm sad")
}

出于某种原因,我从来没有得到提示/更改来自动更新位置。我已经在我的设备 iOS 8.1 和 simulartor 上试过了。我遵循了此处的建议:requestAlwaysAuthorization not showing permission alert : “将核心位置框架添加到项目设置/目标/功能/后台模式设置“位置更新”和“使用蓝牙 LE 附件”在 Info.plist NSLocationAlwaysUsageDescription 添加 key 。

我也试过清理和重建,没有任何改变。我觉得很无能。

编辑:这个问题似乎相关:iOS: App is not asking user's permission while installing the app. getting kCLAuthorizationStatusNotDetermined every time - Objective-c & Swift但所选答案及其文章没有暴露任何新内容

最佳答案

您的 CLLocationManager 对象是本地对象,因此在超出范围后将立即释放。将其设为类属性,然后请求授权和确定位置等异步过程将有机会运行。

关于ios - 无法获取 CLLocationManager 的权限提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27606865/

相关文章:

ios - iPhone SDK:CLocationAccuracy。什么常量映射到什么定位技术?

ios - 了解 Parse Geopoint 和 CoreLocation 之间的区别

objective-c - UIImagePickerController Camera Device Front 每隔一段时间才工作

ios - 下载文件时 UIProgressview 不改变

ios 9 - tableview 单元格在调用 cellForRowAtIndexPath 时向下/向上滚动时跳转

ios - 在后台监控 iBeacon 信标

ios - Swift 无法识别 Firebase 用户

ios - UIScreen.main.bounds 返回什么值?屏幕尺寸匹配问题

ios - 从不同线程使用时 NSDateFormatter 崩溃

ios - 在位置访问权限中按下允许按钮后如何执行操作?