如何使用 Kontakt.io 个信标获取信标的 ID?

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

目前我将信标识别为 CLBeacon 对象。示例:

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

但我需要信标的名称。我是说 b1A8:

有什么方法可以从代码访问它吗?

现在,我这样做:

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

    for beacon in beacons {

        //here need to have a name
    }
}

我就是这样做的。希望对您有所帮助。

var nearestBeacon: CLBeacon!


    func beaconManager(_ manager: KTKBeaconManager, didRangeBeacons beacons: [CLBeacon], in region: KTKBeaconRegion)
    {
    let knownBeacons = beacons.filter{ [=10=].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

            }
        }
    }

iBeacon 格式本身不允许在广告数据包中包含自定义数据,因此 Kontakt.io 信标具有自定义 scan response packet,其中包括电池、固件版本、传输等内容电源,最重要的是:唯一 ID (b1A8)。

因为这不是 iBeacon 广告数据包,所以您需要依赖核心蓝牙而不是核心位置。如果您使用的是他们的 SDK,则可以使用 KTKDevicesManager, and KTKNearbyDevice.

来自他们的开发者中心:

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