Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

ConnectedPeripheral not getting called (CoreBluetooth)

$
0
0

Hi all. I am having partial success with implementing Bluetooth LE.

I have created a CBCentralManager object with an attached CBCentralManagerDelegate, like so:

public class CMD : CBCentralManagerDelegate
{
// overridden methods here... see below
}
public override void ViewDidLoad ()
{
        base.ViewDidLoad();
        System.Threading.Tasks.Task t = new System.Threading.Tasks.Task (() => {
            CMD cmd = new CMD();
            CBCentralManager CM = new CBCentralManager(cmd,MonoTouch.CoreFoundation.DispatchQueue.MainQueue);
            CM.Init ();
        });
        t.Start ();
}

UpdatedState is being called correctly, where I then scan for peripherals:

public override void UpdatedState (CBCentralManager central)
{
    if (central.State == CBCentralManagerState.PoweredOn) 
    {
        Debug.WriteLine ("Scanning for peripherals...");
        central.ScanForPeripherals(serviceID);
    }
}

Once a peripheral is found, DiscoveredPeripheral is being called correctly. I then connect to the peripheral:

public override void DiscoveredPeripheral (CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI)
{
        central.StopScan();
        central.ConnectPeripheral(peripheral);
}    

I successfully connect to the peripheral but that's where the fun ends. CBCentralManagerDelegate.ConnectedPeripheral never gets called. The method below doesn't get executed.

public override void ConnectedPeripheral(CBCentralManager central, CBPeripheral peripheral)
{
    Debug.WriteLine ("Connected to " + peripheral.Name);
}

Have I misunderstood something, or should this work as is? How can I further diagnose why ConnectedPeripheral isn't being called?


Viewing all articles
Browse latest Browse all 204402

Trending Articles