1

I initialize the CBCenteralManager in viewdidload on main queue. First time update state method is called and start scanning for bluetooth devices but didDiscoverPeripheral: delegate method never get called.

Code is :

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.CM = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
}

-(void)centralManagerDidUpdateState:(CBCentralManager *)central{

    if (central.state == CBCentralManagerStatePoweredOn) {

        [self.CM scanForPeripheralsWithServices:nil options:nil];

    }
}

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

}
-(void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals{

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

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

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

}
Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
  • 2
    Your code looks correct. Have you tried the LightBlue app from the app store to verify that your peripheral is advertising? – Paulw11 Apr 02 '14 at 10:39
  • Probably because is not discovering any peripheral. Do you have some NSLog inside `didDiscoverPeripheral:` to know if is called? – Gabriel.Massana Apr 02 '14 at 10:41
  • you are right , LightBlue app not discovering any device whatever nokia or ios. So, can you please tell me what is the reason ? –  Apr 02 '14 at 13:18
  • A couple of options: 1. Your receiving device is not BLE capable - Is it iPhone 4S or later or iPad 3 or later? 2. Your device is not advertising as a peripheral. Note that core bluetooth will not detect legacy Bluetooth 2.1 devices. If you have two BLE capable iOS devices then you can run LightBlue as peripheral mode on one and central mode on the other – Paulw11 Apr 02 '14 at 22:14
  • but my ios device search all the bluetooth devices when i see in device settings. –  Apr 03 '14 at 09:11
  • my ios devices are iphone4s,ipadmini,iphone5s. and nokia device is nokia c1-01. –  Apr 03 '14 at 09:15
  • can you please test my code on your end. –  Apr 03 '14 at 09:17
  • yes Gabriel.Massana, i have NSLog but delegate method not called. –  Apr 04 '14 at 09:06
  • i have found the solution that two device connected when one is centralManager and second is peripheralmanager. –  Apr 30 '14 at 08:19
  • how you did that in your code @VishnuJangid – Deepraj Chowrasia Jul 25 '16 at 13:19

0 Answers0