如何为可变特征创建描述符? [英] How do you create a descriptor for a mutable characteristic?

查看:70
本文介绍了如何为可变特征创建描述符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CBMutableDescriptor:initWithType:value:的文档说,要为type参数传递识别特征的128位UUID。然后继续说,您应该仅对类型参数使用 CBUUIDCharacteristicUserDescriptionString CBUUIDCharacteristicFormatString 之一。最后,没有方法向可变特征添加描述符。

The documentation for CBMutableDescriptor:initWithType:value: says to pass a "128-bit UUID that identifies the characteristic" for the type parameter. It then goes on to say you should only use one of CBUUIDCharacteristicUserDescriptionString or CBUUIDCharacteristicFormatString for the type parameter. Finally, there is no method to add a descriptor to a mutable characteristic.

看来参数正在做两个互斥的事情。一方面,它用于告知O / S描述符所适用的特性,另一方面,它用于设置描述符的类型。第二个更有意义,但是然后如何将描述符添加到特征?

It appears that the parameter is doing two mutually exclusive things. On the one hand, it is being used to tell the O/S which characteristic the descriptor applies to, and on the other, it is being used to set the type of descriptor. The second makes more sense, but then how do you add the descriptor to the characteristic?

是否传递特征的UUID或 CBUUIDCharacteristicUserDescriptionString ,iOS崩溃

Whether you pass the UUID for the characteristic or CBUUIDCharacteristicUserDescriptionString, iOS crashes with

Assertion failure in -[CBMutableDescriptor initWithType:value:], /SourceCache/CoreBluetooth_Sim/CoreBluetooth-59.3/CBDescriptor.m:25

创建CBMutableDescriptor并将其添加的正确方法是什么到CBMutableCharacteristic?

What's the correct way to create the CBMutableDescriptor and add it to a CBMutableCharacteristic?

推荐答案

您对文档是正确的。但是为了让所有人都清楚,这里是CBDescriptor.h中的引用:

You're correct about the docs. But just to be clear for everyone, here is a citation found in CBDescriptor.h:


...仅特征用户说明和特征当前支持
演示文稿格式描述符。
特征扩展属性和客户端特征
配置描述符将在
父服务发布后自动创建,具体取决于
特征本身的属性。

...Only the Characteristic User Description and Characteristic Presentation Format descriptors are currently supported. The Characteristic Extended Properties and Client Characteristic Configuration descriptors will be created automatically upon publication of the parent service, depending on the properties of the characteristic itself.

换句话说,除非您设置了这些描述符,否则系统将阻止您(因此您会导致断言失败)。

So in other words, unless you are setting those descriptors, the system will block you (thus why you got the assertion failure).

所以说您想使用特征用户描述描述符,您可以这样做:

So say you want to use the Characteristic User Description descriptor, you would do:

CBUUID *yourCharUUID = [CBUUID UUIDWithString:@"c07c5050-15a0-11e3-8ffd-0800200c9a66"];//whatever UUID your using

CBMutableCharacteristic *yourCharacteristic = [[CBMutableCharacteristic alloc]initWithType:yourCharUUID properties:CBCharacteristicPropertyWriteWithoutResponse value:nil permissions:perms];

CBUUID *userDescriptionUUID = [CBUUID UUIDWithString:CBUUIDCharacteristicUserDescriptionString];//or set it to the actual UUID->2901

CBMutableDescriptor *yourDescriptor = [[CBMutableDescriptor alloc]initWithType:userDescriptionUUID value:@"myDescriptorValue"];

yourCharacteristic.descriptors = @[yourDescriptor];

让我知道您是否有任何疑问。

Let me know if you have any questions.

这篇关于如何为可变特征创建描述符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆