gpt4 book ai didi

ios - Xamarin-IOS BTLE WroteCharacteristicValue 未触发

转载 作者:行者123 更新时间:2023-11-29 00:54:48 26 4
gpt4 key购买 nike

我的 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)
});
}

最佳答案

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/

关于ios - Xamarin-IOS BTLE WroteCharacteristicValue 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37713353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com