As noted here, https://developer.apple.com/forums/thread/116799 the Network framework probably won't have a connection available when running in the background.
We've been using the BGTask for a couple years now to start a URLSession and pull data from a web server. It works very nicely and reliably.
Do we have any options if we want to connect to another iPad, though? I ran a test and even if I have a "server" iPad running a Network framework listener (NWListener), and the app is in the foreground and the screen on, a "client" iPad (NWBrowser) cannot connect to the NWListener when trying to connect from the BGTask; it gives a DefunctConnection error.
Why does the Network framework not have the network available to it, but a URLSession does?
Is this a limitation of the iPad, or the Network framework? If I had an iPad running as a web server like this project,
https://github.com/swisspol/GCDWebServer
and an iPad client tries to connect a URLSession to it, would that work?
If this is an iPad limitation, could I use a MacBook on the network as a web server and connect to that instead?
UPDATE: If I run a web server on another iPad using Telegraph as described here, https://github.com/Building42/Telegraph the BGTask is able to connect to that iPad and run a URLSession to download from it. (The iPad acting as a web server does need to be on with the server app running; the iPad can't be turned off and the app can't be in the background, so it's not like a true server in that regard.) That tells me that the Network framework doesn't have network access like URLSession does.