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 8289709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:34:29+00:00 2026-06-08T12:34:29+00:00

this is how I start a background task when application goes background , void

  • 0

this is how I start a background task when application goes background ,

   void applicationDidEnterBackground:(UIApplication *)application
{
    btId = UIBackgroundTaskInvalid;
    UIApplication* cuiApplication = [UIApplication sharedApplication];

    void (^backgroundTimeRemainingExtenderHandler)() = ^() {

        NSTimeInterval timeRemaining1 = [cuiApplication backgroundTimeRemaining];

        if(btId != UIBackgroundTaskInvalid){
            [proximityEngine StopEngine];
            [cuiApplication endBackgroundTask:btId];
            btId = UIBackgroundTaskInvalid;
        }
    };

    btId= [cuiApplication beginBackgroundTaskWithExpirationHandler:backgroundTimeRemainingExtenderHandler];

    if(bgmanager != nil){
        [bgmanager BeginBackgroundTaskMainLoop];
    } 
}

My problem is that when my background task calls :

NSURLConnection sendSynchronousRequest

The expiration block is being called even though there is more time remaning , how can I prevent this ?

Regards ,

James

EDIT :

After reading the answer below : I still have 596 seconds left when querying the amount of time left and yet still IOS calls the expiration block handler.

  • 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-06-08T12:34:32+00:00Added an answer on June 8, 2026 at 12:34 pm

    In my particular case – which I do not quite sure why it behaved the way it behaved , I performed the task on a different thread than the beginbackgroundtask thread , after sendsync returned in that thread the backgroundtask was interrupted by the OS .
    When calling sendsync in the beginbackground original thread , it does not occur.
    Not sure if its something logical and I did something wrong or an OS bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the background... one of our server is crashed and I can't start
I use a batch to launch my java application like this start /min java
In my application, I am sending periodic cron and background task requests to refresh
I need to schedule a task in background when the application enter background state.
I am running a background thread in my asp.net web service application. This thread's
I have a situation like this: start(); <Some code> end(); I want start() function
Before I start this may be hard for some people to understand. Sorry. I
I'm trying to convert this line into Batch how would one start this exe
I mean: Consider a VMWare Windows 2003 image. If I 1 - start this
Before you start marking this as a duplicate , read me out. The other

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.