Ios 7 ble cannot reconnect paired devices

There are no problems on ios 6, I can reconnect paired Bluetooth devices.

I use

- (void)retrievePeripherals:(NSArray *)peripheralUUIDs 

and delegate

 - (void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals 

returns an array of peripherals. I iterate over this array and will successfully contact each periphery.

on ios 7,

 - (void)retrievePeripherals:(NSArray *)peripheralUUIDs 

outdated. Ok, I'm using the new method for ios 7:

 - (NSArray *)retrievePeripheralsWithIdentifiers:(NSArray *)identifiers 

This method returns an array of peripherals. I iterate over this array and try to connect each peripheral device, but it does not work.

Peripheral log returned by ios 7 method:

 "<CBPeripheral: 0x176e5f50 identifier = XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, Name = \"Name\", state = disconnected>" 

If I call retrievePeripheralsWithIdentifiers again, the state of the periphery changes to:

 "<CBPeripheral: 0x176e5f50 identifier = XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, Name = \"Name\", state = connecting>" 

But nothing happens

I tried using an obsolete method that works on ios6, but it is the same. No connection.

+4
source share
4 answers

You need to publish how you really connect to these peripherals to be sure, but there is no problem with the new iOS 7 method. I assume that you are passing in CFUUIDRef's (for example, for iOS 6) instead of using the new NSUUID parameter.

Here is what you need to do:

 NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:savedUUID];//where savedUUID is the string version of the NSUUID you've saved somewhere NSArray *peripherals = [_cbCentralManager retrievePeripheralsWithIdentifiers:@[uuid]]; for(CBPeripheral *periph in peripherals) { [_cbCentralManager connectPeripheral:peripheral options:nil]; } 

Note: if you are stuck in a connection state, call cancelPeripheralConnection: before connecting peripherals.

+2
source

First of all, make sure you keep a link to the CBPeripheral interest.

If this is done, but CBPeripheralState never changes from CBPeripheralStateConnecting to CBPeripheralStateConnected , just completely reboot (completely turn off / turn off) your iPhone / iPad.

+2
source

Your code says little, but to connect to the peripheral device that you extracted from retrievePeripheralsWithIdentifiers , you need to scan first and then connect.

0
source

You should not reconnect to viewDidLoad , because at this time the CBCentralManager state is Unknown

You must do this in the centralManagerDidUpdateState method when the state is CBCentralManagerStatePoweredOn

The code:

 - (void)centralManagerDidUpdateState:(CBCentralManager *)central { NSLog(@"state - %ld",(long)[central state]); if ([central state] == CBCentralManagerStatePoweredOn) { [self tryToReconnect]; } } 

Helper Method:

 - (void)tryToReconnect { NSArray * peripherals = [_centralManager retrievePeripheralsWithIdentifiers:@[[CBUUID UUIDWithString:@"savedUdidString"]]]; if (peripherals.count > 0) { CBPeripheral * peripheral = [peripherals firstObject]; self.peripheral = peripheral; self.peripheral.delegate = self; [_centralManager connectPeripheral:peripheral options:nil]; } } 
0
source

All Articles