I have been working on an application for iOS for a few months now, and I want to give my users the best experience possible, when it comes to the peripheral I intend to use with the app, and in order to do that, I would like to be able to use state preservation and restoration to connect to my peripheral, in case the application has been suspended by the OS at some point.
So far, I have only managed to implement a bit of code, following the guide on Apple's developer pages, but without success. If anybody could help me with this, I would be very grateful.
Here is my code:
// AppDelegate.m, didFinishLaunchingWithOptions:
manager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)options:@{CBCentralManagerOptionRestoreIdentifierKey:@"myManager"}];
// AppDelegate.m, willRestoreState:
NSArray *peripherals = dict[CBCentralManagerRestoredStatePeripheralsKey];
if (dict[CBCentralManagerRestoredStatePeripheralsKey]) {
for (CBPeripheral *currentPeripheral in peripherals) {
peripheral = currentPeripheral;
}
[mainController connect: peripheral :manager]; // Connects to the peripheral
}
else{
[mainController scan: manager]; // Scans for the peripheral
}
I am only using one peripheral, and I am only using one central.
Thank you.