简体   繁体   中英

IOS Core bluetooth peripheral connection request

Am working on corebluetooth framework, I can able to discover and connect with the device if both the BLE is visible. Now i got an issue is am able to discover the device once discovered peripheral was switched off due to some reason now am trying to connect that device using

[centralManager connectPeripheral:activePeripheral options:nil];

this method, but the peripheral not available to connect, so i need to check before connection is peripheral available or not.

Thanks

You have one method :

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

if you add the scanning option like :

NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:@YES, CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[manager scanForPeripheralsWithServices:nil options:options];

then the above method will be called continuously to update state of the peripheral . Then you could watch for which peripheral the method is not called for some time then remove that peripheral from the list

Or second option is to scan it again just before the connecting to the peripheral .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM