我已经成功地让我的 iOS 应用程序(外围)向我的 OSX 应用程序(中央)发送消息。
我现在在尝试让 Central 更新特征值并从 Peripheral 读取它时遇到问题。
如果我将 CBCharacteristicProperties 更改为 Notify 以外的任何内容,我的中心无法订阅该特征并出现以下错误:“不允许写入”。
self.transferCharacteristic = CBMutableCharacteristic(type: CBUUID.UUIDWithString(TRANSFER_CHARACTERISTIC_UUID), properties: CBCharacteristicProperties.Read, value: nil, permissions: CBAttributePermissions.Writeable)
据我了解,为了必须将 Central 写入 Peripheral,我应该在 Peripheral 中使用上述行的组合,并带有此事件:
func peripheralManager(peripheral: CBPeripheralManager!, didReceiveWriteRequests requests: [AnyObject]!) {}
这在中央更新特征值:
self.discoveredPeripheral?.writeValue(passwordData, forCharacteristic: self.characteristicSubscribed, type: CBCharacteristicWriteType.WithoutResponse)
请让我知道我做错了什么。任何展示如何做我想做的事情的示例项目都将受到高度赞赏。
谢谢