I'm trying to implement the background mode for VoIP application using the new mechanisms provided by iPhone OS 4.x
Still without success... Application remains silent in the background mode when some data arrives from the server via TCP socket.
According to the documentation the following two things have to be done:
- Add "voip" value for "Required background modes" in Info.plst file
- Set property "kCFStreamNetworkServiceType" of CFReadStreamRef object to "kCFStreamNetworkServiceTypeVoIP" value
I'm using an externally created BSD socket to instantiate CFReadStreamRef with CFStreamCreatePairWithSocket function. Socket handle is correct - checked with some testing. So I'm obtaining a correct CFReadStreamRef object, which I'm later configuring and opening.
Here is the chunk of code:
CFSocketNativeHandle socket = (CFSocketNativeHandle)socketHandle;
CFStreamCreatePairWithSocket(kCFAllocatorDefault, socket, &sipSocketReadStream, nil);
CFReadStreamSetProperty(sipSocketReadStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
NSInputStream *inputStream = (NSInputStream*)sipSocketReadStream;
[inputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
CFReadStreamOpen(sipSocketReadStream);
Please note - my delegate for NSInputStream receives successfully "Stream Opened" event. But any other events simply didn't come - I was expecting to receive an event when some TCP traffic started to arrive.
Please help me to resolve this problem.
Thanks!