Socket in background state iOS

1.5k views Asked by At

Maybe someone ever solve the problem with stable connection to server when application is in background? I need to transfer audio data from server to client app. I know about all hacks for iOS how to keep alive application, but I need legal methods to solve this problem. Maybe you have any idea? I found that I can send VoIP push to device that will wakeup my app and then establish tcp connect to my server but this socket will be keep alive about 30 seconds (as I see in log, every 3 seconds fires timer in iOS app that send data to server) this is not enough for me.

1

There are 1 answers

0
Alex Makushkin On

Maybe this project https://github.com/SmallSharpToolsOpenSource/Speakerbox will be helpful for someone. And this video https://www.youtube.com/watch?v=lXJ1LDjL4Os

And official answer from Apple tech support:

PushKit is how voip apps can reliable receive silent notifications, while CallKit is basically a UI framework voip apps can use to notify the user about calls. Note that there is NOT any direct connection within the APIs- for example, a voip app can generate a local notification (instead of using CallKit) or simply do nothing and “ignore” the notification entirely. Similarly, a voip app could “fake” a call at anytime by simply telling CallKit that there was an incoming call (our sample code for CallKit did exactly this).

Anything your app could previously have done when it received voip socket traffic, it could also do when it received a PushKit notification.

Standard voip apps actually operate in two COMPETELY unrelated “modes”:

1) While waiting for an incoming call, the app is suspended until “something” (PushKit OR a voip socket) wakes the app to tell it about the call.

2) Once a call has started, the app has an active audio session and is relying an the standard “background audio” behavior of iOS, just like a wide variety of other audio apps (for example, any streaming music app).