我正在使用Xamarin.iOS编写iOS应用程序,但是在本机iOS中的回答也将不胜感激。我的应用程序使用BLE写入特性在设备之间发送消息。我用于创建服务并将其添加到CBPeripheralManager的代码:
_cbPeripheralManager.WriteRequestsReceived += WriteRequestReceived; // WriteRequestReceived is never called
// my read characteristic actually works fine
_readCharacteristic = new CBMutableCharacteristic(CBUUID.FromString(MyReadCharacteristicUuid), CBCharacteristicProperties.Read | CBCharacteristicProperties.Notify, null, CBAttributePermissions.Readable);
// but my write characteristic doesn't work when i try to write to it
_writeCharacteristic = new CBMutableCharacteristic(CBUUID.FromString(MyWriteCharacteristicUuid), CBCharacteristicProperties.Write | CBCharacteristicProperties.Notify, null, CBAttributePermissions.Writeable);
_service = new CBMutableService(CBUUID.FromString(MyServiceUuid), true);
_service.Characteristics = new CBCharacteristic[2] { _readCharacteristic, _writeCharacteristic };
_cbPeripheralManager.AddService(_service);
我的代码将写入外围设备的特性(为简单起见,未显示设备和服务/特性发现的代码)
peripheral.WroteCharacteristicValue += handler; // handler is never called
peripheral.WriteValue(NSData.FromString("hello"), characteristic, CBCharacteristicWriteType.WithoutResponse);
知道可能是什么问题吗?