NWUDPSession never viable after WiFi disabled

I'm developing a NetworkExtension. I use an NWUDPSession to maintain a connection (of sorts—UDP is connectionless) with a server. I watch the session's hasBetterPath property and construct an "upgrade" session when it's true. You can prompt this behavior by switching off WiFi. The problem is this: after WiFi is switched off, the new session's `viable` property never becomes true, and it ignores all datagrams written to it.


That's the specific problem I'm tracking at the moment, but it's symptomatic of a set of problems with NetworkExtensions and network interface changes, such as switching the WiFi off.


  • `NSURLSession.dataTaskWithRequest()` when called from the NetworkExtension times out after a long delay.
  • POSIX UDP sockets created within the NetworkExtension successfully `connect()`, but `send()` fails with "Cannot allocate memory."
  • As of iOS 10.0.2, the WiFi icon in the status bar remains gray after switching off the WiFi button in Settings. WiFi really does seem to be off and data from apps are routed through the WWAN device. The icon will remain in this state until the NetworkExtension is disabled (i.e. turn off the VPN switch in Settings) or WiFi is switched back on.


In general it appears that switching off WiFi on an iPhone causes NetworkExtensions to lose the ability to talk over any network interface until WiFi is switched on again. Is this the intended behavior? If not, how can we "upgrade" an NWUDPSession such that it becomes `viable` again? If so, how should NetworkExtensions continue operating on a WWAN context?


Significantly, if the NetworkExtension starts in a WWAN context (no WiFi), it communicates happily across cellular. If you then switch WiFi *on*, the NetworkExtension continues to communicate happily with no interruption. But if you then switch WiFi off again, the NetworkExtension fails in the ways described above, except that the WiFi status bar icon does successfully disappear in this context (even on iOS 10; this particular symptom never appears on iOS 9).


So my question: Am I doing something wrong? Or is it true, as it appears, that there is a set of operating system bugs surrounding NetworkExtensions and the loss of WiFi?

Replies

Which of these symptoms are new in iOS 10? And which reproduce on iOS 9?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

As far as I can tell, all of the symptoms have been in both iOS 9 and 10 except for the persistent gray WiFi icon, which is iOS 10 only.

I don’t know of any systematic problem with NWUDPSession but there’s clearly something going on here that I don’t understand. I’m going to ask you to open a DTS tech support incident so that I can look at this in detail.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"