几个小时后,在后台运行的VOIP应用程序停止运行

时间:2014-02-12 11:45:40

标签: ios ios7 voip pjsip

我们使用PJSIP创建了一个VOIP应用程序,并实现了后台运行,可以正常运行几个小时。之后它停止工作(它不再接收电话)。

还有其他人有这个问题吗?我相信它只适用于ios7

PJSIP TCP套接字标记为VOIP

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


    [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
    [application setKeepAliveTimeout:600 handler: ^{
        [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
    }];

}

- (void)keepAlive {
    int i, timeout = KEEP_ALIVE_INTERVAL;

    if (!pj_thread_is_registered())
    {
        pj_thread_register("ipjsua", a_thread_desc, &a_thread);
    }

    for (i = 0; i < (int)pjsua_acc_get_count(); ++i) {
        if (pjsua_acc_is_valid(i)) {
            pjsua_acc_config acc_cfg;

            pjsua_acc_get_config(i, &acc_cfg);
            if (!acc_cfg.reg_uri.slen)
                continue;
            if (acc_cfg.reg_timeout < timeout) {
                acc_cfg.reg_timeout = timeout;
                pjsua_acc_modify(i, &acc_cfg);
            } else {
                pjsua_acc_set_registration(i, PJ_TRUE);
            }
        }
    }
}

0 个答案:

没有答案