Flutter : keep socket io open while app in background (IOS)

Viewed 2763

I'm building app that uses flutter_pllayout and adhara_socket_io

App Scenario

When app is launched, it connect to a socket and keep receiving audio urls at random times, then it plays this url, it works fine on android

Problem

but in iOS when user switch to home or any other app (when my app is in background) it seems to close the connection of the socket and continue when app become in foreground, is there any way to keep the socket connection open ?

1 Answers

Background tasks on iOS are very limited. Only works if you play audio constantly with the correct Info.plist details.

If you want recurrent (cron job task) client side, use: BGTaskScheduler (for iOS), one other option is using a cron job triggered push notification task (you can even user Firebase Functions for that) server side.

Official docs: BFTaskScheduler, Background Behavior iOS, Enabling Background Audio

and no, sockets connections can't keep opened all the time (not even on Android on latest versions of their OS). Again, use cron job tasks to achieve a similar behavior.

Officials docs: Android Background limitations

Related