Network.Framework background operation

I have a simple app that sends and receives data over WiFi using Network.Framework. It receives about 80 bytes every 10 seconds.

The issue comes when the user wants to leave the app runing and do something else, perhaps check their mail. As soon as the user selects the home button the app is put into the background and Network.Framework disconnects.


  1. How to I prevent the initial disconnection on entry in to background? and
  2. How do I enable support for the 80 bytes every 10 secondsthat are written to a file?


All wisdon gratefully accepted.

The rules of the road here are documented in Technote 2277 Networking and Multitasking. While that technote hasn’t been updated for Network framework, the basic situation is unchanged: If your app is suspended while in the background, it’s possible that your connections will be closed out from underneath you.

The only way to avoid this is to prevent your app from being suspended. You can use a

UIApplication
background task to do that for a short period of time (see my UIApplication Background Task Notes post for details). That should be enough time to cover the user switching out of and back in to your app.

If you need to keep your network connections alive indefinitely, that’s not possible given the iOS multitasking architecture.

Share and Enjoy

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

let myEmail = "eskimo" + "1" + "@apple.com"
Network.Framework background operation
 
 
Q