Frage

plz help me out how much time UIApplication is going to run in the background state.like when we press home button etc

War es hilfreich?

Lösung

Limitation is as following:

  • 10 mins for iOS6
  • 3 mins for iOS7

Just in your app delegate implement:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    UIApplication *app = [UIApplication sharedApplication];
    __block UIBackgroundTaskIdentifier bgTask = 0;
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
              [app endBackgroundTask:bgTask];
              bgTask = UIBackgroundTaskInvalid;
          }];

}

After 600s (iOS6) or 180 s (iOS7) the expiration handler is called - you have to finish immediately - no chance for any time consuming task or app will crash.

Andere Tipps

I suggest you to take a look at Background Execution and Multitasking, briefly:

Most apps are moved to the suspended state shortly after entering the background. Only apps that provide important services to the user are allowed to continue running for any amount of time

It runs something like 5 seconds. You can also do a special process to ask more time to end a long task (like upload etc..).

Everything is explained here : https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

Have a nice reading session :)

The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see “Background Execution and Multitasking.”

Edited:

Support for some types of background execution must be declared in advance by the app that uses them. In Xcode 5 and later, you declare the background modes your app supports from the Capabilities tab of your project settings. Enabling the Background Modes option adds the UIBackgroundModes key to your app’s Info.plist file. Selecting one or more checkboxes adds the corresponding background mode values to that key. Table 3-4 lists the background modes you can specify and the values that Xcode assigns to the UIBackgroundModes key in your app’s Info.plist file.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top