SocketRocket icon indicating copy to clipboard operation
SocketRocket copied to clipboard

messages not received from socket rocket when app is in background

Open ambercool99 opened this issue 8 years ago • 9 comments

Device: iPhone 6S iOS : 9.3.5 Socket Rocket version: 0.5.0 Steps:

  1. Server sends multiple messages on Socket connection when app is in Background. (through socket rocket i have created a VOIP socket)
  2. Messages are not received by socket rocket (though application is active in background as background task was running).
  3. Move the application to foreground and on trying to send a message out .

Observed that all messages which were sent by server previously are getting received now.

Expected: Messages should be received whenever it is sent by server.

ambercool99 avatar Oct 03 '16 12:10 ambercool99

Any updates for this?

Viktorianec avatar Oct 21 '16 12:10 Viktorianec

This is generally not a reasonable expectation for socket clients; you will need to use a VOIP socket (now-deprecated so not linking) to accomplish this at all, and even still will lose access to the socket after 3m in the background.

You can get around these limitations with some kludges; such techniques however will not pass Apple's review process.

anulman avatar Oct 24 '16 22:10 anulman

we have already marked it as VOIP socket and app is active in background in this case. If you are using socket rocket for VOIP application and consider a case incoming call this is expected.

AshokPitambar avatar Oct 27 '16 13:10 AshokPitambar

@AshokPitambar I'm not sure what you're trying to say, or what a helpful answer looks like. Can you try being more specific re: what behavior you've observed vs. what you'd expect? Sample code would also be helpful if you're looking for support.

anulman avatar Oct 27 '16 16:10 anulman

@ambercool99 are you building your code with iOS SDK 9 or 10?

If you are using 10 (latest, default for xCode 8) then the behavior is as expected because Apple has removed the deprecated VOIP functionality completely from iOS 10. PushKit is the only way to go for building with iOS SDK 10.

madlymad avatar Dec 20 '16 06:12 madlymad

Experiencing same issue. any idea?

platform :ios, "7.0"

target 'WebsocketExampleClient' do
  use_frameworks!
  pod 'SocketRocket', '~> 0.4.2'
end

ashokseervidev avatar Apr 18 '17 08:04 ashokseervidev

messages not received from socket rocket when app is in background ? any one have solution for this issue.

anandt avatar Jun 13 '17 07:06 anandt

Solution: For Swift

In App Delegate:

Create variable:

`var backgroundUpdateTask: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid`

Create Method:

private func endBackgroundTask(){
        UIApplication.shared.endBackgroundTask(self.backgroundUpdateTask)
        self.backgroundUpdateTask = UIBackgroundTaskInvalid
    }

In applicationWillResignActive and WillEnterForeground Delegate:

func applicationWillResignActive(_ application: UIApplication) {
        self.backgroundUpdateTask = UIApplication.shared.beginBackgroundTask(expirationHandler: {
            self.endBackgroundTask()
            })
    }
func applicationWillEnterForeground(_ application: UIApplication) {
        self.endBackgroundTask()
    }

ghost avatar Jul 10 '18 21:07 ghost

I was going to say add backgroundTask but @tamimibnaman already explained. It should work. Since you have voip there shouldn't any problem.

Also, try to debug socket is closed or not when you send the app to background.

One more addition, I think it is best to terminate backgroundTask when the call ended not with application states if you have voip based app.

kutayinclr avatar Dec 11 '18 11:12 kutayinclr