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

  • Home
  • SEARCH
  • 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 4570912
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:25:47+00:00 2026-05-21T19:25:47+00:00

I am doing some tasks after having entered in background mode. I want to

  • 0

I am doing some tasks after having entered in background mode. I want to do these tasks only if I am in background mode so I did :

if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground)

But applicationState is only available in iOS 4.0 and later…

I wonder how this piece of code will work on iOS 3 for example.

  • How can I know if the device has iOS 4 ?
  • How can I avoid crash and exceptions for iOS < 4 ?

Thansk for your help

Kheraud

  • 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-21T19:25:48+00:00Added an answer on May 21, 2026 at 7:25 pm

    You can check whether the current iOS supports returning the current application state by using -respondsToSelector:

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(applicationState)] ){
      UIApplicationState state = [[UIApplication sharedApplication] applicationState];
    }
    

    You can determine whether multitasking support is available (even devices running iOS 4 or later may not have the hardware to support multitasking) by specifically checking for background support:

    UIDevice* device = [UIDevice currentDevice];
    BOOL backgroundSupported = NO;
    if ([device respondsToSelector:@selector(isMultitaskingSupported)])
       backgroundSupported = device.multitaskingSupported;
    

    You can retrieve the iOS version by using the following code (although you should not really rely on the following code to infer background support):

    float osVersion=[[[UIDevice currentDevice] systemVersion] floatValue];
    

    Finally, if you want to perform some tasks just after having entered background mode, you’ll want to take advantage of the following event:

    - (void)applicationDidEnterBackground:(UIApplication *)application
    

    .. but note that your time will be very limited. You will have approximately five seconds to do whatever you want to do. In case you need more, you can try asking iOS for additional time:

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        UIApplication*    app = [UIApplication sharedApplication];
    
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
            [app endBackgroundTask:bgTask];
            bgTask = UIBackgroundTaskInvalid;
        }];
    
        // Start the long-running task and return immediately.
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    
            // Do the work associated with the task.
    
            [app endBackgroundTask:bgTask];
            bgTask = UIBackgroundTaskInvalid;
        });
    }
    

    Note that in this case, you might be granted more time by iOS (or not), but it’s still a finite-length time.

    Apple’s Executing Code in the Background is a worth read.

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

Sidebar

Related Questions

After doing some research on the subject, I've been experimenting a lot with patterns
In my asp.net page I have a VBScript method which is doing some tasks
I am using custom delegate objects to do some cleanup tasks after a request
I have a specific task and after doing some research, I feel a little
So, after converting my repository to git and doing the first build, some build
I often want to do some customization before one of the standard tasks are
I'm doing some stuff that uses snow clusters. Currently the only way I know
While doing some small regex task I came upon this problem. I have a
Doing some jquery animation. I have certain divs set up with an attribute of
Doing some homework here (second assignment, still extremely green...). The object is to read

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.