我们在TCP模式下使用Pjsip并且已配置保持活动状态。应用程序在后台运行顺利但是在应用程序尝试重新注册SIP服务器注册消息已经发送并且应用程序没有得到响应的一段时间之后,应用程序在此时陷入困境,然后它将无法在后台运行。杀死之后就行了。你能告诉我们失踪的是什么吗?
有时候它的工作时间为3-4小时,有时甚至在5分钟内停止工作:(
当应用为后台时运行此代码:
- (void)applicationDidEnterBackground:(UIApplication *)application {
[self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
[application setKeepAliveTimeout:KEEP_ALIVE_INTERVAL handler: ^{
[self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
}];
}
- (void)keepAlive {
int i;
if (!pj_thread_is_registered()) {
pj_thread_register("ipjsua", a_thread_desc, &a_thread);
}
/* Since iOS requires that the minimum keep alive interval is 600s,
* application needs to make sure that the account's registration
* timeout is long enough.
*/
for (i = 0; i < (int)pjsua_acc_get_count(); ++i) {
if (pjsua_acc_is_valid(i)) {
pjsua_acc_set_registration(i, PJ_TRUE);
}
}
pj_thread_sleep(15000);
}