Franz van der Steg
Franz van der Steg

Reputation: 273

iOS Unable to "Configure one of the app’s sockets for VoIP usage" for background mode

I am trying to set up my app to listen to a tcp-socket even when the app is suspended. I set the voip-background mode in the Info.plist as described in the apple documentation. Now I am stuck where is says: "Configure one of the app’s sockets for VoIP usage.". I am trying to do this with the CFReadStreamSetProperty() methods but the point is how I create the sockets. The creation of the socket is done via the standard C-Library like this:

int mySock = socket(AF_INET, SOCK_STREAM, 0);

This is done inside a .cpp file within an existing library. This is what I have tried to configure the socket for VoIP usage:

CFStreamCreatePairWithSocket(kCFAllocatorDefault, sock, &readStream, &writeStream);
if(readStream && writeStream)
{
   CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
   CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
}

When I step through it it is looking good but unfortunately it does not work. Whenever the app is going from foreground to background/suspended the connection gets lost and any input from the server is ignored. I have no clue if the configuration of the socket can be done like this at all and can not find an answer to it.

Upvotes: 1

Views: 1558

Answers (2)

TheSquad
TheSquad

Reputation: 7506

Are you using an iPhone 5S or 5C ?

Try using some device like iPhone 5 or iPad 2

There is a known issue with theses devices (maybe iPad Air, can't confirm...) concerning VOIP sockets, a bug report has been reported, we are still awaiting for Apple to fix it...

Upvotes: 0

Somu
Somu

Reputation: 11

This is my first post in this forum. But I found this is working.

  1. Set VOIP in info.plist file
  2. CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);

    CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);

  3. Use TCP sockets

It didn't work for UDP socket. If I am wrong, please edit this post.

Upvotes: 1

Related Questions