【问题标题】:CLLocationManager and tvOS - RequestWhenInUseAuthorization() not promptingCLLocationManager 和 tvOS - RequestWhenInUseAuthorization() 不提示
【发布时间】:2015-11-16 15:20:45
【问题描述】:

让 tvOS 提示用户进行位置数据授权似乎有点麻烦。我从字面上复制并粘贴了 iOS 的工作代码,它似乎没有提示用户。我正在使用下面列出的代码以及带有字符串值的 NSLocationWhenInUseUsageDescription 键。我看到的 api 的唯一区别是在 iOS 上它使用 startupdatinglocation() 而在 tvOS 上它使用 requestLocation()(类似于 watchOS)我已经解决了这个问题,它实际上是在点击 requestWhenInUseAuthorization() 但根本没有提示用户。

知道发生了什么吗?

import UIKit
import CoreLocation
class ViewController: UIViewController {
  var locationManager = CLLocationManager()

  override func viewDidLoad() {
  super.viewDidLoad()

  locationManager.delegate = self
  locationManager.desiredAccuracy = kCLLocationAccuracyBest

  if CLLocationManager.locationServicesEnabled(){

    if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.NotDetermined{
      locationManager.requestWhenInUseAuthorization()
    }
    else if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedWhenInUse{
      locationManager.requestLocation()
    }

  }

}

【问题讨论】:

    标签: swift cllocationmanager tvos


    【解决方案1】:

    事实证明,需要 CFBundleDisplayName 键和 $(PRODUCT_NAME) 值才能显示提示。

    【讨论】:

    • 您可以在自己的答案中发布一个示例吗?
    • 在我的情况下,我的 Info.plist 文件中缺少 NSLocationWhenInUseUsageDescription 键。
    • 添加CFBundleDisplayName 有帮助,谢谢!我希望他们在缺少重要的东西时简单地用断言杀死应用程序,而不是让我们猜测。
    猜你喜欢
    • 1970-01-01
    • 2014-11-15
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 2016-02-07
    • 2015-10-28
    相关资源
    最近更新 更多