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.
UIBackgroundModes
asvoip
? If not so, iOS won't allow a wakeup due to incomming packets. – Matthias