2016-11-17 100 views
0

我正在使用此代码为我的VOIP应用程序启用后台模式。当应用程序在后台时无法获得呼叫

- (void)applicationDidEnterBackground:(UIApplication *)application{ 

[NSTimer timerWithTimeInterval:60.0 target:self selector:@selector(sipRegisterEveryTime) userInfo:nil repeats:YES]; 
[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);} 

但我没有得到我的应用程序,如果任何VOIP呼叫到达,而我的应用程序在后台清醒。通过在“所需的背景模式”中设置“应用程序提供IP服务语音”,可启用VOIP背景的info.plist设置。VOIP内部功能设置已完成。还有什么我需要做的吗?我正在为我的VOIP应用程序使用PJSIP库。

+0

检查传输使用TCP协议,它是唯一一个会在后台工作。 – azimov

回答

相关问题