CLLocationManager和tvOS-RequestWhenInUseAuthorization()不提示 [英] CLLocationManager and tvOS - RequestWhenInUseAuthorization() not prompting

查看:89
本文介绍了CLLocationManager和tvOS-RequestWhenInUseAuthorization()不提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I seem to be having a little trouble getting tvOS to prompt the user for location data authorization. I literally copied and pasted working code from iOS and it seems to not be prompting the user. I am using the code listed below as well as the NSLocationWhenInUseUsageDescription key with a string value. The only difference in the api that I see is on iOS it uses startupdatinglocation() and on tvOS it uses requestLocation() (similar to watchOS) I've stepped through the problem and it is infact hitting requestWhenInUseAuthorization() but simply doesn't prompt the user.

知道发生了什么吗?

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)值。

It turns out that a CFBundleDisplayName key and $(PRODUCT_NAME)value is needed in order for the prompt to display.

这篇关于CLLocationManager和tvOS-RequestWhenInUseAuthorization()不提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆