1
votes

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.

2
Did you register your application with UIBackgroundModes as voip? If not so, iOS won't allow a wakeup due to incomming packets.Matthias
I am facing the same issue (using a posix socket for voip). Did you manage to get it working ?Paul Praet

2 Answers

1
votes

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.

0
votes

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...