how can scan bluetooth devices using core bluetooth sdk?

与世无争的帅哥 提交于 2019-12-07 17:54:19

Your code looks correct.

Some hints on why the second device might not appear:

  • If you found the second device using another 3rd party iOS Bluetooth scanning app like LightBlue, it might have connected to that device (if you tapped on it to get more details). When a peripheral device is connected to, very often, it stops advertising (connection establishment is usually the sole reason for advertising). If the device is not advertising any more, you cannot find it by scanning. If this is the case and the device is already connected to the iOS device, you could use CBCentralManager's methods -retrieveConnectedPeripheralsWithServices: or -retrieveConnectedPeripherals (deprecated since iOS 7) to get the peripherals that have already been connected to iOS by another app.

  • The peripheral might be advertising at such a slow rate, that it just takes a really long time (and a bit of luck) to be found by the iOS device. If this is the case, try picking a shorter advertising interval on your peripheral (assuming you control the firmware of the peripheral).

Note you do not need the CBPeripheralManager if you only need to scan for other peripherals.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!