As the message suggests, you need to store your CBPeripheral instance somewhere that keeps a strong reference to it.
In general, you have a strong reference to an object by storing the pointer somewhere. For example, you might have a BluetoothConnectionManager keeps a list of connected peripherals:
@implementation BluetoothConnectionManager
- (instancetype)init
{
if(self = [super init])
{
_knownPeripherals = [NSMutableArray array];
dispatch_queue_t centralQueue = dispatch_queue_create("com.my.company.app", DISPATCH_QUEUE_SERIAL);
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:centralQueue options:@{CBCentralManagerOptionShowPowerAlertKey : @YES}];
}
return self;
}
- (void)centralManager:(CBCentralManager *)central
didConnectPeripheral:(CBPeripheral *)peripheral
{
[_knownPeripherals addObject:peripheral];
}
- (void)centralManager:(CBCentralManager *)central
didDisconnectPeripheral:(CBPeripheral *)cbPeripheral
error:(NSError *)error
{
// This probably shouldn't happen, as you'll get the 'didConnectPeripheral' callback
// on any connected peripherals and add it there.
if(![_knownPeripherals containsObject:cbPeripheral])
{
[_knownPeripherals addObject:cbPeripheral];
}
[_centralManager connectPeripheral:cbPeripheral options:nil];
}
@end
Or you can modify this code to have a reference to a single, connected peripheral.
You can also use this to write out your previous connection ids to try and establish them when re-launching the app as described in the Apple Docs
Finally, a few links on references:
Doing a search on "strong and weak references ios" will yield additional results. If you're using ARC, simply having a property will create a strong reference. Regardless, adding the CBPeripheral instance to an array will also create a strong reference.