无法从CLLocationManager获取权限提示

时间:2014-12-22 16:46:17

标签: 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"。

我也试图清理和重建,没有任何改变。我感到无能为力。

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

1 个答案:

答案 0 :(得分:1)

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