gpt4 book ai didi

swift - Info.plist 中缺少 NSLocationWhenInUseUsageDesciption

转载 作者:搜寻专家 更新时间:2023-10-31 22:38:13 26 4
gpt4 key购买 nike

下午好,在过去的几周里,我在 Xcode 中遇到了一个问题:

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

我在我的 info-plist 中实现了这两个用法描述,我尝试从我的手机中删除该应用程序(我将我的 iPhone 用作模拟器)我尝试重新组织我的代码,我尝试注释掉特定的线只是为了看看消息是否会消失并让我看到我的位置。我试过删除并重新安装 google maps pods,但没有任何效果。我尝试在 StackOverflow、medium 和 GitHub 上阅读有关此问题的文章,看看是否可以使用以前的技巧来帮助解决我的问题。我什至在这里发帖,看看我是否能对这个问题有所了解。

我不知道该怎么做才能解决这个问题,我真的不想重新开始。我将在下面发布我的全部代码,这非常广泛。如果有人有空闲时间通读并让我知道我做错了什么或没有实现,将不胜感激。

import UIKit
import GoogleMaps
import GooglePlaces
import CoreLocation

class mainViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate, GMSAutocompleteViewControllerDelegate, UITextFieldDelegate {

let currentLocationMarker = GMSMarker()
var locationManager = CLLocationManager()

override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.prefersLargeTitles = false

navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 25)]


myMapView.delegate=self
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.requestAlwaysAuthorization()
locationManager.startMonitoringSignificantLocationChanges()
locationManager.startUpdatingLocation()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
setupViews()
initGoogleMaps()
txtFieldSearch.delegate=self

func initGoogleMaps() {
let camera = GMSCameraPosition.camera(withLatitude: 40.014281, longitude: -83.030914, zoom: 17.0)
self.myMapView.camera = camera
self.myMapView.delegate = self
self.myMapView.isMyLocationEnabled = true
}
func getLocation() {

let status = CLLocationManager.authorizationStatus()

if status == .notDetermined {
locationManager.requestWhenInUseAuthorization()
return
}

if status == .denied || status == .restricted {
let alert = UIAlertController(title: "Location Services Disabled", message: "Please enable Location Services in Settings", preferredStyle: .alert)

let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(okAction)

present(alert, animated: true, completion: nil)
return
}
}



@objc func btnMyLocationAction() {
let location: CLLocation? = myMapView.myLocation
if location != nil {
myMapView.animate(toLocation: (location?.coordinate)!)
}
}

let myMapView: GMSMapView = {
let v=GMSMapView()
v.translatesAutoresizingMaskIntoConstraints=false
return v
}()


let btnMyLocation: UIButton = {
let btn=UIButton()
btn.backgroundColor = UIColor.white
btn.setImage(#imageLiteral(resourceName: "my_location-1"), for: .normal)
btn.layer.cornerRadius = 25
btn.clipsToBounds=true
btn.tintColor = UIColor.gray
btn.imageView?.tintColor=UIColor.gray
btn.addTarget(self, action: #selector(btnMyLocationAction), for: .touchUpInside)
btn.translatesAutoresizingMaskIntoConstraints=false
return btn
}()
}

最佳答案

为“info.plist”搜索应用程序目标的build设置,并非常仔细地研究完整路径。确保您将 key 添加到正确的 info.plist - 它是实际正式用作您的应用构建的 info.plist 的 key 。您还可以单击“build设置”旁边的“信息”选项卡来验证是否存在这两个条目。

它应该是这样的(一定要为它们都提供一个值): enter image description here

关于swift - Info.plist 中缺少 NSLocationWhenInUseUsageDesciption,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53056563/

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