Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用PJSIP取消SIP注册_Iphone_Ios_Ipad_Sip_Pjsip - Fatal编程技术网

Iphone 使用PJSIP取消SIP注册

Iphone 使用PJSIP取消SIP注册,iphone,ios,ipad,sip,pjsip,Iphone,Ios,Ipad,Sip,Pjsip,在我们的应用程序中,当用户将应用程序推到后台时,我们需要对其进行取消注册。 我们正在使用PJSIP。我的应用程序标识符背景: - (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"did enter background"); __block UIBackgroundTaskIdentifier bgTask; bgTask = [application begi

在我们的应用程序中,当用户将应用程序推到后台时,我们需要对其进行取消注册。 我们正在使用PJSIP。我的应用程序标识符背景:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"did enter background");


     __block UIBackgroundTaskIdentifier bgTask;

     bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];


    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self deregis];        
        [application endBackgroundTask: bgTask]; //End the task so the system knows that you are done with what you need to perform
        bgTask = UIBackgroundTaskInvalid; //Invalidate the background_task
        NSLog(@"\n\nRunning in the background!\n\n");

    });
     }
deregis方法如下所示:

- (void)deregis {
    if (!pj_thread_is_registered())
    {
        pj_thread_register("ipjsua", a_thread_desc, &a_thread);
   }    
    dereg();

}
void dereg()
{
    int i;
    for (i=0; i<(int)pjsua_acc_get_count(); ++i) {
        if (!pjsua_acc_is_valid(i))
             pjsua_buddy_del(i);

        pjsua_acc_set_registration(i, PJ_FALSE);
    }
}
而de reg方法如下所示:

- (void)deregis {
    if (!pj_thread_is_registered())
    {
        pj_thread_register("ipjsua", a_thread_desc, &a_thread);
   }    
    dereg();

}
void dereg()
{
    int i;
    for (i=0; i<(int)pjsua_acc_get_count(); ++i) {
        if (!pjsua_acc_is_valid(i))
             pjsua_buddy_del(i);

        pjsua_acc_set_registration(i, PJ_FALSE);
    }
}
void dereg()
{
int i;

对于(i=0;i您不想在后台线程中结束后台任务:

e、 g

您希望在更新注册时结束后台任务,因此需要挂接到pjsua on_reg_状态回调

e、 g.此示例可能仅假设一个注销,对于多个帐户,您必须等待所有帐户都注销

-(void) regStateChanged: (bool)unregistered {
    if (unregistered && bgTask != UIBackgroundTaskInvalid) {
        [application endBackgroundTask: bgTask]; //End the task so the system knows that you are done with what you need to perform
        bgTask = UIBackgroundTaskInvalid; //Invalidate the background_task
    }
}