【问题标题】:How do I get the id of the beacon using Kontakt.io beacons?如何使用 Kontakt.io 信标获取信标的 ID?
【发布时间】:2017-05-18 09:44:07
【问题描述】:

目前我将信标识别为CLBeaconobjects。示例:

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

【问题讨论】:

    标签: ios swift kontakt.io


    【解决方案1】:

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

    因为这不是 iBeacon 广告数据包,所以您需要依赖 Core Bluetooth 而不是 Core Location。如果您使用的是他们的 SDK,则可以使用 KTKDevicesManagerKTKNearbyDevice

    来自他们的开发者中心:

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

    【讨论】:

      【解决方案2】:

      我就是这样做的。我希望它会有所帮助。

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

      【讨论】:

      • 这对 OP 没有任何帮助,因为它没有参考获取信标的名称或标识符。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      • 1970-01-01
      相关资源
      最近更新 更多