Xamarin-IOS BTLE WroteCharacteristicValue没有被解雇

时间:2016-06-08 21:36:52

标签: ios xamarin bluetooth btle

我的IOS实现有以下代码,问题是WroteCharacteristicValue事件永远不会被触发。当我连接到同一个模块时,是在android端被解雇了。任何想法该怎么做?

    public void StartUpdates ()
    {
        // TODO: should be bool RequestValue? compare iOS API for commonality
        bool successful = false;
        if(CanRead) {
            Console.WriteLine ("** Characteristic.RequestValue, PropertyType = Read, requesting read");
            _parentDevice.UpdatedCharacterteristicValue += UpdatedRead;

            _parentDevice.ReadValue (_nativeCharacteristic);

            successful = true;
        }
        if (CanUpdate) {
            Console.WriteLine ("** Characteristic.RequestValue, PropertyType = Notify, requesting updates");
            _parentDevice.UpdatedCharacterteristicValue += UpdatedNotify;

            _parentDevice.WroteCharacteristicValue += Wrote; // -DP here??

            _parentDevice.SetNotifyValue (true, _nativeCharacteristic);

            successful = true;
        }

        Console.WriteLine ("** RequestValue, Succesful: " + successful.ToString());
    }
    void Wrote(object sender, CBCharacteristicEventArgs e) {

        System.Diagnostics.Debug.WriteLine("Characteristic Write Complete!");

        this.WriteComplete (this, new CharacteristicReadEventArgs () {
            Characteristic = new Characteristic(e.Characteristic, _parentDevice)
        });
    } 

1 个答案:

答案 0 :(得分:1)

WroteCharacteristic仅在特征写入响应时才会触发。

您可以查看:

var prop = _nativeCharacteristic.Properties;
if(prop.HasFlag(CBCharacteristicProperties.Write))
{
    // Event can be used
}
else if(prop.HasFlag(CBCharacteristicProperties.WriteWithoutResponse))
{
    // Event will not fire if WriteWithoutResponse
}
顺便说一下:我们为BLE提供了一个插件,所以你不必关心平台特定的东西;)http://smstuebe.de/2016/05/13/blev1.0/