目前,我将信标识别为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
}
}发布于 2017-05-19 05:00:46
iBeacon格式本身不允许在广告包中包含自定义数据,因此Kontakt.io信标有一个自定义https://support.kontakt.io/hc/en-gb/articles/201492522,它包括电池、固件版本、传输功率,最重要的是:唯一ID (b1A8)。
因为这不是一个iBeacon广告包,所以您需要依赖Core蓝牙而不是Core。如果使用他们的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")
}
}
}
}发布于 2017-05-18 10:39:27
我就是这样做的。我希望它能帮上忙。
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
}
}
}https://stackoverflow.com/questions/44044241
复制相似问题