user366584
user366584

Reputation: 1056

Unable to keep Websocket alive in background iOS

I am creating a VOIP application and also using a SocketRocket library to manage my Websockets and pull data from it. But my main problem is when I click on (IOS) Home button so my websocket disconnects after one minute. I have read Apple's documentation for developing VOIP application from the link below

https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html

I am also setting UIBackgroundModes in plist for VOIP and Audio, but when I resume my application so my websocket state is closed although I am not releasing websocket Object.

_webSocket.readyState = 3    //  It identifies that my websocket is close.

Now for restablishing a connection with Websocket so I need to call again websocket open and create another instance of Websocket object after releasing previously.

On closing of websocket my SIP registeration from my server also disconnects and I need to reconnect to my SIP again.

How can I prevent my websocket to get close and how can I make setKeepAliveTimeout:handler: useful to fix my problem.

Library use to establish Websocket is as below

https://github.com/square/SocketRocket

Upvotes: 6

Views: 3726

Answers (1)

Nailer
Nailer

Reputation: 2426

Try adding the following two lines in SRWebSocket _initializeStreams

// Setup connections to be VOIP connections
CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);

Upvotes: 3

Related Questions