Keeping TCP connection alive when app enters background

Hi there, I have established a TCP connection using Apple's Network framework. It works fine when the app is running in foreground but the connection drops in background mode. I was trying to keep the connection alive in background mode using background fetch/BackgroundTasks but not getting a way to do so. Any help world be appreciated. Thanks!

Answered by DTS Engineer in 732000022

The issue here isn’t whether your app is in the background, it’s whether your app gets suspended while it’s in the background. If your app remains running in the background, it’s network connections continue to work.

So your question is equivalent to “How do I remain running in the background?” and that’s a complex issue. I usually start people who ask that question off by pointing them at my iOS Background Execution Limits post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

The issue here isn’t whether your app is in the background, it’s whether your app gets suspended while it’s in the background. If your app remains running in the background, it’s network connections continue to work.

So your question is equivalent to “How do I remain running in the background?” and that’s a complex issue. I usually start people who ask that question off by pointing them at my iOS Background Execution Limits post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Got it, thanks!

@ganaraj-savant did you find a solution and would you be willing to share it? I am trying to maintain a connection between an iOS device and tvOS. Thanks for any help.

Keeping TCP connection alive when app enters background
 
 
Q