0

I'm trying restore state from my viewController that implements core bluetooth. I’m trying the restore posted in this question: coreBluetooth question , but this is added into appDelegate instead of a viewController.

So the code added in didFInishLaunching that is calling the coreBluetooth manager…

Where need I implement this code? In which function of my ViewController?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{

    NSArray *peripheralManagerIdentifiers = launchOptions[UIApplicationLaunchOptionsBluetoothPeripheralsKey];

    if (peripheralManagerIdentifiers) {

        // We've restored, so create the _manager on the main queue
        _manager = [[CBPeripheralManager alloc] initWithDelegate:self
                                                          queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
                                                        options:@{CBPeripheralManagerOptionRestoreIdentifierKey:@"YourUniqueIdentifier"}];

    } else {

        // Not restored so just create as normal
        manager = [[CBPeripheralManager alloc] initWithDelegate:self
                                                          queue:nil
                                                        options:@{CBPeripheralManagerOptionRestoreIdentifierKey:@"YourUniqueIdentifier"}];

    }
return YES;
}
Community
  • 1
  • 1
user3745888
  • 6,143
  • 15
  • 48
  • 97
  • 2
    I would recommend against holding your `CBCentralManager` in a view controller. Hold it in another class or your AppDelegate. – Paulw11 Mar 24 '17 at 08:10
  • Thanks for the anwer! This would mean changing much of the structure. COuld be possible keep my structure and use restoration? – user3745888 Mar 24 '17 at 08:50

0 Answers0