- 首次搜索到设备,并连接成功时,将CBPeripheral对象的的唯一标识保存起来
[[NSUserDefaults standardUserDefaults] setValue: peripheral.identifier.UUIDString forKey:];
- 通过CBCentralManager的retrievePeripheralsWithIdentifiers方法,找回连接过的设备
NSString *uuidstring = [[NSUserDefaults standardUserDefaults] valueForKey:advertisingData];
NSUUID *storagePeripheralUUID = [[NSUUID alloc] initWithUUIDString:uuidstring];
NSArray *Peripherals = [self.centralManager retrievePeripheralsWithIdentifiers:@[storagePeripheralUUID]];
CBPeripheral *peripheral = [PeripheralsfirstObject];
参考官方文档:
CoreBluetooth