swift - 按“忘记此设备”如何知道我的蓝牙设备已被删除?
问题描述
- 我确实使用以下方式配对蓝牙设备:centralManager.connect(peripheral, options: nil)
- 杀死我的应用程序
- 设置 -> 蓝牙 -> “我的设备”列表中显示的蓝牙设备。
- 通过在设置中按“忘记此设备”-> 蓝牙设备将从“我的设备”列表中删除。
- 我想获得有关我的蓝牙设备不再与 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)
解决方案
推荐阅读
- android - 每个回收站视图项上的 ViewTreeObserver.OnGlobalLayoutListener 以被动地自动调整 TextView 的大小
- c - 为什么在调用 exit(0) 之后,子进程仍然存在?
- ssl - 引入 SSL 时 ActiveMQ 错误证书
- flutter - 颤振 + PhotoView 适合屏幕 - _RenderLayoutBuilder 对象在布局期间被赋予无限大小
- javascript - Mongoosejs .find 返回整个模型而不是文档
- ruby-on-rails - 路径问题:错误资产管道中不存在资产“课程/python”?
- firebase - 我可以在 firestore 安全规则中执行 if else 语句来设置不同的操作吗?
- spring-boot - 运行 spring 测试时加载 ApplicationContext 失败
- c - 在内核模块中为 root 用户提供权限
- arrays - 唯一 ID 生成器和随机器