首页 > 解决方案 > 按“忘记此设备”如何知道我的蓝牙设备已被删除?

问题描述

  1. 我确实使用以下方式配对蓝牙设备:centralManager.connect(peripheral, options: nil)
  2. 杀死我的应用程序
  3. 设置 -> 蓝牙 -> “我的设备”列表中显示的蓝牙设备。
  4. 通过在设置中按“忘记此设备”-> 蓝牙设备将从“我的设备”列表中删除。
  5. 我想获得有关我的蓝牙设备不再与 iPhone 配对的信息。

如何使用“忘记此设备”获取有关我的蓝牙设备已从“我的设备”列表中删除的信息?

连接到选定的外围设备:

centralManager.connect(peripheral, options: nil)

在委托保存标识符中:

func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
    UserDefaults.standart.set(peripheral.identifier, key: "peripheralID")
}

检索外围设备,我不需要再次扫描:

let identifier = // Getting identifier from user defaults.
guard let peripheral = centralManager.retrievePeripherals(withIdentifiers: identifiers).first else {
    log("Can not retrieve peripherals", log: .ble, type: .info)
    return
}
centralManager.connect(peripheral, options: nil)

标签: swiftobjective-cbluetoothcore-bluetooth

解决方案


推荐阅读