Xamarin IOS setDesiredConnectionLatency

Xamarin IOS setDesiredConnectionLatency

我需要在我的 BLE 连接上设置连接延迟,但关于 setDesiredConnectionLatency 的文档非常少。

我IOS使用的是CoreBluetooth框架,documentation只是指实际方法:

  [Foundation.Export("setDesiredConnectionLatency:forCentral:")]
  public virtual Void SetDesiredConnectionLatency (CBPeripheralManagerConnectionLatency latency, CBCentral connectedCentral)

我看不到有关如何使用它的任何示例、文档或指南,我尝试了以下方法:

  var peripheralDelegate = new PeripheralManagerDelegate();
  //CBCentral central = new CBCentral();
  CBPeripheralManager peripheralManager = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
  peripheralManager.SetDesiredConnectionLatency(CBPeripheralManagerConnectionLatency.Low, central);

我不知道如何获取或创建一个 CBCentral 实例。

有人可以为我指明正确的方向,了解如何使用 SetDesiredConnectionLatencyCBCentral

在Swift 3.0中,您可以尝试在建立连接后设置延迟,因为延迟属于外围-中心连接,对外围设备本身没有(看看这个link:https://developer.apple.com/reference/corebluetooth/cbperipheralmanager/1393277-setdesiredconnectionlatency

确保您已经建立连接的一种方法(但只有当您的外围设备具有中央可以订阅的特征时才有效)是通过在 CBPeripheralManagerDelegate 中实现 didSubscribe 回调] class:

public func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didSubscribeTo characteristic: CBCharacteristic) {
    peripheralManager?.setDesiredConnectionLatency(.low, for: central)
}