加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – EAAccessory.Name与配对的设备名称不匹配

发布时间:2020-12-14 19:05:52 所属栏目:百科 来源:网络整理
导读:我有一个iOS应用程序.我可以成功连接到我的配对EAAccessory(蓝牙经典).我能够从通过EAAccessory对象公开的设备中提取信息.我注意到的一件事是配对设备的名称(在我的设置 – 蓝牙 – 我的设备列表中)与我的EAAccessory对象公开的设备名称不匹配.我觉得这很奇
我有一个iOS应用程序.我可以成功连接到我的配对EAAccessory(蓝牙经典).我能够从通过EAAccessory对象公开的设备中提取信息.我注意到的一件事是配对设备的名称(在我的设置 – >蓝牙 – >我的设备列表中)与我的EAAccessory对象公开的设备名称不匹配.我觉得这很奇怪.

有没有办法通过我的iOS应用程序获取设备的实际名称(来自“设置”页面的名称)?

解决方法

如果您有广告UUID,则可以获取配对/连接设备的列表.

var centralQueu = DispatchQueue(label: "A_NAME")
centralManager = CBCentralManager(delegate: self,queue: centralQueu,options: [CBCentralManagerOptionRestoreIdentifierKey: "RESTORE_KEY",CBCentralManagerOptionShowPowerAlertKey: true])
ServiceUUIDs = [CBUUID(string: "THE_UUID")]
//the array of CBUUIDs which you are looking for

您需要找到您感兴趣的服务UUID:

var options = [
    CBCentralManagerScanOptionAllowDuplicatesKey : (1)
]
centralManager.scanForPeripherals(withServices: [CBUUID(string: SERVICE_UUID)],options: options)

centralManager.retrieveConnectedPeripherals(withServices: ServiceUUIDs)

以这种方式处理didDiscoverperipheral:

func centralManager(_ central: CBCentralManager,didDiscover peripheral: CBPeripheral,advertisementData: [String : Any],rssi RSSI: NSNumber) {
    discoveredPeripheral = peripheral
    if !mRemoteDevices.contains(discoveredPeripheral) {
        let peripherels = centralManager.retrievePeripherals(withIdentifiers: [discoveredPeripheral.identifier])
        mRemoteDevices.append(peripherels[0])
    }
}

如果您熟悉目标C,则此代码将从objective-C转换为swift,然后原始代码为here.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读