约30秒后BLE按钮断开连接

时间:2018-07-04 09:17:21

标签: ios objective-c core-bluetooth

我正在实现与蓝牙低能耗按键通话按钮的简单连接。一切正常,除了设备(iphone)在约30秒后从外围设备断开连接的事实。

我正在使用单例来管理CBCentralManager并强烈引用CBPeripheral,在阅读了所有其他StackOverflow问题/答案之后,我找不到任何简洁的方法。

代码如下:

//DeviceManager.m

-(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(nullable NSError *)error{
    NSArray *services = peripheral.services;
    for(CBService *service in services){
        if([service.UUID.UUIDString isEqualToString:(NSString*)UUID_SERVICE_BUTTON]){
            [peripheral discoverCharacteristics:nil forService:service];
        }
    }
}
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverIncludedServicesForService:(CBService *)service error:(NSError *)error{

}
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{
    NSLog(@"START DATE %@",[NSDate new]);
    NSArray <CBCharacteristic*> * characteristics = service.characteristics;
    for (CBCharacteristic *characteristic in characteristics) {
        [peripheral setNotifyValue:YES forCharacteristic:characteristic];
        if([characteristic.UUID.UUIDString isEqualToString:(NSString*)UUID_SERVICE_BUTTON_CHARATERISTIC_STATE]){
        }
        [peripheral discoverDescriptorsForCharacteristic:characteristic];
    }
    self.peripheralManager = [[CBPeripheralManager alloc]initWithDelegate:self queue:nil];

}
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
    NSLog(@"%@",characteristic);
    [peripheral setNotifyValue:YES forCharacteristic:characteristic];
}

**请记住,BT设备只有1个服务,1个特征和1个描述符**

我在这里想念什么?

谢谢!

0 个答案:

没有答案