具有后台模式和来电通知的SIP应用程序

时间:2014-04-23 13:39:31

标签: ios objective-c sip voip

我正在开发一个SIP Calling应用。我使用siphon app project来实现开源pjsip library。我能够在前台模式下成功运行Application,对于Device和Simulator。

为了在VOIP的后台模式下运行应用程序,我正在关注此RayWenderlich Tutorial。 根据{{​​3}},我们必须遵循以下4个步骤:

  1. 从Xcode项目的“功能”选项卡的“后台模式”部分启用对IP语音的支持。 (您也可以通过在应用的Info.plist文件中包含带有voip值的UIBackgroundModes键来启用此支持。)
  2. 为VoIP使用配置其中一个应用的套接字
  3. 在移至后台之前,请调用-setKeepAliveTimeout:handler:方法安装要定期执行的处理程序。您的应用可以使用此处理程序来维护其服务连接。
  4. 配置音频会话以处理与活动使用之间的转换。
  5. 我已经实施了第一步:

    enter image description here

    但我不知道如何实施接下来的三个步骤以便在后台模式下接收SIP呼叫。得到了这三个步骤背后的逻辑,但没有找到任何实现的源代码。

    以前有人有过这方面的工作吗?

2 个答案:

答案 0 :(得分:1)

这里也是我用过的虹吸项目的例子。 如果您修改此项目,则可以在- (void)processCallState:(NSNotification *)notification回调中执行所需的所有其他操作。

- (void)keepAlive {
    /* Register this thread if not yet */
    if (!pj_thread_is_registered()) {
        static pj_thread_desc   thread_desc;
        static pj_thread_t     *thread;
        pj_thread_register("ipjsua", thread_desc, &thread);
    }
    pjsua_acc_set_registration(0, PJ_TRUE);
    NSLog(@"Keep Alive");
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /* Send keep alive manually at the beginning of background */
    [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];

    /* iOS requires that the minimum keep alive interval is 600s */
    [application setKeepAliveTimeout:600 handler: ^{
        [self performSelectorOnMainThread:@selector(keepAlive)
                               withObject:nil waitUntilDone:YES];
    }];
}

不要忘记将虹吸设置中的keepAlive间隔设置为600。

答案 1 :(得分:0)

步骤2& pjsip本身就为你完成了4个,所以没什么可以做的。

步骤3是您需要实施的唯一步骤。步骤3是必需的,因为在后台模式下,没有IOS定时器会触发,因此sip重新注册永远不会发生。所以你需要设置ios" special"后台计时器回拨到pjsip说请注册sip ragistar。因此,您将保持活动超时设置为小于重新注册时间的值。

步骤3的示例可以在pjsip示例pjsua应用程序中找到,您也应该能够在虹吸应用程序中找到它。

通常,您会在applicationDidEnterBackground回调中的app delegate类中添加支持。请参阅pjsua了解example

确保您使用的是tcp连接,因为udp无法在后台运行。

相关问题