简体   繁体   English

如何在iOS中与SIP服务器连接以进行VoIP通话?

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

I would like to connect with SIP server for SIP handshake. 我想与SIP服务器连接以进行SIP握手。 Could any one help me on how to implement the same in iOS. 谁能帮我在iOS中实现相同的功能。 How should we do it. 我们应该怎么做。 Should it be done through TCP protocol or can it be done through NSURLSession ? 应该通过TCP协议完成还是可以通过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? 我们如何将请求或参数传递到SIP服务器? Is it through header or XML? 是通过标头还是XML? Any help on this? 有什么帮助吗?

I shall recommend building you app on top an SIP SDK that can be found on the net. 我建议您在网上可以找到的SIP SDK之上构建您的应用程序。 Prefer to use the TCP as the transport protocol for the SIP Signaling message because - Apple like Connection oriented protocols. 首选使用TCP作为SIP信令消息的传输协议,因为-Apple类似于面向连接的协议。 As you start getting deeper it should help you better to understand why it makes sense. 随着您开始更深入,它应该可以帮助您更好地理解它为什么有意义。

NSURLSession is mechanisms to perform URL requests. NSURLSession是执行URL请求的机制。 The SIP signaling is a Protocol packet containing session creation and maintenance information. SIP信令是一个包含会话创建和维护信息的协议数据包。 So i haven't seen any particular use for this for SIP. 因此,对于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): 正如Rajesh在回答中提到的那样,iOS上必须强制使用TCP(或TLS)以允许在后台接收数据:您的应用程序在进入后台时将被挂起,但系统将密切注意TCP连接并唤醒您的应用程序当套接字上发生某些事情可以让您处理事件(通常是传入呼叫)时:

In order to ask the system to wake up your app, you have to configure the socket for such VoIP usage: 为了要求系统唤醒您的应用程序,您必须配置用于此类VoIP使用的套接字:

With C code, you can do this: 使用C代码,您可以执行以下操作:

//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) 注意:您的应用程序当然必须是“ IP语音”应用程序(“背景模式”设置)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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