简体   繁体   English

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

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

Currently I recognize beacons, as CLBeacon objects. 目前,我将信CLBeaconCLBeacon对象。 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 : 我的意思是b1A8

在此处输入图片说明

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

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). iBeacon格式本身不允许在广告包中包含自定义数据,因此Kontakt.io信标具有自定义扫描响应包 ,其中包括电池,固件版本,传输功率以及最重要的:唯一ID( b1A8)。

Because this isn't an iBeacon advertisement packet, you'll need to rely on Core Bluetooth instead of Core Location. 因为这不是iBeacon广告包,所以您需要依靠Core Bluetooth而不是Core Location。 If you're using their SDK, you can do so by using KTKDevicesManager , and KTKNearbyDevice . 如果您使用他们的SDK,则可以使用KTKDevicesManagerKTKNearbyDevice来实现

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

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

            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM