gpt4 book ai didi

ios - 用户位置的iOS权限

转载 作者:行者123 更新时间:2023-12-01 21:53:53 26 4
gpt4 key购买 nike

我只是在创建需要获取用户位置的iOS应用。

我已经将所需的键和值包含在info.plist中,如屏幕截图所示:

enter image description here

但是在运行应用程序时,调试器中会显示一条消息:

2020-04-25 18:51:16.395466+0200 Jogua[23008:1151035] This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain both “NSLocationAlwaysAndWhenInUseUsageDescription” and “NSLocationWhenInUseUsageDescription” keys with string values explaining to the user how the app uses this data

我是否需要更改代码中的其他内容?

编辑
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
determineMyCurrentLocation()
}

func determineMyCurrentLocation() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()

if CLLocationManager.locationServicesEnabled() {
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation

print("user latitude = \(userLocation.coordinate.latitude)")

self.defaults.set(userLocation.coordinate.latitude, forKey: "mi_latitud")

print("user longitude = \(userLocation.coordinate.longitude)")
self.defaults.set(userLocation.coordinate.longitude, forKey: "mi_longitud")

}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error)
{
print("Error \(error)")
}

最佳答案

如调试器所说,您在info.plist中缺少一项。这可能会引起误解,因为控制台打印的名称不是info.plist中的实际键名。

您添加了:

Privacy - Location Always Usage Description
Privacy - Location Usage Description
Privacy - Location Always and When In Use Usage Description

根据调试器,您需要的是:
Privacy - Location When In Use Usage Description
Privacy - Location Always and When In Use Usage Description

您需要添加什么:
Privacy - Location When In Use Usage Description

关于ios - 用户位置的iOS权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61429325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com