Post

Replies

Boosts

Views

Activity

Add dual communication into ConfiguringAWiFiAccessoryToJoinTheUsersNetwork Apple Example Codes Issue
Add above codes to Matt's [https://developer.apple.com/documentation/networkextension/configuring_a_wi-fi_accessory_to_join_the_user_s_network] sample to verify certified local network, Why not correct send to server ? Thanks any reply. ``**Button Action**`` SetupRemoveHotspotViewController @IBAction func sendDataBTN() { // This part get url info and create a valid WebSocket connection。 if websocketConnection == nil,let connectionTuple = DeviceNetworkManager.shared.accessoryNetwork?.accessoryConnectionInfo { // (scheme: String, host: String, port: String, psk: String, pskIdentity: String) var urlComponents = URLComponents() urlComponents.scheme = connectionTuple.scheme urlComponents.host = connectionTuple.host urlComponents.port = Int(connectionTuple.port) guard let wsURL = urlComponents.url else { print("Failed to build a proper URL out of URLComponents") return } // Create the new NWConnection object. let tlsParams = NWParameters(psk: connectionTuple.psk, pskIdentity: connectionTuple.pskIdentity) let urlConnectionEndpoint = NWEndpoint.url(wsURL) let connection = NWConnection(to: urlConnectionEndpoint, using: tlsParams) let websocket = WebSocketConnection(newConnection: connection) websocketConnection = websocket websocket.delegate = self websocket.startConnection() } } ``**Delegation sendData **``SetupRemoveHotspotViewController extension SetupRemoveHotspotViewController: WebSocketConnectionDelegate { /// @function didEstablishConnection /// @discussion Automatically sends the network information when the app establishes a valid WebSocket connection. func didEstablishConnection(connection: WebSocketConnection, with error: Error?) { let message = WebSocketMessage(ssid: DeviceNetworkManager.shared.getOriginalAssociatedSSID(), passphrase: "123456789", status: "", sendData: "TEST12345") connection.sendDataOnConnection(websocketMessage: message) } /// @function didReceivedData /// @discussion Validates the response and instructs the user to remove the configuration (if it's still present from joinOnce). func didReceivedData(connection: WebSocketConnection, with messageResponse: WebSocketMessage) { var instructionMessage = "\(messageResponse.ssid):\(messageResponse.passphrase)" if messageResponse.status == "ACK" { // Cancel the connection. connection.cancel() didPassNetworkDataSuccessfully = true } } }
5
0
737
Oct ’21