Info.plist

时间:2018-10-30 02:30:57

标签: swift xcode google-maps showuserlocation

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

  

此应用已尝试访问没有使用说明的隐私敏感数据。应用的Info.plist必须同时包含“ NSLocationAlwaysAndWhenInInUsUsageDescription”和“ NSLocationWhenInUseUsageDescription”键,并带有字符串值,向用户说明应用程序如何使用此数据

我在info-plist中实现了这两种用法说明,我尝试从手机中删除该应用程序(我将iPhone用作模拟器),我试图重新组织代码,并尝试注释掉特定的只是为了查看消息是否消失并允许我查看我的位置。我尝试过删除并重新安装Google Maps Pod,但是什么也没有。我已经尝试在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
    }()
}

2 个答案:

答案 0 :(得分:2)

转到“ info.plist”搜索应用目标的构建设置,并仔细研究完整路径。确保将密钥添加到正确的info.plist中-这是实际正式用作应用程序构建的info.plist的密钥。您还可以单击“构建设置”旁边的“信息”选项卡,以确认其中有两个条目。

这是它的外观(仅确保为它们两个都提供一个值): enter image description here

答案 1 :(得分:0)

之所以如此,是因为您需要添加描述以向用户询问位置权限。为了做到这一点,我们必须编辑属性列表:

在Xcode的Supporting Files文件夹下,我们将在Info.plist中添加两个新键(“隐私位置始终且在使用时使用情况说明”和“隐私位置在使用时使用情况说明”)

为此,请转到显示“信息属性列表”的部分,单击该小添加按钮(+)。并且,如果您删除“应用程序类别”并开始输入“隐私”(带有大写字母P),您将开始看到弹出的建议。

找到并选择“始终且在使用时的隐私位置使用情况说明”和“在使用时的隐私位置使用情况说明”之后,接下来要做的就是给它们每个赋予一个值。在“值”(Value)列下,只需简单地写上“我们需要您的位置才能...”(...可能会获取您当前的天气状况)描述。

现在您有两个新键,并且每个键都有一个数据类型为String的值。