[iOS] Keep TCP connection alive in the background


For the iOS (even better, swift!) devs out there, how do you keep the connection from your app to IF’s tcp channel alive whilst your app is in the background?

My app stops receiving events as soon as it goes in the background :/

I looked at things like VoIP capabilities, but I doubt Apple would approve the use case?


@epaga would be the expert here :)

A blank noise works, but Apple will reject it if it doesn’t do anything useful with it. For John’s apps, I think he solved this by adding the option to play music from the Music app. Strange fix… but it works!

I’ve been playing with waking up the app using push notifications, which gives a very small amount of time to connect and send a command (some covid-19 trackers do it this way, the UK one does that)

Last way I can think of is to just use multitasking, but that only works on iPad and covers the screen.


Thanks. @epaga any pointer would be much appreciated, thanks :)

Yep, Cameron is absolutely right: keeping an audio running that plays a blank noise on loop works. Because my one app is an audio background app anyways, this was allowed.

The other app wasn’t, so was blocked until I added the option to play music. :-/

Thanks very much. That’s the route I’m going to follow then. Already figured I’d need to pretend the app allowed to play music for this to work :)

Ok so udp greeting and tcp connection are working in the background, yeah! Now I’m having a hard time understanding the format of what needs to be sent to the api…

Looking at Cam’s source code it looks like byte arrays?

I’m struggling to come up with swift’s equivalent to C#'s GetBytes ^^

Hi …

Not sure if you made any progress on this. Are you using the v1 or v2 Connect API? They require quite a different communication protocol – both with byte arrays.

I’ve worked with v1 in Node JS – I can point you at some libraries in Node that might help.

I am working on an iOS app in Swift right now using the v2 api and will soon release a simple class/library in GitHub for managing simple transactions with the v2 API from Swift.