Thursday, 21 March 2019

Get Manufacturer Data from BLE on iOS devices

In my Xamarin.Android app, I can read Manufacturer Data from BLE with the following code:

public class CustomScanCallback : ScanCallback
{
    public override void OnScanResult([GeneratedEnum] ScanCallbackType callbackType, ScanResult result)
    {
        base.OnScanResult(callbackType, result);

        if (result.ScanRecord.ManufacturerSpecificData != null)
        {
            var dataByteResult = result.ScanRecord.GetManufacturerSpecificData(0xFFFE);

            if (dataByteResult != null)
            {
                Guid dataResult = new Guid(dataByteResult);

                if (dataResult.ToString() == "myUuid")
                {
                    // found the uuid from my UWP app
                }
            }
        }
    }
}

How can I do the same on Xamarin.iOS? I have a callback for when peripherals are discovered:

_cbCentralManager.DiscoveredPeripheral += CBCentralManager_DiscoveredPeripheral;

private void CBCentralManager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
{
    // how to find "myUuid" ?
}

And have tried many things to find it, but couldn't. An answer in Swift/Obective-C would help too as I can translate it to C#.

EDIT

I looked through the advertisement data parameter with the key CBAdvertisementDataManufacturerDataKey and found the value:

<06000109 2002aa4e 7e54b91f 2212c398 74eb0fe9 9fc3ecce 4ce76d8f aa>

It looks like it's encoded in hex format, but don't think it's my uuid that I am looking for...



from Get Manufacturer Data from BLE on iOS devices

No comments:

Post a Comment