[英]iOS permissions for user location
我只是在創建一個需要獲取用戶位置的 iOS 應用程序。
我已將所需的鍵和值包含在 info.plist 中,如屏幕截圖所示:
但是在運行應用程序時,調試器中有一條消息:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.