DidDiscoverPeripheral not called after updating from iOS 7 to iOS 8

I am calling scanForPeripheralsWithServices from didFinishLaunchingWithOptions callback on AppDelegate. The code looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    NSLog(@"didFinishLaunchingWithOptions");
    // Override point for customization after application launch.
    cm = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
    [cm scanForPeripheralsWithServices:nil
                               options:nil];
}

- (void) centralManager:(CBCentralManager*)central didDiscoverPeripheral:(CBPeripheral*)peripheral advertisementData:(NSDictionary*)advertisementData RSSI:(NSNumber*)RSSI{

   NSLog(@"Did discover peripheral %@", peripheral.name);

   [cm stopScan];
}

      

Before upgrading to iOS 8 everything worked fine, however after upgrading (exactly the same code no line was changed) I don't get any errors, but also didDiscoverPeripheral is not called.

+3


source to share


1 answer


It looks like the main change that came with Core Bluetooth in iOS 8 is that the BLE stack is not enabled until you try to connect (or maybe execute some other command).

CBCentralManager *cbCentralManager;
[cbCentralManager scanForPeripheralsWithServices:...];

      

This call is used to issue a warning, visible in the Xcode debug log, which says that the central manager must be enabled before it can be used. However, this warning has always been catch-22 - the only way to enable the central dispatcher is to send it a message, and the only way to handle the message is to enable it.



Apple seems to have resolved this issue by adjusting the power supply slightly differently. Now, after issuing the above command, the central manager informs his delegate that his state has changed through centralManagerDidUpdateState:

.

We have resolved the issue you described by replying to centralManagerDidUpdateState:

by re-submitting your message scanForPeripherals...

.

+4


source







All Articles