[英]Why CBPeripheral identifier and UUID are different?
I have iBeacon that have known UUID. 我有知道UUID的iBeacon。 If I search for this beacon from Android device - I can see exact this UUID.
如果我从Android设备搜索此信标-我可以确切看到此UUID。
But when I search for this iBeacon from iOS device it can't be found with this UUID. 但是,当我从iOS设备搜索此iBeacon时,找不到此UUID。 I found peripheral with identifier that differs from UUID.
我发现外围设备的标识符不同于UUID。
func centralManagerDidUpdateState(_ central: CBCentralManager) {
let serviceUUID: CBUUID = CBUUID(string: "e2c56db5-dffb-48d2-b060-d0f5a71096e0")
central.scanForPeripherals(withServices: [serviceUUID], options: nil)
}
Why are they different? 他们为什么不同? What can I do to search peripheral with known UUID?
如何搜索具有已知UUID的外围设备?
I suspect that what you are "discovering" on Android is not the ProximityUUID of an iBeacon, but a different kind of UUID (eg GATT Service as Larme suggests in his comment.) There are many different UUIDs that are used for different things with Bluetooth. 我怀疑您在Android上“发现”的不是iBeacon的ProximityUUID,而是另一种UUID(例如Larme在其评论中建议的GATT服务。)有许多不同的UUID用于蓝牙的不同用途。 The one you want for iBeacons is called the Proxmity UUID.
您想要iBeacons的那个被称为Proxmity UUID。
You can try to see the Proximity UUID by using a dedicated beacon scanner like the Locate App. 您可以尝试使用专用信标扫描仪(例如“ 定位应用程序”)查看“接近UUID” 。 If you can see the beacon with this app, and it identifies it as an iBeacon you should also be able to detect it with CoreLocation on iOS like this:
如果您可以通过此应用看到信标,并且将其标识为iBeacon,那么您还应该能够通过iOS上的CoreLocation来检测到它,如下所示:
let region = CLBeaconRegion(proximityUUID: UUID(uuidString: "11111111-2222-3333-4444-c0765a17c9ab")!, identifier: "myBeacons")
locationManager.delegate = this
locationManager.startRangingBeacons(in: region)
You cannot use CoreBluetooth APIs as you have shown to detect iBeacons, because iOS blocks using CoreBluetooth to detect iBeacons. 您不能像显示的那样使用CoreBluetooth API来检测iBeacons,因为iOS会阻止使用CoreBluetooth来检测iBeacon。 Note also that there are a few more steps to setting up beacon ranging on iOS (requesting permissions, defining a callback method), so check out a tutorial like here .
另请注意,在iOS上设置信标还有更多步骤(请求权限,定义回调方法),因此请查看此处的教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.