简体   繁体   中英

How to connect with SIP server for VoIP call in iOS?

I would like to connect with SIP server for SIP handshake. Could any one help me on how to implement the same in iOS. How should we do it. Should it be done through TCP protocol or can it be done through NSURLSession ? It would be really help full to provide some guidance on the same.

How do we post request or pass parameter to SIP server? Is it through header or XML? Any help on this?

I shall recommend building you app on top an SIP SDK that can be found on the net. Prefer to use the TCP as the transport protocol for the SIP Signaling message because - Apple like Connection oriented protocols. As you start getting deeper it should help you better to understand why it makes sense.

NSURLSession is mechanisms to perform URL requests. The SIP signaling is a Protocol packet containing session creation and maintenance information. So i haven't seen any particular use for this for SIP.

As Rajesh mentionned in his answer, TCP (or TLS) is mandatory on iOS to allow receiving data in background: your app will be suspended when it goes to background, but the system will keep an eye on the TCP connection and wake up your app when something happen on the socket to let you handle the event (usually, an incoming call):

In order to ask the system to wake up your app, you have to configure the socket for such VoIP usage:

With C code, you can do this:

//include required
#include <CoreFoundation/CFStream.h>
#include <CFNetwork/CFSocketStream.h>

//additionnal declaration
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;


//TODO: open your socket as usual
...

//Configure the socket 
CFStreamCreatePairWithSocket (kCFAllocatorDefault, socket, &readStream, &writeStream);
if (readStream != NULL)
        CFReadStreamSetProperty (readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
if (writeStream != NULL)
        CFWriteStreamSetProperty (writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
if (CFReadStreamOpen (readStream)) {
        //CFReadStreamOpen Succeeded
}
if (CFWriteStreamOpen (writeStream)) {
        //CFWriteStreamOpen Succeeded
}

//Now, if you go to background, your app will be woken up
...


//When you close the socket
if (readStream != NULL) {
  CFReadStreamClose (readStream);
  CFRelease (readStream);
}
if (writeStream != NULL) {
  CFWriteStreamClose (writeStream);
  CFRelease (writeStream);
}

NOTE: Your app must of course be a "Voice Over IP" app (Background Modes settings)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM