I am trying to do a connection, with NWConneciton, and wanted to know if the connect fails? I can't seem to determine what status I should look for
How to tell if NWConnection "connect" failed?
This is related to your other thread, but it’s a more general question so I thought I’d respond here more generally.
How to tell if
NWConnection
"connect" failed?
In networking the concept of ‘failed to connect’ is trickier than it sounds. Let’s say the user is using your app and, just as they tap the Connect button, they step into a lift. The doors close and the device loses the cellular signal, so there’s no WWAN. What should happen?
You probably don’t want the connection to fail. Rather, you want it to continue to retry until the user explicitly cancels the connection. In this specific case, the user understands that WWAN isn’t available while in the lift, but they won’t cancel because they know that they’ll soon step out of the lift and the connection will go through.
So, my general advice on this topic is:
-
Classify your connections as to whether they are directly solicited by the user or not.
-
For a solicited connection, display a connection UI and allow the user to cancel and retry.
-
For an solicited connection — one that your app is managing itself, without the user being aware of it — decide whether you want to continue waiting indefinitely. If so, do nothing. If not, implement your own timeout.
If you do implement your own timeout, make it long, at least 60 seconds, to avoid unnecessary thrash.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Ok, thanks. The code I am working on is for a small Mac mini, which has about 40 different devices (Small Single Board Controllers) that connect to it (they come and go), that the server controls. In addition, one other Mac mini connects (another Client), that is controlled (it runs a media setup that is controlled and orcherstrated by the server).