Beacons in Windows 10

后端 未结 4 472
盖世英雄少女心
盖世英雄少女心 2021-02-03 10:10

Is there any way to use ibeacons with Windows 10 development? Since ibeacons development with previous versions of Windows seemed nearly impossible, will we have the oportunity

4条回答
  •  無奈伤痛
    2021-02-03 10:35

    Here is how you work with Apple iBeacons based on the new Windows 10 APIs mentioned in the answer by Rob Caplan:

    1. Start watching for beacons:

    BluetoothLEAdvertisementWatcher watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active };
    watcher.Received += WatcherOnReceived;
    

    1. Handle beacon data - note that depending on your scenario, you might need to distinguish between beacons by storing them and comparing the Bluetooth address

    private void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs btAdv)
    {
        // Optional: distinguish beacons based on the Bluetooth address (btAdv.BluetoothAddress)
        // Check if it's a beacon by Apple
        if (btAdv.Advertisement.ManufacturerData.Any())
        {
            foreach (var manufacturerData in btAdv.Advertisement.ManufacturerData)
            {
                // 0x4C is the ID assigned to Apple by the Bluetooth SIG
                if (manufacturerData.CompanyId == 0x4C)
                {
                    // Parse the beacon data according to the Apple iBeacon specification
                    // Access it through: var manufacturerDataArry = manufacturerData.Data.ToArray();
                }
            }
        }
    }
    

    This is also how I implemented it in the open source Universal Beacon Library, which comes with complete sample code and an app to try it out: https://github.com/andijakl/universal-beacon

提交回复
热议问题