0

I have used CoreBluetooth framework to scan for all services and get the peripheral it works well when i launch my application first time, but if i popover to previous class and come again from that class , my delegate methods of CBCentralManger is not getting triggered

But the below method is called in the second time

 -(void)centralManagerDidUpdateState:(CBCentralManager *)central {
if (central.state != CBCentralManagerStatePoweredOn) {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"BLE not supported !" message:[NSString stringWithFormat:@"CoreBluetooth return state: %ld",central.state] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
}
else {
    [central scanForPeripheralsWithServices:nil options:nil];

}

}

but after this its not getting triggered the rest of the delegate methods

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

-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
}

- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
}

can any one tell me what would be the possibilities for not calling these delegate methods?

Rajjjjjj
  • 424
  • 3
  • 16
  • 1
    Where is your central manager created? Do you have a property for it? Can you log its value inside `centralManagerDidUpdateState:`? – James Frost Feb 05 '14 at 08:01
  • @JamesFrost i Have created in the viewDidLoad method – Rajjjjjj Feb 05 '14 at 09:18
  • Check your central manager object's lifecycle. Is there any place where you change the delegate? Are there any events that you think should generate callbacks. Just because you got back to some view controller, the callbacks will not be called if not necessary. – allprog Feb 05 '14 at 09:51
  • What do you mean by "popover and return". Show us your code. – Larme Feb 05 '14 at 13:24
  • @Larme popOver means going back to my previous viewcontroller and coming back to the present viewcontroller – Rajjjjjj Feb 05 '14 at 13:54
  • In `viewDidLoad` which should be called, check if yourCBCentralManager & its delegate. – Larme Feb 05 '14 at 13:56
  • @Larme i have done that too and set the delegate in viewVillAppear too – Rajjjjjj Feb 05 '14 at 14:13
  • Did you stop scanning before navigating away? You don't turn off duplicate filtering in the initialization. But honestly, you should take a look at some working examples. There is a load of good stuff in the documentation, the example projects and github repos. Don't expect anyone to do the debugging for you. Clearly, your code does not follow the rules and you must find where you fail. Your question is not answerable in its current form. – allprog Feb 05 '14 at 14:46

1 Answers1

0

You don't need to work with that messy framework (Core Bluetooth), There is a great solution - LGBluetooth Which works over CoreBluetooth and gives modern block based api.

https://github.com/DavidSahakyan/LGBluetooth

It's super easy to use

    [[LGCentralManager sharedInstance] scanForPeripheralsByInterval:15
                                                         completion:^(NSArray *peripherals)
     {
     }];

here is an example of scanning peripherals

l0gg3r
  • 8,864
  • 3
  • 26
  • 46