需要 NSBluetoothAlwaysUsageDescription,但未使用蓝牙

NSBluetoothAlwaysUsageDescription required, but bluetooth is not used

在我的 ios 应用程序中,新 Xcode 11 GM Seed 2 部署后,苹果返回错误: ITMS-90683:Info.plist 中缺少带有 NSBluetoothAlwaysUsageDescription 的目的字符串。

https://developer.apple.com/documentation/bundleresources/information_property_list/nsbluetoothalwaysusagedescription?language=objc 已读。

问题是我没有在我的应用程序中使用蓝牙。或者也许我不知道。我如何找出为什么需要此权限目的?

我没有使用 CoreBluetooth.framework

您应用中的第三方 library/framework/pod 可能正在使用 CoreBluetooth。只需在 Info.plist 中添加 NSBluetoothAlwaysUsageDescription,错误就会消失。

如果您的应用程序的部署目标早于 iOS 13,请将 NSBluetoothPeripheralUsageDescription 键添加到您的应用程序的信息 属性 列表文件中,除了 NSBluetoothAlwaysUsageDescription 键作为您的一个或多个第三方项目使用蓝牙功能。

显然 Apple 对政策进行了一些更改。否则,要求未使用的标志是很奇怪的。这是非常令人担忧的。 由于这些原因,我的应用程序也被拒绝了,而旧版本一直 运行 没有这个。

我今天遇到了完全相同的问题。当我进行 grep 搜索时,我发现 project.pbxproj

中有一些对 CoreBluetooth.framework 的引用

我删除了引用并且构建应用程序很顺利。上传到 Apple 并成功通过,所以这对我有用。

要搜索,请使用以下命令

grep -r -a CoreBluetooth.framework ProjectFolder

打开你的 Info.plist 并添加一个 NSBluetoothAlwaysUsageDescription。您可以在编辑器中通过添加这样的行项目来执行此操作:

或者您可以右键单击 Info.plist 并打开为 -> 源代码并将两行适当的内容粘贴为 xml:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
    ....
    <key>NSBluetoothPeripheralUsageDescription</key>
    <string>We use Bluetooth to connect to the MantisX hardware device.</string>
    ....
</dict>
</plist>

我能够通过扫描符号使用来消除 CoreBluetooth 的使用,特别是寻找 CBCentralManager。我为此编写的脚本:

#!/usr/bin/env bash
#
# find-bluetooth-usages.sh <app1.app> <app2.app> ...

check_references_corebluetooth() {
  nm "" | grep "CBCentralManager" 2>&1 >/dev/null
}

find_usages () {
  app_path=
  if [[ ! -d $app_path || ! -d "$app_path/Frameworks" ]]; then
    echo "$app_path is not a valid app directory."
    exit 1
  fi
  app_filename=$(basename -- "$app_path")
  app_name="${app_filename%.*}"

  if check_references_corebluetooth "$app_path/$app_name"; then
    echo "$app_name contains references to CoreBluetooth"
  fi
  for framework_filename in $(ls "$app_path/Frameworks" | egrep '\.framework$'); do
    framework_path="$app_path/Frameworks/$framework_filename"
    framework_name=$(basename "$framework_path" .framework)
    if check_references_corebluetooth "$framework_path/$framework_name"; then
      echo "$framework_name contains references to CoreBluetooth"
    fi
  done
}

for arg in "$@"; do
  find_usages "$arg"
done

这将挖掘主二进制文件及其包含的框架以查找 CBCentralManager 引用。例如:

./find-bluetooth-usages.sh /path/to/MyApp.app

我试过 Maurice 的回答,有和没有 .framework 扩展名,但在我的项目中没有找到任何对 CoreBluetooth 的引用。 我之前还在 Info.plist 文件中添加了:“Privacy - Bluetooth Peripheral Usage Description”,字符串值:“App would like to use your bluetooth for communication purposes"”。 这也没有用。
最后在看到 Chase Roberts 的回答后,我添加了:“NSBluetoothAlwaysUsageDescription”,字符串值为:“App would like to use your bluetooth for communication purposes”。 之后,我的应用在发布时不再显示此错误。

注意:在错误警告中:ITMS-90683,因为我的应用程序说交付成功,但如果我想对陈述的问题。

您应该将 NSBluetoothPeripheralUsageDescription 和 NSBluetoothAlwaysUsageDescription 添加到您的 Info.plist 文件中。您的 Info.plist 文件位于(默认情况下)您的项目文件夹 "Supporting Files" 组中,可能被称为 {PROJECTNAME}-Info.plist。您有几个选择来添加它。 一种选择是使用 vim 或其他任何方式从命令行编辑文件。然后添加这些行:

<key>NSBluetoothAlwaysUsageDescription</key>
<string>App would like to use your bluetooth for communication purposes</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App would like to use your bluetooth for communication purposes</string>

第二种选择是双击 XCode 中的 Info.plist 文件并使用 "super helpful" XCode 编辑器。这个烦人的编辑器实际上在下拉列表中没有 NSBluetoothAlwaysUsageDescription,您必须手动添加它。超级有帮助。不管怎样,在信息 属性 列表 header 的右侧有一个小加号按钮,只需单击它即可。在第 1 步中,您查找 "Privacy - Bluetooth Peripheral Usage Description"。这是 NSBluetoothPeripheralUsageDescription 的可读名称。然后只需单击右侧的值部分并输入您的文本,例如 "App would like to use your bluetooth for communication purposes" 或 watever。完成后,再次单击相同的加号按钮,您将获得相同的下拉列表。忽略该列表,只需将字符串 NSBluetoothAlwaysUsageDescription 粘贴到那里。然后单击右侧的值并粘贴 "App would like to use your bluetooth for communication purposes".

Swift 5

<key>NSBluetoothAlwaysUsageDescription</key>
<string>App would like to use your bluetooth for communication purposes</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App would like to use your bluetooth for communication purposes</string>

就我而言,我没有使用任何与蓝牙相关的东西 API,但应用因此崩溃了。我发现 Google 移动广告正在使用蓝牙。我通过将其从 pods 中删除并重新运行应用程序来确保这一点。 (我想我们都应该问 Google 为什么他们需要蓝牙来显示移动广告)

无论如何,您现在可以通过将 NSBluetoothAlwaysUsageDescription 添加到您的 plist 来阻止您的应用程序崩溃。