Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于iOS的PJSIP-无法确定在用于iOS的pjsua应用程序中如何发送命令_Ios_Pjsip - Fatal编程技术网

用于iOS的PJSIP-无法确定在用于iOS的pjsua应用程序中如何发送命令

用于iOS的PJSIP-无法确定在用于iOS的pjsua应用程序中如何发送命令,ios,pjsip,Ios,Pjsip,我已经按照这一点编译了pjsip,当我为iPhone运行pjsip示例应用程序ipjsua时,一切都很好。 现在的问题是,我无法理解命令是如何发送的。我的意思是,当我在命令文本字段中键入某个文本时,有人正在听我在那里写的内容,然后执行它。这是谁?它在ipjsua应用程序代码中的位置 在我的应用程序中,我将没有该文本字段来编写命令。我将有一个联系人列表,在选择联系人时,我将拨打sip电话 哪个pjsip函数用于执行命令,哪个函数(事件、委托)用于侦听sip服务器的响应?好的,我找到了解决方案 ip

我已经按照这一点编译了pjsip,当我为iPhone运行pjsip示例应用程序ipjsua时,一切都很好。 现在的问题是,我无法理解命令是如何发送的。我的意思是,当我在命令文本字段中键入某个文本时,有人正在听我在那里写的内容,然后执行它。这是谁?它在ipjsua应用程序代码中的位置

在我的应用程序中,我将没有该文本字段来编写命令。我将有一个联系人列表,在选择联系人时,我将拨打sip电话


哪个pjsip函数用于执行命令,哪个函数(事件、委托)用于侦听sip服务器的响应?

好的,我找到了解决方案

ipjsua应用程序向sip服务器发送命令的位置位于ipjsuaAppDelegate.m文件中的
char*getInput(char*s,intn,FILE*stream)
函数中

char*getInput(char*s,intn,FILE*stream)

正在读取config.cfg文件及其内容,并将其发送到sip服务器执行。在此文件中,您可以设置帐户配置、媒体配置。。。(有关此链接的更多信息)

读取config.cfg文件后,这段代码

while (!thread_quit && !app.mainView.hasInput)
{
    int ctr = 0;
    [NSThread sleepForTimeInterval:SLEEP_INTERVAL];
    if (ctr == 4)
    {
      [app performSelectorOnMainThread:@selector(displayMsg:) withObject:mstr waitUntilDone:YES];
        [mstr setString:@""];
        ctr = 0;
    }
    ctr++;
}
正在运行并等待来自应用程序的更多命令输入。要触发此while循环以继续执行,必须将app.mainView.hasInput设置为true。 当您要发送某些命令时:

  • 首先,将命令文本放入此变量
    app.mainView.text
  • 其次,设置
    app.mainview.hasInput=true
当然,您可以在ipjsuaAppDelegate类中将这些变量设为私有变量。重要的事实是,
而(!thread\u quit&&!app.mainView.hasInput)
包含的是
app.mainView.hasInput
您的局部变量
hasInput

发送命令后,执行这段代码(在
char*getInput(char*s,intn,FILE*stream)
函数中)

然后,执行pjsua_app.c文件中的相应代码,然后再次调用函数
char*getInput(char*s,intn,file*stream)
,执行while循环(
while(!thread_quit&!app.mainView.hasInput)
)并等待另一个输入。 因此,如果需要执行两个或多个连续命令,您可以在这里使用while循环执行前一刻发送另一个命令(例如:为了进行调用,您必须发送'm',在发送sip uri后调用'sip:account@example.com'这是两个连续的命令)

在我的应用程序中,它看起来像这样

char * getInput(char *s, int n, FILE *stream)
{
    if (stream != stdin)
    {
        return fgets(s, n, stream);
    }

    [appDelegate performSelectorOnMainThread:@selector(actionAfterCommand) withObject:nil waitUntilDone:NO];   

    app.mainView.hasInput = false;
    [app.mainView.textField setEnabled: true];
    [app performSelectorOnMainThread:@selector(displayMsg:) withObject:mstr waitUntilDone:YES];
    [mstr setString:@""];

    while (!thread_quit && !app.mainView.hasInput)
    {
        int ctr = 0;
        [NSThread sleepForTimeInterval:SLEEP_INTERVAL];
        if (ctr == 4)
        {
            [app performSelectorOnMainThread:@selector(displayMsg:) withObject:mstr waitUntilDone:YES];
            [mstr setString:@""];
            ctr = 0;
        }

        ctr++;
    }

    [app.mainView.text getCString:s maxLength:n encoding:NSASCIIStringEncoding];
    [app.mainView.textField setEnabled: false];    
    [app performSelectorOnMainThread:@selector(displayMsg:) withObject:app.mainView.text waitUntilDone:NO];

    return s;
}
和选择器
actionAfterCommand

- (void)actionAfterCommand
{
    [NSThread sleepForTimeInterval:1.0];//this is just to be sure that sip server is ready to listen agin

    if ([app.mainView.text isEqualToString:command])// command can be m, a, ...
    {
        app.mainView.text = secondCommand;
        appDelegate.hasInput = true;
    }
}
另外,如果有人有其他方法解决这个问题,请添加到这里

char * getInput(char *s, int n, FILE *stream)
{
    if (stream != stdin)
    {
        return fgets(s, n, stream);
    }

    [appDelegate performSelectorOnMainThread:@selector(actionAfterCommand) withObject:nil waitUntilDone:NO];   

    app.mainView.hasInput = false;
    [app.mainView.textField setEnabled: true];
    [app performSelectorOnMainThread:@selector(displayMsg:) withObject:mstr waitUntilDone:YES];
    [mstr setString:@""];

    while (!thread_quit && !app.mainView.hasInput)
    {
        int ctr = 0;
        [NSThread sleepForTimeInterval:SLEEP_INTERVAL];
        if (ctr == 4)
        {
            [app performSelectorOnMainThread:@selector(displayMsg:) withObject:mstr waitUntilDone:YES];
            [mstr setString:@""];
            ctr = 0;
        }

        ctr++;
    }

    [app.mainView.text getCString:s maxLength:n encoding:NSASCIIStringEncoding];
    [app.mainView.textField setEnabled: false];    
    [app performSelectorOnMainThread:@selector(displayMsg:) withObject:app.mainView.text waitUntilDone:NO];

    return s;
}
- (void)actionAfterCommand
{
    [NSThread sleepForTimeInterval:1.0];//this is just to be sure that sip server is ready to listen agin

    if ([app.mainView.text isEqualToString:command])// command can be m, a, ...
    {
        app.mainView.text = secondCommand;
        appDelegate.hasInput = true;
    }
}