2015-08-15 117 views
1

當配置CBMutableCharacteristic以將iOS設備設置爲外設時,CBCharacteristicProperties的可能值之一是CBCharacteristicPropertyBroadcast。CBCharacteristicPropertyBroadcast的用途

但是,如果你選擇了它,在運行時你會得到:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'CBCharacteristicPropertyBroadcast is not allowed' 

我創建的特徵是這樣的:

let characteristic = CBMutableCharacteristic(type: myCharacteristicUUID, 
         properties: CBCharacteristicProperties.Broadcast, 
         value: characteristicValue, 
         permissions: CBAttributePermissions.Readable) 

什麼是CBCharacteristicPropertyBroadcast的目的是什麼? CBCharacteristicPropertyReadCBCharacteristicPropertyNotify工作,但我想知道爲什麼我不能使用其他值。

理想情況下,我想將用戶數據作爲外設廣播而不用作信標。這是可行的嗎?

+0

請注意,如果您在創建特徵時指定了值,則無法對其進行更改。您需要指定nil作爲初始值,然後根據需要更新它,以便能夠更改數據。 – Paulw11

+0

啊對 - 謝謝。我現在意識到了。 –

回答

1

documentation很清楚。您不能在發佈的特徵上使用此屬性。此值的目的是使您能夠解釋從其他外圍設備發現的特性的屬性。

如果你想告訴集中你的價值已經改變,那麼notify是合適的方法。

+0

所以大概這些其他外設不是iOS設備使用CoreBluetooth廣播他們的廣告? –

+0

沒錯。 Core Bluetooth不是所有藍牙4.0規範都可用的 – Paulw11