jjzjj

swift - CLLocationManager 和 tvOS - RequestWhenInUseAuthorization() 不提示

coder 2023-09-12 原文

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

知道发生了什么吗?

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

  }

}

最佳答案

事实证明,为了显示提示,需要一个 CFBundleDisplayName 键和 $(PRODUCT_NAME) 值。

关于swift - CLLocationManager 和 tvOS - RequestWhenInUseAuthorization() 不提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33738744/

有关swift - CLLocationManager 和 tvOS - RequestWhenInUseAuthorization() 不提示的更多相关文章

随机推荐