使用Swift和CoreBluetooth创建静态特性
我正在使用Swift 2.2.1构建一个iOS应用程序,它可以作为蓝牙外围设备使用 我想把一个人的名字作为一个静态的特征来宣传,所以我创建了如下特征:使用Swift和CoreBluetooth创建静态特性,swift,core-bluetooth,Swift,Core Bluetooth,我正在使用Swift 2.2.1构建一个iOS应用程序,它可以作为蓝牙外围设备使用 我想把一个人的名字作为一个静态的特征来宣传,所以我创建了如下特征: // Build the NAME characteristic if (identity.name != nil) { nameCharacteristic = CBMutableCharacteristic(type: performerNameCharacteristicUUID, p
// Build the NAME characteristic
if (identity.name != nil) {
nameCharacteristic =
CBMutableCharacteristic(type: performerNameCharacteristicUUID,
properties: ([CBCharacteristicProperties.Read, CBCharacteristicProperties.Broadcast]),
value: myIdentity?.name?.dataUsingEncoding(NSUTF8StringEncoding,
allowLossyConversion: false),
permissions: CBAttributePermissions.Readable)
characteristicsArray.append(nameCharacteristic!)
}
当程序运行时,调用addServices并弹出此异常:
***由于未捕获异常“NSInternalInconsistencyException”而终止应用程序,
原因:“具有缓存值的特征必须为只读”
如果能想到我可能做错了什么,我将不胜感激 您不能将
CBCharacteristicProperties.Broadcast
属性与您自己创建的特征一起使用。从:
- CBCharacteristicPropertyBroadcast可以使用特征配置描述符广播特征值
通过发布的本地特征不允许使用此属性
类的cbperipheraldmanager
方法。这意味着 当您初始化新属性时,不能使用此属性addService:
通过CBMutableCharacteristic
initWithType:properties:value:permissions:
classCBMutableCharacteristic
您不能将
CBCharacteristicProperties.Broadcast
属性与您自己创建的特征一起使用。从:
- CBCharacteristicPropertyBroadcast可以使用特征配置描述符广播特征值
通过发布的本地特征不允许使用此属性
类的cbperipheraldmanager
方法。这意味着 当您初始化新属性时,不能使用此属性addService:
通过CBMutableCharacteristic
initWithType:properties:value:permissions:
classCBMutableCharacteristic
修正-谢谢!我在以前的版本中使用了它,无意中又重新引入了它-非常感谢您的帮助!修正-谢谢!我在以前的版本中使用了它,无意中又重新引入了它-非常感谢您的帮助!