Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift CLLocationManager和tvOS-RequestWhenUseAuthorization()未提示_Swift_Cllocationmanager_Tvos - Fatal编程技术网

Swift CLLocationManager和tvOS-RequestWhenUseAuthorization()未提示

Swift CLLocationManager和tvOS-RequestWhenUseAuthorization()未提示,swift,cllocationmanager,tvos,Swift,Cllocationmanager,Tvos,让tvOS提示用户进行位置数据授权似乎有点困难。我从iOS复制并粘贴了工作代码,它似乎并没有提示用户。我正在使用下面列出的代码以及带有字符串值的NSLocationWhenUsageDescription密钥。我看到的api的唯一区别是,在iOS上它使用startupdatinglocation(),在tvOS上它使用requestLocation()(类似于watchOS)。我已经解决了这个问题,它实际上是在点击RequestWhenUseAuthorization(),但只是不提示用户 知道

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

知道发生了什么吗

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()
    }

  }

}

事实证明,为了显示提示,需要CbundleDisplayName键和$(PRODUCT_NAME)值

您能在自己的答案中发布一个示例吗?在我的例子中,我的Info.plist文件中缺少NSLocationWhenUsageDescription密钥。添加
CbundleDisplayName
帮助,谢谢!我希望他们只是在缺少重要信息时用断言终止应用程序,而不是让我们猜测。