下午好,在过去的几周里,我在 Xcode 中遇到了一个问题,上面写着:
此应用程序试图在没有使用说明的情况下访问隐私敏感数据。应用程序的 Info.plist 必须同时包含“NSLocationAlwaysAndWhenInUseUsageDescription”和“NSLocationWhenInUseUsageDescription”键,其中包含向用户解释应用程序如何使用这些数据的字符串值
我在我的 info-plist 中实现了这两种用法描述,我尝试从手机中删除应用程序(我使用我的 iPhone 作为模拟器)我尝试重新组织我的代码,我尝试注释掉特定行只是为了看看消息是否会消失并让我看到我的位置。我试过删除并重新安装谷歌地图窗格,但没有。我尝试在 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
}()
}