简体   繁体   中英

Extract Contents of advertisementData[kCBAdvDataManufacturer] in iOS BLE scan in Swift

I would like help extracting the contents of the dictionary:

advertisementData[kCBAdvDataManufacturer]

advertisementData is one of the parameters returned when iOS finds an advertising BLE server during a BLE scan.

I see that it is of type AnyObject . When I print it I can see the first character enclosed within <>.

How can I extract the rest of the byte contents?

Most likely you need to cast to String

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

Swift 3

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM