nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

SocketIO automatically disconnects automatically when phone locked - Swift #91

Closed iulianmargeloiu closed 8 years ago

iulianmargeloiu commented 8 years ago

Hi guys,

I have a very strange issue with SocketIO. I need to get socket events in background, even phone is locked, or app is background.

But currently after 1-2 minutes, after I locked the phone, I got message: "socket disconnected"

Anyone can help with this? What solutions I have?

Thanks in advance

nuclearace commented 8 years ago

This is probably related to the fact that iOS does not let you do background execution unless you specify one of the background execution modes. Most of which won't apply to socketio

iulianmargeloiu commented 8 years ago

Hi, thanks for very quick response.

I already have background execution mode enabled. I am using 'audio' one, and is playing perfectly on background or if phone is locked.

nuclearace commented 8 years ago

Does it happen when the audio stops? iirc the app can get suspended if the audio stops.

I'm not that experienced with iOS development so my knowledge on this subject is limited.

nuclearace commented 8 years ago

Also see https://github.com/socketio/socket.io-client-swift/issues/146

iulianmargeloiu commented 8 years ago

Many thanks...

I already did the same, and seems it is fine.. but still there are some strange situations when socket disconnects again - eg: incoming call...

Thanks a lot

aniketc-gslab commented 8 years ago

@bubblebytes, 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.

podilivinay commented 7 years ago

@bubblebytes, You better to use push notifications when you are using socketio. We can't keep application in background mode, iOS will not allow your own background services unless you use specified background capabilities like Audio, Voip, location services. That too each background capability has their own kind of execution.