"use Bluetooth for new connections" 的 iOS 权限提示是什么原因造成的?

What causes this iOS permission prompt for "use Bluetooth for new connections"?

自 iOS13 起,我们使用 BLE 信标定位的应用程序现在获得 两个 蓝牙相关权限提示。

第一个是可以理解和预期的:

第二个提示不是预期的,我们不知道为什么会这样。

仅供参考,该应用当前是使用之前的 iOS SDK/XCode.

编译的

我有点确定第二个提示是 "please enable Bluetooth" 的新 iOS13 变体,它出现是因为:

  1. 我们创建了没有 CBCentralManagerOptionShowPowerAlertKey=false 的 CBCentralManager
  2. 用户已在控制中心将蓝牙设置为"off",但未在“设置”中完全关闭蓝牙。

"use Bluetooth for new connections"的描述好像对应的是"fully enabled"状态,而控制中心的"partially enabled"白色按钮就是得到这个提示

Swift 5 / 在实例化 CBCentralManager 时禁用“APP_NAME 想使用蓝牙进行新连接”警报使用选项:

var centralManager = CBCentralManager(delegate: YOUR_DELEGATE?, queue: YOUR_QUEUE?, options: [CBCentralManagerOptionShowPowerAlertKey: 0])

默认情况下,当您每次创建 CBCentralManager 禁用蓝牙时,都会出现此 pop-up。

如果您在创建 CBCentralManager 时将 CBCentralManagerOptionShowPowerAlertKey 添加到 options,则此 pop-up 将不会出现。

Swift:

let manager = CBCentralManager(delegate: nil,
                               queue: nil,
                               options: ["CBCentralManagerOptionShowPowerAlertKey": 0])

Objective-C:

[[CBCentralManager alloc] initWithDelegate:self
                                     queue:nil
                                   options:@{CBCentralManagerOptionShowPowerAlertKey: @0}];