在Swift中的iOS BLE扫描中提取advertiseData [kCBAdvDataManufacturer]的内容

时间:2014-08-24 18:48:03

标签: ios swift bluetooth-lowenergy core-bluetooth

我想帮助提取字典的内容:

advertisementData[kCBAdvDataManufacturer]

advertisementData是iOS在BLE扫描期间找到广告BLE服务器时返回的参数之一。

我看到它的类型为AnyObject。当我打印它时,我可以看到<>中包含的第一个字符。

如何提取剩余的字节内容?

2 个答案:

答案 0 :(得分:0)

很可能你需要转换为String

let manufacturerName = advertisementData[kCBAdvDataManufacturer]! as String
println("The manufacturer is \(manufacturerName).")

答案 1 :(得分:0)

Swift 3

 let manufactureData = ((advertisementData as NSDictionary).value(forKey: "kCBAdvDataManufacturer")) as? String
 print(manufactureData)