Home > Net >  Check whether a peripheral is reachable using UUID
Check whether a peripheral is reachable using UUID

Time:04-28

In a table view controller list, I have all the peripherals which had been connected before. When the app loads, I want to check whether each of the peripherals is reachable. By reachability, I mean whether the device is turned on or is in range. How to achieve that when I have just the UUID of the different peripherals in the list?

CodePudding user response:

You test reachability by connecting (CBCentralManager.connect). If the device is advertising, you can scan again and rediscover it (CBCentralManager.scanForPeripherals), but generally speaking it's quicker and easier to just connect to known devices without scanning.

If you can connect and get a response, then it's reachable. There is no other way to know that something is reachable. (The same is true of any networking protocol. The way you determine that another node is available is you send a packet and get a packet back.)

Note that many BLE devices can only accept a single connection, and do not advertise when they are connected. So if some other device has connected to your peripheral, it may become invisible to you. Improving this generally requires reworking the firmware.

  • Related