【问题标题】:Unable to get the permission prompt from CLLocationManager无法从 CLLocationManager 获取权限提示
【发布时间】:2015-02-20 19:10:19
【问题描述】:

这是我实现 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 和模拟器上进行了尝试。我遵循了这里的建议: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,但所选答案及其文章没有公开任何新内容

【问题讨论】:

  • 您是否在应用的Info.plist 文件中为NSLocationAlwaysUsageDescription 键设置了字符串。否则,您将不会看到权限提醒。
  • 是的,我设置了一个虚拟字符串(并在开始时尝试将其设为空)。

标签: ios core-location


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-01-24
    • 1970-01-01
    • 2018-08-13
    • 2022-12-17
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多