MariusB
MariusB

Reputation: 53

Xamarin IOS setDesiredConnectionLatency

I need to set the connection latency on my BLE connection, but the documentation is very sparse on setDesiredConnectionLatency.

I use the CoreBluetooth framework for IOS, and the documentation simply refers to the actual method:

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

I cannot see any examples, documentation or guides on how to use this, I have tried the following:

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

I do not know how to either obtain a CBCentral instance, or how to create one.

Can someone please point me in the right direction on how to either use SetDesiredConnectionLatency or CBCentral

Upvotes: 1

Views: 694

Answers (1)

nbloqs
nbloqs

Reputation: 3282

In Swift 3.0, you can try to set the latency after having established a connection, since latency belongs to a peripheral-central connection, no to the peripheral itself (take a look to this link: https://developer.apple.com/reference/corebluetooth/cbperipheralmanager/1393277-setdesiredconnectionlatency)

One way of ensuring that you already have a connection (but that only works if you have characteristics in your peripheral to which the central can suscribe) is by implementing the didSubscribe callback in your CBPeripheralManagerDelegate class:

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

Upvotes: 1

Related Questions