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.
Topic:
App & System Services
SubTopic:
Networking
Tags: