Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Swift和CoreBluetooth创建静态特性_Swift_Core Bluetooth - Fatal编程技术网

使用Swift和CoreBluetooth创建静态特性

使用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

我正在使用Swift 2.2.1构建一个iOS应用程序,它可以作为蓝牙外围设备使用

我想把一个人的名字作为一个静态的特征来宣传,所以我创建了如下特征:

    // 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:
    CBMutableCharacteristic
    class


您不能将
CBCharacteristicProperties.Broadcast
属性与您自己创建的特征一起使用。从:

  • CBCharacteristicPropertyBroadcast可以使用特征配置描述符广播特征值

    通过发布的本地特征不允许使用此属性
    cbperipheraldmanager
    类的
    addService:
    方法。这意味着 当您初始化新属性时,不能使用此属性
    CBMutableCharacteristic
    通过
    initWithType:properties:value:permissions:
    CBMutableCharacteristic
    class


修正-谢谢!我在以前的版本中使用了它,无意中又重新引入了它-非常感谢您的帮助!修正-谢谢!我在以前的版本中使用了它,无意中又重新引入了它-非常感谢您的帮助!