Bartłomiej Semańczyk
Bartłomiej Semańczyk

Reputation: 61840

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

Currently I recognize beacons, as CLBeaconobjects. 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
    }
}

Upvotes: 1

Views: 1173

Answers (2)

mrtnclzd
mrtnclzd

Reputation: 73

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")
            }
        }
    }
}

Upvotes: 2

Kegham K.
Kegham K.

Reputation: 1614

This is how i do it. I wish it would help.

var nearestBeacon: CLBeacon!


    func beaconManager(_ manager: KTKBeaconManager, didRangeBeacons beacons: [CLBeacon], in region: KTKBeaconRegion)
    {
    let knownBeacons = beacons.filter{ $0.proximity != CLProximity.unknown }
        if (knownBeacons.count > 0) {
            nearestBeacon = knownBeacons[0] as CLBeacon
        }
        print(knownBeacons, "+")


        if nearestBeacon != nil {

            switch nearestBeacon!.minor.intValue {

            case 1:

                changeColorWithAnime(color: .blue, status: .show)

                logNearestBeacon(beacon: "Balcony")



                changeColorWithAnime(color: .orange, status: .hide)
                changeColorWithAnime(color: .yellow, status: .hide)
             //   print("Blue")

            case 2:

                changeColorWithAnime(color: .orange, status: .show)


                logNearestBeacon(beacon: "Bathroom")



                changeColorWithAnime(color: .blue, status: .hide)
                changeColorWithAnime(color: .yellow, status: .hide)
          //      print("Orange")

            case 3:

                changeColorWithAnime(color: .yellow, status: .show)
                logNearestBeacon(beacon: "Bedroom")



                changeColorWithAnime(color: .blue, status: .hide)
                changeColorWithAnime(color: .orange, status: .hide)

             //   print("Yellow")
            default:
                return

            }
        }
    }

Upvotes: -1

Related Questions