简体   繁体   中英

Writing to Descriptors BLE on iOS device

I have created a simple application and my requirement is to write to a descriptor to a Peripheral in order to get Sensor data. There is a method writeValue(data:Data, descriptor: CBDescriptor) on the apple documentation, but when I try to execute it I get an NSException stating

"Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Client Characteristic Configuration descriptors must be configured using setNotifyValue:forCharacteristic:'".

Can someone please tell me how to write for a descriptor?

Rather than calling WriteValue , you should call SetNofifyValue .

I'm using Xamarin, and the code is as follows (it should be the same principle for xcode)

void SwitchNotify(CBCharacteristic mychar,bool SwitchOn)
{
    mychar.Service.Peripheral.SetNotifyValue(SwitchOn,mychar);
}

I'm not sure if there's a way of writing the descriptors directly, or why Apple have decided to only allow notify/indicate by using this method. Android and Windows (UWP) both allow direct writing of descriptors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM