我正在尝试在 Swift 中创建 application/vnd.wfa.wsc 有效负载。我在这里为 Android 找到了这篇文章: Creating an NDEF WiFi record using application/vnd.wfa.wsc in Android
我坚持创建我想在 NFC 标签上写入的有效负载。我试图将 java 代码转换为 swift 并将有效负载写入 NFC 标签,但我无法使用 android 手机读取数据。
let VERSION: [UInt8] = [0x10, 0x4A]
let CREDENTIAL: [UInt8] = [0x10, 0x0e]
let AUTH_TYPE: [UInt8] = [0x10, 0x03]
let CRYPT_TYPE: [UInt8] = [0x10, 0x0F]
let MAC_ADDRESS: [UInt8] = [0x10, 0x20]
let NETWORK_IDX: [UInt8] = [0x10, 0x26]
let NETWORK_KEY: [UInt8] = [0x10, 0x27]
let NETWORK_NAME: [UInt8] = [0x10, 0x45]
let OOB_PASSWORD: [UInt8] = [0x10, 0x2C]
let VENDOR_EXT: [UInt8] = [0x10, 0x49]
let VENDOR_WFA: [UInt8] = [0x00, 0x37, 0x2A]
let VERSION2: [UInt8] = [0x00]
let KEY_SHAREABLE: [UInt8] = [0x02]
let AUTH_OPEN: [UInt8] = [0x00, 0x01]
let AUTH_WPA_PERSONAL: [UInt8] = [0x00, 0x02]
let AUTH_SHARED: [UInt8] = [0x00, 0x04]
let AUTH_WPA_ENTERPRISE: [UInt8] = [0x00, 0x08]
let AUTH_WPA2_ENTERPRISE: [UInt8] = [0x00, 0x10]
let AUTH_WPA2_PERSONAL: [UInt8] = [0x00, 0x20]
let AUTH_WPA_WPA2_PERSONAL: [UInt8] = [0x00, 0x22]
let CRYPT_NONE: [UInt8] = [0x00, 0x01]
let CRYPT_WEP: [UInt8] = [0x00, 0x02]
let CRYPT_TKIP: [UInt8] = [0x00, 0x04]
let CRYPT_AES: [UInt8] = [0x00, 0x08]
let CRYPT_AES_TKIP: [UInt8] = [0x00, 0x0C]
let credential: [UInt8] = [0x00, 0x36]
let idx: [UInt8] = [0x00, 0x01, 0x01]
let ssid = "TestWifi"
let password = "Test12345"
let ssidBytes: [UInt8] = Array(ssid.utf8)
let passwordBytes: [UInt8] = Array(password.utf8)
let authBytes: [UInt8] = Array("WPA PSK".utf8)
let lengthSSID: [UInt8] = [UInt8(ssid.lengthOfBytes(using: .utf8))]
let lengthPassword: [UInt8] = [UInt8(password.lengthOfBytes(using: .utf8))]
let cred: [UInt8] = CREDENTIAL + credential
let index: [UInt8] = NETWORK_IDX + idx
let network: [UInt8] = NETWORK_NAME + lengthSSID + ssidBytes
let auth: [UInt8] = AUTH_TYPE + AUTH_WPA_PERSONAL + authBytes
let crypt: [UInt8] = CRYPT_TYPE + CRYPT_WEP + CRYPT_AES_TKIP
let netw: [UInt8] = NETWORK_KEY + lengthPassword + passwordBytes
let foo1 = cred + index
let foo2 = network + auth
let foo3 = crypt + netw
let payload = foo1 + foo2 + foo3
let type = Data(base64Encoded: "application/vnd.wfa.wsc".base64Encoded()!)!
let identifier = Data(base64Encoded: "".base64Encoded()!)!
let payloadData = Data(bytes: payload, count: payload.count)
let payload = NFCNDEFPayload(format: .media, type: type, identifier: identifier, payload: payloadData)
有人可以指出我做错了什么吗?