开发者

Will a BSD UDP Socket work with iOS's VoIP Background Mode?

I can't get it to work, but that doesn't mean it is not possible.

I've seen other people say that I need to use a TCP Port, but does anyone have any pointers to any kind of official documentation that woul开发者_JS百科d have the final say?


Yes, that's the point.

But in iOS 4.2.1 (for example) you can receive in UDP while in background WITHOUT any ack. Just declaring a CFReadStream as a VoIP socket listening in applicationDidEnterBackground... From iOS 4.3 and above that method doesn't work anymore.

Also Media5 uses a "trick" to keep active the app, thus receiving incoming calls in background also with UDP.


There wil be possibly no such clear documentations from Apple sounding like "UDP on background is not possible".

But the fact is that the official documentation states to use one of these interface to perform background networking : - NSInputStream and NSOutputStream - NSURLRequest - CFReadStreamRef and CFWriteStreamRef

This said, i believe the stream concept can't wrap a non connected UDP mode socket. http://lists.apple.com/archives/cocoa-dev/2010/Jul/msg00091.html

So you could understand it like Apple only allowing "streams" of data to be open in background mode and not UDP sockets.

I actually don't know how Counterpath's Bria managed to perform their UDP backgrounding, but the hypothesis is that they have some kind of hack to execute code in background instead of marking a special socket as "to be maintained living"


From my tests, UDP backgrounding is not more possible with iOS >= 4.3.


Does this trick consist of playing a silent sound when switching to background ? Because i think it didn't work anymore...


For current version iOS only allow TCP socket with VOIP property in background mode.

readStream=NULL; writeStream=NULL;

    CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)serverIP, Port, &readStream, &writeStream);

    CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP); //VOIP property for input stream
    CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);

    inputStream = (__bridge NSInputStream *)readStream;
    outputStream = (__bridge NSOutputStream *)writeStream;
    [inputStream setDelegate:self];
    [outputStream setDelegate:self];

    [inputStream setProperty:NSStreamNetworkServiceTypeVoIP forKey:NSStreamNetworkServiceType] ;
    [outputStream  setProperty:NSStreamNetworkServiceTypeVoIP forKey:NSStreamNetworkServiceType] ;

    [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [inputStream open];
    [outputStream open];

This will create simple tcp connection with server and socket type is VOIP. Then you must add application background mode in property list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜