Reputation: 826
I have developed a wearable device which uses BLE technology to connect top other BLE devices. I have successfully implemented ANCS also from the wearable side.
The problem statement here is that:
I am not using the Apple's MFI Program.
When I am scanning the device for the very first time it gets discovered based on the Service IDs. After successful connection ANCS establishes and asks for the pairing request which is visible in the app.
If somehow the wearable gets disconnected and the user switches it on manually. The device gets connected automatically from the outside Bluetooth setting screen. This leads to a problem in which I cannot scan the device from the app itself agin as it gets connected from outside and hence the advertisement packets stops spreading. Since I am not able to scan the watch, I am not able to connect it.
I have to unpair it manually and then the device is coming in the scan list.
Is there any way that I can know that the Device is connected from outside from inside my app?
If yes, then please let me know and if not, then please suggest some alternative solution to this whole scenario as I have to unpair it again and again to scan it form the app.
I have been stuck on this problem from the last 10 days.
Please provide a solution. Any help is appreciated.
Thanks
Upvotes: 2
Views: 1191
Reputation: 429
when you try to scan the peripheral in your app, you should use retrieveConnectedPeripheralsWithServices:
first before scan.
Here is the example:
NSArray *peripherals = [central retrieveConnectedPeripheralsWithServices:@[serviceUUId]];
if (peripherals.count > 0) {
CBPeripheral *peripheral = [peripherals firstObject];
peripheral.delegate = self;
[central connectPeripheral:peripheral options:nil];
} else {
[central scanForPeripheralsWithServices:@[serviceUUId] options:nil];
}
The best practice for connect a peripheral described in apple BLE document:
Upvotes: 1