ios5 – CoreBluetooth writeValue:forDescriptor:issue

前端之家收集整理的这篇文章主要介绍了ios5 – CoreBluetooth writeValue:forDescriptor:issue前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的CoreBluetooth应用程序需要启用客户端特征配置描述符中的“指示位”.这是我做的:

>开始扫描
>开始连接设备
>调用discoverServices
>在回调中调用discoverCharacteristics

– (void)peripheral:(CBPeripheral *)peripheral diddiscoverServices:(NSError *)错误
>在回调内调用discoverDescriptorsForCharacteristic

– (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
>内部回调

– (void)peripheral:(CBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristic:(CBCharacteristic *)特征错误:(NSError *)错误

我打了电话:

if ( [[descriptor.UUID representativeString] isEqualToString:@"2902" ] )
        {
            const unsigned char raw_data[] = {0x02};
            NSData *myData = [NSData dataWithBytes: raw_data length: 2];
            [self.cBCP writeValue:myData forDescriptor:descriptor];
        }

但我的应用程序在writeVale崩溃:.控制台中的错误消息是:

Cannot write Client Characteristic Configuration descriptors using
this method!

任何的想法?谢谢

解决方法

很老的问题,但由于没有回答,似乎方法setNotifyValue(_:for :)将为您处理,它取决于下面的charcateristics属性

>仅通知:将启用通知.
>仅指示:将启用指示.
>指示&通知:仅启用通知.

因此,如果需要启用指示,则特征必须仅具有指示属性,并且应删除通知.

我猜这背后的主要原因是指示速度慢得多,因此iOS总是更喜欢最快的选项,除非需要指明.

Read more on the Apple docs

原文链接:https://www.f2er.com/iOS/331502.html

猜你在找的iOS相关文章