2011-09-22 4 views
0

우리 앱에서 앱을 배경으로 푸시하면 사용자 등록을 취소해야합니다. PJSIP을 사용하고 있습니다. 내 applicationDidEnterBackground :와 :PJSIP를 사용한 SIP 등록 취소

- (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); 
    } 
} 

우리는 배경에 응용 프로그램을 누르면, dereg가 호출됩니다. 그러나 서버가 401 챌린지를 다시 보내면 응용 프로그램을 다시 포 그라운드로 가져올 때까지 스택이 SIP 통화의 인증 세부 정보를 다시 보내지 않습니다. 왜 이런 일이 일어나는 지 아는 사람이 있습니까?

감사합니다, Hetal

답변

1

당신은 백그라운드 스레드에서 백그라운드 작업 종료하고 싶지 않은 :

예를

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    [self deregis];   
    // don't do below... 
    // [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"); 

}); 

등록이 업데이트되면 백그라운드 작업을 종료하고 싶습니다. 따라서 pjsua on_reg_state 콜백에 연결해야합니다.

이 예에서는 하나의 계정을 등록 취소한다고 가정 할 수 있습니다. 여러 계정의 경우 모두 등록이 끝날 때까지 기다려야합니다.

-(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 
    } 
} 
관련 문제