【问题标题】:NSLocationWhenInUseUsageDescription error keep showingNSLocationWhenInUseUsageDescription 错误继续显示
【发布时间】:2018-09-05 04:46:29
【问题描述】:

我尝试在我的项目中实现 MapKit 和 CoreLocation。不幸的是,错误一直显示

此应用试图在没有使用说明的情况下访问隐私敏感数据。应用的 Info.plist 必须包含一个 NSLocationWhenInUseUsageDescription 键和一个字符串值,向用户解释应用如何使用这些数据

这是我的代码和info.plist

import Foundation
import CoreLocation
import MapKit

class ViewController: UITabBarController, CLLocationManagerDelegate{

    let locationManager: CLLocationManager = CLLocationManager()

    @IBAction func backBarButton(_ sender: Any) {
        self.dismiss(animated: true, completion:nil)
    }


    override func viewDidLoad() {
        super.viewDidLoad()

        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
    }
}

作为源代码打开 info.plist

<key>NSLocationWhenInUseUsageDescription</key>
    <string>accept to get location</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>description</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>description</string>
    <key>NSLocationUsageDescription</key>
    <string>description</string>

打开 .plist 作为属性视图

我尝试创建一个新项目,它运行顺利,但是当我尝试在现有项目上实现它时,它不起作用。

【问题讨论】:

  • 您正在编辑的 info.plist 可能不是您的应用正在使用的 info.plist。我建议您存档您的应用程序,然后从管理器窗口中,为存档选择“在查找器中显示”并在存档中选择“显示内容”以查看实际包含的 info.plist。
  • @Paulw11有道理,我先试试
  • 删除描述

标签: ios swift core-location


【解决方案1】:

从 iOS 11 开始,您无法在不提供“使用时”的情况下请求“始终”:如果您仅设置隐私 - 位置始终使用说明,则不会出现,并且您会收到错误消息“信息。 plist 必须同时包含 NSLocationAlwaysAndWhenInUseUsageDescriptionNSLocationWhenInUseUsageDescription 键...”。在 Xcode 9 beta 中,我必须使用 NSLocationAlwaysAndWhenInUseUsageDescription 键; Xcode 不会选择匹配的隐私密钥。

位置经理要求“始终”:

click link for more description

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-08
    • 1970-01-01
    • 2020-09-03
    • 2023-01-17
    • 2010-12-25
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    相关资源
    最近更新 更多