目前我认为信标为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
}
}
答案 0 :(得分:1)
iBeacon格式本身并不允许将自定义数据包含在广告数据包中,因此Kontakt.io信标具有自定义scan response packet,其中包括电池,固件版本,传输功率,最重要的是:唯一ID(b1A8)。
因为这不是iBeacon广告包,所以您需要依靠Core Bluetooth而不是Core Location。如果您正在使用他们的SDK,则可以使用KTKDevicesManager和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")
}
}
}
}
答案 1 :(得分:0)
我就是这样做的。我希望它会有所帮助。
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
}
}
}