Post

Replies

Boosts

Views

Activity

Reply to Add dual communication into ConfiguringAWiFiAccessoryToJoinTheUsersNetwork Apple Example Codes Issue
Hi Matt, Thanks your replay. As you said, MacOS NWListener will ignore extra websocket connection without interfering with the running logic. But I added the button event in the last ViewController and copied the original websocket connection info and sent it to the server. Before sending, the state of NWConnection was 0x3d (waiting) .Normal it is 0x02 (ready). This may have caused me not to be able to send successfully main reason. Of course I am also trying to refactor the WebSocketListenerDelegate code on the macOS side. func startConnection() {                  // Receive state updates for the connection and perform actions upon the ready and failed state.         connection.stateUpdateHandler = { newState in             switch newState {             case .ready:                 print("Connection established")                 self.delegate?.didEstablishConnection(connection: self, with: nil)                              case .preparing:                 print("Connection preparing")             case .setup:                 print("Connection setup")             case .waiting(let error):                 // Attempt to account for a disallowed local network privacy prompt.                 if let currentPathDescription = self.connection.currentPath?.debugDescription {                     print("Check local network privacy permissions: \(currentPathDescription)")                     self.delegate?.didEstablishConnection(connection: self, with: error)                 } else {                     print("Connection waiting: \(error.localizedDescription)")                 }             case .failed(let error):                 print("Connection failed: \(error.localizedDescription)")                                  // Cancel the connection upon a failure.                 self.connection.cancel()                                  // Notify your delegate with an error message when the connection fails.                 self.delegate?.didEstablishConnection(connection: self, with: error)             default:                 break             }         }
Oct ’21
Reply to Add dual communication into ConfiguringAWiFiAccessoryToJoinTheUsersNetwork Apple Example Codes Issue
Yes ,thanks for your open source codes in Apple developer community. Maybe I haven't fully understood your code yet. I would like to ask for some help about the error code of NWConnection state. I comb out my thoughts and added two steps (13, 14)according to your steps. as below: Build and run the BrandXAccessory app. Build and run the BrandXAccessorySetup app on an iOS device, and associate the device with the user's network. In the BrandXAccessory app, click Next to embed the accessory network information in a QR code. A QR code appears with the following encoded network information: SSID of the accessory network: AccessoryWiFi Passphrase of the accessory network: embedded1 Service URL for NWConnection TLS PSK TLS PSK identity In the iOS app, tap Capture Accessory Network Info to bring up a QR code capture session. Point the iOS device's camera at the QR code in the BrandXAccessory app to capture, decode, and save the QR data. Tap Next. In the iOS app, tap Get Network Info to capture the user's network SSID. Tap Next. In the iOS app, tap Associate to Accessory Network. NEHotspotConfiguration creates a Wi-Fi configuration with the accessory's network data from the QR code, applies it to the device, and updates the device's screen when the association finishes. Tap Next. In the iOS app, tap Confirm Network to confirm the device's association with the accessory network. Tap Next. In the BrandXAccessory app, click Start Listener so the NWListener begins listening for incoming connections from the iOS app. In the iOS app, tap Enter Network Passphrase and enter the passphrase for the user's network. Tap Set Passphrase. In the iOS app, tap Send Network Data. The sample sends the passphrase to the BrandXAccessory app, along with the user's network SSID. In the BrandXAccessory app, the view displays the SSID and passphrase of the user's network. In the iOS app, tap Next, and Entry RemoveNetworkConfigurationViewController , add one SendData button, tap SendData button, after collection original websocket info send new data. (This time send data interface ocurrent error code 0x3d NWConnection state is waiting) In the BrandXAccessory app, get the new data info and refresh new data to label. final in the iOS app, tap Remove Network Configuration to disassociate from the accessory network and rejoin the user's network.
Oct ’21