0

We have one bluetooth devices.We using core_bluetooth.framework.Bluetooth Devices have data.We need to Get Data for bluetooth Devices to my iPhone.We tried like this

-(void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    NSLog(@"Discovered peripheral %@ (%@)",peripheral.name,peripheral.identifier.UUIDString);
    if (![self.discoveredPeripherals containsObject:peripheral] ) {

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.discoveredPeripherals addObject:peripheral];
            [self.tableview insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.discoveredPeripherals.count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationLeft];
        });
    }
    [central connectPeripheral:peripheral options:nil];
}   
-(void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
    peripheral.delegate = self;

    if(peripheral.services)
        [self peripheral:peripheral didDiscoverServices:nil]; //already discovered services, DO NOT re-discover. Just pass along the peripheral.
    else
        [peripheral discoverServices:nil];

}
-(void) peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
    for(CBService* svc in peripheral.services)
    { NSLog(@" service %@",svc.description);
       if(svc.characteristics)
 [self peripheral:peripheral didDiscoverCharacteristicsForService:svc error:nil]; 
        else
[peripheral discoverCharacteristics:nil forService:svc]; 
 }
}
-(void) peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
    for (CBCharacteristic *characteristic in service.characteristics ) {
        NSLog(@"Discovered characteristic %@(%@)",characteristic.description,characteristic.UUID.UUIDString);
        NSLog(@"Characteris is %@",[characteristic description]);
    }
}

We got Devices name and Devices UUID number. But our Problem is We never call didDiscoverServices and didDiscoverCharacteristicsForServices.I wants to hit my head on my monitor i am very frustrated with this problem.Please guide to us.What wrong in my code

1 Answers1

0

I have done recently Bluetooth functionality for my VOIP based app. I used corebluetooth framework for that. Also i used MPVolumeview (Airplay) for displaying avaialble bluetooths in pickerview as actionsheet. Coming to corebluetooth frame work, First #Import corebluetooth framework and then create instance for Corebluetoothmanager and after initialize call, following delegate method

  • (void)centralManagerDidUpdateState:(CBCentralManager *)central { }

except this delegate method, no other delegates methods invoking in iOS 8.0 onwards.So, in above delegate method, you can track bluetooth of iPhone/iPad bluetooth is active or not. If its active state, check the audioroute either bluetooth or speaker or Microbuiltinphone. If its bluetooth then add MPVolumeView to ur view to display bluetooth icon.

Also along with this, use Audioroutechange notification to track the External bluetooth state either ON/OFF. According to that you can know the external bluetooth device state.

I hope this description helps you a lot.