【问题标题】:NSLocationWhenInUseUsageDescription warning, but I have already added itNSLocationWhenInUseUsageDescription 警告,但我已经添加了
【发布时间】:2018-02-21 22:39:33
【问题描述】:

虽然我已经添加了:

NSLocationWhenInUseUsageDescription

我不断收到此警告:

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

仅供参考:我在应用中有多个 Info.plist。不知道该怎么办。

【问题讨论】:

  • 已在任何 plist 中添加了密钥?
  • 您确定,您修改了正确的 Info.plist 文件吗?
  • 是的,我已经添加了带有描述的密钥...是的,但是我更改了 Bundle 标识符,这可能是问题吗?
  • 不,捆绑标识符不是问题。
  • 尝试找出正确的 .plist 文件!

标签: ios swift location info.plist userlocation


【解决方案1】:

同时添加

NSLocationAlwaysAndWhenInUseUsageDescription

NSLocationWhenInUseUsageDescription

plist 中的键解决了我的问题。

    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your location is required for xyz benefits for you</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Your location is required for xyz benefits for you</string>

【讨论】:

  • 我不明白,为什么我们需要添加两个键。第一个键的名称向我暗示,它应该为旧键 NSLocationWhenInUseUsageDescription 和 NSLocationAlwaysUsageDescription 提供相同的文本...
  • @finngu 不仅如此,docs 还明确指出“如果您的应用在后台需要位置信息,请使用 NSLocationAlwaysAndWhenInUseUsageDescription 而不是。”。 [强调我的]。
【解决方案2】:

有大量结构不佳的框架(即 FirebaseMessaging) 使用相机和位置对用户没有任何好处。 您应该提醒最终用户您的应用程序不需要此功能,并且用户不得授予应用程序访问该寄生虫内部的权限。 我们生活在多么悲伤、悲伤的时代。

    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your location is not needed. This request has popped up due to a 3rd party framework used by the app in a context that does NOT need you to reveal you location. Do be sure to check audit trail for the location queries on ios 15 or later.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>You will get zero benefit allowing this app accessing your location. You should never see this alert. If you do alert technical support at foo@bar.baz</string>

否则,在用于传达确切用法和风险的措辞上确实很狡猾,让应用程序可以访问其沙盒之外的任何内容。

【讨论】:

    【解决方案3】:

    嗯,实际上,就我而言,我需要像这样放置所有三个:

    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>...</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>...</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>...</string>
    

    否则,我不会收到要求允许该位置的弹出警报。

    注意:我是用Flutter开发的,不知道在这种情况下会不会有什么影响……

    【讨论】:

      【解决方案4】:

      我在

      中请求授权

      viewDidLoad

      如下:

      self.locationManager.requestWhenInUseAuthorization()
      

      当我删除这一行时,错误消失了。

      【讨论】:

      • NSLocationWhenInUseUsageDescription 和 NSLocationAlwaysAndWhenInUseUsageDescription 用于在您添加 self.locationManager.requestWhenInUseAuthorization() 时寻求用户同意使用他们的位置,这意味着您现在将请求许可。所以如果你没有使用位置,你不需要添加权限字符串。如果您这样做,您在哪里编写代码以获得许可并不重要,您应该添加两个许可字符串作为来自@Kartihkraj Duraisamy 的答案,以使定位服务正常工作。
      • 我在乎他在哪里获得许可 ;^) 看看一个典型的应用程序,其中有十几个问题等待毫无戒心的新用户。
      【解决方案5】:

      从 plist 中删除 NSLocationWhenInUseUsageDescription 并运行应用程序并再次添加并再次运行应用程序

      【讨论】:

        猜你喜欢
        • 2016-10-20
        • 2021-02-05
        • 2016-11-10
        • 1970-01-01
        • 2017-01-31
        • 1970-01-01
        • 1970-01-01
        • 2019-05-23
        • 2021-02-05
        相关资源
        最近更新 更多