Bartłomiej Semańczyk Bartłomiej Semańczyk -4 years ago 185
Swift Question

How do I get the id of the beacon using Kontakt.io beacons?

Currently I recognize beacons, as

CLBeacon
objects. Example:

CLBeacon (uuid:F7826DA6-4FA2-4E98-8024-BC5B71E0893E, major:57140, minor:4299, proximity:1 +/- 0.77m, rssi:-75)


But I need here the name of the beacon. I mean
b1A8
:

enter image description here

Is there any way to access it from code?

Now, I do it like this:

func beaconManager(_ manager: KTKBeaconManager, didRangeBeacons beacons: [CLBeacon], in region: KTKBeaconRegion) {

for beacon in beacons {

//here need to have a name
}
}

Answer Source

The iBeacon format itself doesn't allow for custom data to be included on the advertising packet, so Kontakt.io beacons have a custom scan response packet, which includes things like battery, firmware version, transmission power, and most importantly: unique ID (b1A8).

Because this isn't an iBeacon advertisement packet, you'll need to rely on Core Bluetooth instead of Core Location. If you're using their SDK, you can do so by using KTKDevicesManager, and KTKNearbyDevice.

From their developer center:

extension ViewController: KTKDevicesManagerDelegate {
    func devicesManager(_ manager: KTKDevicesManager, didDiscover devices: [KTKNearbyDevice]?) {
        guard let nearbyDevices = devices else {
            return
        }

        for device in nearbyDevices {
            if let uniqueId = device.uniqueID {
                print("Detected a beacon \(uniqueId)")
            } else {
                print("Detected a beacon with an unknown Unique ID")
            }
        }
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download