Q: How to get advertisement and response data from a bluetooth low energy device in swift 4? My IOS application is trying to get advertisement and response data from a blue device without connect to it. The advertisement and response data should all be 31 bytes long (we used 4 bytes of the header too, plus 27 bytes of data), totally 62 bytes. While android version of app can easily get all this data, I fail to get them in swift. I called advertisement in corebluetooth, but only receive 27bytes of response data. I can not find the 4 header bytes of response data nor the 31 bytes of advertisement data.
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
......
let data2: NSDictionary? = advertisementData[CBAdvertisementDataServiceDataKey] as? NSDictionary
    if data2 != nil {
        let str :Data = (data2!.allValues)[0] as! Data
        bytes = [UInt8](str)
        print("advertisement data: ",bytes)
    }
}


A: Print the advertisementData, you will see that iOS is getting the full advertised data.
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
    print(advertisementData)
    // Add discovered peripheral to the list
    nearbyPeripherals.append(peripheral)
}

You can follow this guide for iOS Corebluetooth.
https://www.raywenderlich.com/231-core-bluetooth-tutorial-for-ios-heart-rate-monitor
