在 Swift 中的 iOS BLE 扫描中提取广告数据 [kCBAdvDataManufacturer] 的内容
Posted
技术标签:
【中文标题】在 Swift 中的 iOS BLE 扫描中提取广告数据 [kCBAdvDataManufacturer] 的内容【英文标题】:Extract Contents of advertisementData[kCBAdvDataManufacturer] in iOS BLE scan in Swift 【发布时间】:2014-08-24 18:48:02 【问题描述】:我想帮忙提取字典的内容:
advertisementData[kCBAdvDataManufacturer]
advertisementData
是 ios 在 BLE 扫描期间发现广告 BLE 服务器时返回的参数之一。
我看到它的类型是AnyObject
。当我打印它时,我可以看到包含在 中的第一个字符。
如何提取剩余的字节内容?
【问题讨论】:
【参考方案1】:您很可能需要转换为字符串
let manufacturerName = advertisementData[kCBAdvDataManufacturer]! as String
println("The manufacturer is \(manufacturerName).")
【讨论】:
【参考方案2】:斯威夫特 3
let manufactureData = ((advertisementData as NSDictionary).value(forKey: "kCBAdvDataManufacturer")) as? String
print(manufactureData)
【讨论】:
以上是关于在 Swift 中的 iOS BLE 扫描中提取广告数据 [kCBAdvDataManufacturer] 的内容的主要内容,如果未能解决你的问题,请参考以下文章