1

I'm working on an app , which use CBCentralManager functionality to connect band with iPhone. Band working fine with 5 and 5s, But disconnected just after connected with 6s , 6 plus , 7 and 7 plus . Please help me to solve this issue .

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
    self.connected = true;
    [self.centralManager stopScan];
    [self.data setLength:0];

    peripheral.delegate = self;

    NSString *serviceAddress = [NSString stringWithFormat:@"%x", MBServiceTypeDefault];

    [peripheral discoverServices:@[[CBUUID UUIDWithString:IMMEDIATE_ALERT_SERVICE], [CBUUID UUIDWithString:ADVERTISED_SERVICE],[CBUUID UUIDWithString:serviceAddress]]];

}

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {

    if (error) {
        [self cleanup];
        return;
    }

    for (CBService *service in peripheral.services) {
        self.service = [peripheral.services firstObject];
        [peripheral discoverCharacteristics:nil forService:service];
    }
}
Omal Perera
  • 2,971
  • 3
  • 21
  • 26
  • You need to keep a strong reference on peripheral: `@property (nonatomic, strong) CBPeripheral *myPeripheral`, and in `centralManager:didConnectPeripheral:` (or even in `centralManager:didDiscoverPeripheral:`, just before you try to connect) `_myPeripheral = peripheral`. It's due to the fact that CoreBluetooth don't keep in memory/references on its objects, and they are deallocated (too soon). https://stackoverflow.com/questions/15846663/ios6-cbperipheral-is-being-dealloced-while-connecting Else, if it's disconnected, does it show a reason? (in didDisconnect: or in console logs?) – Larme Jun 13 '17 at 08:22

0 Answers0