Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:39:30+00:00 2026-05-26T01:39:30+00:00

In our app, we need to de-reg a user when he pushes the app

  • 0

In our app, we need to de-reg a user when he pushes the app to the background.
We are using PJSIP. My applicationDidEnterBackground:

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

    });
     }

The deregis method is as below:

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

}

And the de-reg method is as below:

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

When we push the app to the background, the dereg gets called. But when the server sends back a 401 challenge, the stack isn’t sending back the auth details in SIP call until I bring the application back to foreground.
Does anyone have any idea why this is happening?

Thanks,
Hetal

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:39:31+00:00Added an answer on May 26, 2026 at 1:39 am

    You don’t want to end the background task in your background thread:

    e.g.

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

    You want to end the background task when the registration is updated. So you need to hook into the pjsua on_reg_state callback.

    e.g. this example may only assume one unregister, for multiple accounts you have to wait until all are unregistered

    -(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
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we are using the asp.net profiles provider in our app and I need to
We are using SVG in our web app and we need to allow users
In our app, we need to detect if the user is connected to VPN
I'm dealing with a standalone MQ JMS application, our app need to aware that
We need to increase our knowledge on deployment of ASP.NET Web sites/Web App. We
All, I need to create an app for work that signs into our website
Our app (already deployed) is using an Access/Jet database. The upcoming version of our
Our app is going to move for testing. We need to debug for finding
I need to add a second DataTable from our app's main DataSet into a
We are a bit lost here. We need to make our app installable on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.