kay*_*Eff 4 mac-address ios bluetooth-lowenergy swift
是的,我知道无法检索使用 CoreBluetooth 包找到的 BLE 外设的 MAC 地址,如其他问题(如此处)中所述。
我工作的公司有一个测试设置,我们有不同类型的 iPhone,它们应该连接到不同的被测外围设备。对于每个被测外设,我们都知道 MAC 地址。对于我们的测试,我们需要特定的 iPhone 来连接到特定的外围设备。外设的区别仅在于 MAC 地址。
由于可以通过使用在单个 iOS 设备上拥有一致的外设 ID
public func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
let id = peripheral.identifier
}
Run Code Online (Sandbox Code Playgroud)
我们为每个外围设备和每个 iPhone 创建一个映射表。因此,我们有一个类似于这个的函数:(我们不使用这个,但你明白了)
func getMAC(peripheralId: String, iPhoneID: String) -> String {
if iPhoneID == "iPhoneFoo" && peripheralId == "uuid-peripheralFoo-iPhoneFoo" {
return "MAC-peripheralFoo"
}
else if iPhoneID == "iPhoneFoo" && peripheralId == "uuid-peripheralBar-iPhoneFoo" {
return "MAC-peripheralBar"
}
else if iPhoneID == "iPhoneBar" && peripheralId == "uuid-peripheralFoo-iPhoneBar" {
return "MAC-peripheralFoo"
}
else if iPhoneID == "iPhoneBar" && peripheralId == "uuid-peripheralBar-iPhoneBar" {
return "MAC-peripheralBar"
}
else {
return "unkown"
}
}
Run Code Online (Sandbox Code Playgroud)
我们使用此函数的输出来检查找到的外设是否与其应搜索的 MAC 地址匹配。正如您所猜测的,制作此映射功能非常繁琐,特别是如果新的 iPhone 或新的外围设备进入测试设置。
我现在的问题是:如果您事先知道 MAC 地址,有没有办法“计算”设备的外设 ID?
那么像函数之类的东西,您可以在其中提供 MAC 地址并检索 uuid,就好像通过执行 BLE 扫描实际上找到了设备一样?
提前致谢!
| 归档时间: |
|
| 查看次数: |
1041 次 |
| 最近记录: |