Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with CoreBluetooth: Cant discover the device

I'm working on BLE device named WIRELESS BLOOD PRESSURE WRIST MONITOR. I've downloaded these application and every thing is working great. But when I tried to connect to the device from my application, I didn't receive a response. and my code is straight like the code from developer.apple.com and also this tutorial.

This is my code:

_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[_centralManager scanForPeripheralsWithServices:nil options:nil];

I receive notification on the delegate for centralManagerDidUpdateState but I don't receive the didDiscoverPeripheral even if I'm searching with nil in services.

When I go to Setting -> Bluetooth: I can see the device and it is connected and the signal of bluetooth is on. So the iPhone can see the BLE device, So when I used in my code these method retrieveConnectedPeripheralsWithServices to get the list of connected device it returns 0 object.

So I don't know what is the problem, keeping in mind that the BLE device is working great with there own app so it's Low Energy not classic , and the BLE device display bluetooth signal when opening the app.

So any ideas from the GEEKS :D

Thanks..

like image 958
Abo3atef Avatar asked Jan 19 '26 05:01

Abo3atef


1 Answers

There are lots of pieces you need to take care of:

  1. You need to wait for the centralManagerDidUpdateState to indicate CBCentralManagerStatePoweredOn. Anything you do before will either result in error or be ignored. So your call to scanForPeripheralsWithServices is probably ignored. This is true for other APIs, like the retrieveConnectedPeripheralsWithServices you mentioned.
  2. It is also possible that the device turns off advertising after it is connected, so your scanning will not succeed until you disconnect from it.
  3. Scanning in the background has many limitations. You can search the SO questions to find out the details. In the beginning I would advise you to not to try backgrounded operation as it can be really tricky.
like image 191
allprog Avatar answered Jan 20 '26 19:01

allprog