【问题标题】:RSSI of CLBeacon from a dictionary return nil来自字典的 CLBeacon 的 RSSI 返回 nil
【发布时间】:2020-07-23 10:09:50
【问题描述】:

我有一个字典,它的键是 UDID,值是 CLBeacon。当我尝试访问 CLBeacon 的 RSSI 时,它返回 nil,但如果我打印整个字典,我会看到 CLBeacon 和 RSSI 值。

CLBeacon dictionary

让 beaconDict = viewContr.beaconsDict 作为 NSDictionary

    for (key, value) in beaconDict {
        let beacon = value as? CLBeacon
        let rssi = beacon?.rssi
        print("key=\(key), value=\(rssi)")
    }
    print("The dictionary is: \(beaconDict))")
}

【问题讨论】:

  • 您是否尝试打印除 rssi 以外的其他值? UUID、次要、主要等。由于某种原因,看起来像 CLBeacon 的转换失败

标签: swift dictionary ibeacon


【解决方案1】:

该值返回一个 NSArray。 更改以下内容。

let beacon = value as? CLBeacon
     

let array = value as! NSArray
let beacon = array.firstObject as? CLBeacon

【讨论】:

    猜你喜欢
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多