Socket.io-client-swift: Using socket.io in a background task

Created on 20 Aug 2015  ·  11Comments  ·  Source: socketio/socket.io-client-swift

Hi,

Any example of a possible usage of socket.io in a background task? (when the iOS app isn't in the foreground)

I'm looking for a way to keep sending data to the server even if the screen is locked/the user moved into another app.

Thanks

question

Most helpful comment

@meismyles please tell whether you were able to connect socket in background or not,
if yes,then please help us too.
Thanks

All 11 comments

I'm not sure if that's possible. iOS multitasking is pretty restrictive.

Sent from my iPhone

On Aug 20, 2015, at 4:41 AM, mp3il [email protected] wrote:

Hi,

Any example of a possible usage of socket.io in a background task? (when the iOS app isn't in the foreground)

I'm looking for a way to keep sending data to the server even if the screen is locked/the user moved into another app.

Thanks


Reply to this email directly or view it on GitHub.

@nuclearace Is it restrictive as in not allowing WebSockets at all (afaik it seems to allow low-level TCP socket connection only?) or as in only allowing when the intention is sound like being used for signaling channel for voip functionality?

I haven't really looked into it, since I wrote this library to be platform independent. But I think it has to with it only allowing VoIP connections in the background.

They actually expanded the scope of applications allowed to communicate in the background.
Now allow apps if they fall into a number of categories such as playing audio, location updates (navigation), VoIP, Newsstand, background fetch, remote notifications, etc.

See: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

Yeah, but I actually have no idea how to properly do it with this library. (If it's even possible)

Oh yeah, I was just letting the OP know that it is now theoretically allowed, not that it is possible with this library. I'll potentially be attempting it soon so I'll report back if I have any success.

Woops, forgot to reply. I implemented this client recently in an iOS app that plays audio and setting my applications background mode to audio kept the socket open and connected when the app was in the background. So it should work fine.

@meismyles , I am also going through the same issue, but when I activated Audio and VoIP background modes (and marked the socket.io client as voip = true while initializing) the connected socket is giving me the log as

2016-03-30 12:11:12.213 GSLVideoCallApp[3318:1287745] LOG SocketEngine: Writing ws: has data: 0
2016-03-30 12:11:12.214 GSLVideoCallApp[3318:1287745] LOG SocketEngine: Sending ws: as type: 2
2016-03-30 12:11:12.218 GSLVideoCallApp[3318:1287744] ERROR SocketEngine: connection closed by server

When I am switching the app to background and 2-3 minutes after locking the phone.
Is there something wrong I am doing or missing something.

@meismyles please tell whether you were able to connect socket in background or not,
if yes,then please help us too.
Thanks

Has anybody solved this problem?

Any update or workaround sample?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leeyuno picture leeyuno  ·  5Comments

gaetanm picture gaetanm  ·  4Comments

Seonift picture Seonift  ·  4Comments

roma86 picture roma86  ·  4Comments

huangxiaolin0425 picture huangxiaolin0425  ·  6Comments