2016-11-17 101 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

回答

相關問題