1

I have looked into related topics which did not give correct answers.

The following code is running from within an observer of UIApplicationDidEnterBackgroundNotification

    NSTimeInterval backgroundTimeRemaining = [[UIApplication sharedApplication] backgroundTimeRemaining];
    NSLog(@"SHUTDOWN: OS allows=[%.2f]", backgroundTimeRemaining );

The output (sometimes) shows this:

SHUTDOWN: OS allows=[179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00]

It is not an issue of wrong printing format, as the same is shown when pointing to this number in the debugger.

I did not get it for iOS6/iOS7.04, only in iOS7.1. iPad 3.

Any idea please?

ishahak
  • 6,585
  • 5
  • 38
  • 56

2 Answers2

0

backgroundTimeRemaining value of [UIApplication sharedApplication] has relevance only when the app is in background. If you read the value of this property app when app is in foreground, you get such (big) output.

Typically, this should output close to 180 (time in seconds) immediately after app goes in background and then decrease gradually to 0 (if the app remains in background). As per apple docs, the app gets up to 600 seconds in background to perform tasks before it is suspended.

NSLog(@"UIApplication.sharedApplication.backgroundTimeRemaining = %f", UIApplication.sharedApplication.backgroundTimeRemaining);
Ashok
  • 6,224
  • 2
  • 37
  • 55
  • 1
    Hi @Ashok, did you notice that I wrote my code is called from within 'UIApplicationDidEnterBackgroundNotification'? what is the added value of your answer? – ishahak Oct 26 '14 at 07:04
0

Two potential issues here.

First one is that a lot of timers are suspended when you're running connected to Xcode. This makes debugging this stuff very annoying; take heart, you're not the only one.

The other is that you have to tell the OS that you have a long running shutdown task; otherwise you get the 5 seconds then 0xbadfood. Try calling UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil]; before you query the time remaining. Remember to disconnect your hardware from Xcode before running this, and remember to [[UIApplication sharedApplication] endBackgroundTask:bgTask]; or else it is 0xbadfood time again.

0xbadfood is the exception code when your app is killed by the watchdog, btw.

Gordon Dove
  • 2,537
  • 1
  • 22
  • 23