Background TCP socket (iOS)

Hello,


I want to create a TCP sockets, which runs also in background. For example if the dispaly is switched off.

Currently my socket will be instantly closed, if display is off (same if I minimize the app).


What possibilities we have to create this special socket on iOS?


My background: I built a special VoIP app, which holds all the time a connection to the server.

There is a heartbeat mechanism which checks cyclic the connection between client and server.


Many thanks in advance!

Accepted Reply

Is it possible to use PushKit in closed networks?

Not if the network is completely closed. However, it doesn’t take much to open the network up enough for devices to open the outgoing connection required to make push notifications work, and that’s by far the easier best to this problem.

If not, what is an alternative for PushKit?

There aren’t any good alternatives. My advice, as stated in QA1938, is to contact DTS officially and discuss this with the DTS engineer who’s taken the lead on VoIP issues (which, for once, is not me :-).

Please make sure to reference this DevForums thread in your support request.

Share and Enjoy

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

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

Replies

It’s perfectly feasible to run a TCP connection in the background, you just have to prevent your app from being suspended. Technote 2277 Networking and Multitasking describes the rules of the road here.

You wrote:

I built a special VoIP app, which holds all the time a connection to the server.

There’s no good way to do this on iOS. Historically the legacy VoIP API used to work this way, but that mechanism has long since been deprecated (and for good reason; it never worked reliably). Modern VoIP apps have migrated to PushKit, and that’s what I’d recommend you do here.

Share and Enjoy

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

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

Many thanks for your fast reply!


"Modern VoIP apps have migrated to PushKit, and that’s what I’d recommend you do here."

Is it possible to use PushKit in closed networks? If not, what is an alternative for PushKit?

Is it possible to use PushKit in closed networks?

Not if the network is completely closed. However, it doesn’t take much to open the network up enough for devices to open the outgoing connection required to make push notifications work, and that’s by far the easier best to this problem.

If not, what is an alternative for PushKit?

There aren’t any good alternatives. My advice, as stated in QA1938, is to contact DTS officially and discuss this with the DTS engineer who’s taken the lead on VoIP issues (which, for once, is not me :-).

Please make sure to reference this DevForums thread in your support request.

Share and Enjoy

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

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

Okay, many thanks for answers.


"However, it doesn’t take much to open the network up enough for devices to open the outgoing connection required to make push notifications work, and that’s by far the easier best to this problem."


Could you say me which protocols or ports I need for this use case?


Exist for PushKit a WWDC video or something else?

Could you say me which protocols or ports I need for this use case?

This is documented by Apple Support in this article.

Exist for PushKit a WWDC video or something else?

It was introduced in WWDC 2014 Session 712 Writing Energy Efficient Code, Part 2. Honestly though, the API is pretty simple, and is reasonably well covered by the official PushKit docs.

One significant change in iOS 13 beta is that the system now requires that apps using PushKit generate a CallKit call for every push notification they receive. This is a new change, and one that I’m not really up to speed on (did I mention that I’m not DTS’s VoIP specialist? :-). The announcement was in WWDC 2019 Session 707 Advances in App Background Execution but you can find more info in this thread.

Share and Enjoy

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

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

"It was introduced in WWDC 2014 Session 712 Writing Energy Efficient Code, Part 2"

Sorry, but this link doesn't work.


"The announcement was in WWDC 2019 Session 707 Advances in App Background Execution but you can find more info in this thread."

Thanks a lot!

this link doesn't work.

Indeed. Sorry about the bogus link. The Powers That Be™ have decided that the world would be a better place if we removed old WWDC videos. On the plus side, the PushKit docs are in good shape.

Share and Enjoy

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

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