Search code examples
iosswiftlifecycle

iOS app life cycle after long periods of time of inactivity


I have an app (written in Swift) that currently crashes after the user goes to a particular view then closes the app or turns off the device for several hours.

I'm wondering what happens to the app after a long period of inactivity:

  • Does the app try to go to the same view? (I think yes)
  • If so does it go through the app delegate first?
  • Is -viewDidLoad run again or just -viewWillAppear?
  • If the device is completely switched off, when it goes back on and the user tries to start the app, does it restart completely or tries to go where it left off?

I find it hard to test because in order to recreate this issue I have to switch off the device while being on a certain view and then leave off or several hours.

From a different perspective, the crash log shows the following:

Exception Type:  00000020
Exception Codes: 0x000000008badf00d
Exception Note:  SIMULATED (this is NOT a crash)
Highlighted by Thread:  0

Application Specific Information:
matt.myApp-v2 failed to launch after 20.00s (launchIntent: foreground-interactive)

Elapsed total CPU time (seconds): 2.030 (user 2.030, system 0.000), 5% CPU 
Elapsed application CPU time (seconds): 0.006, 0% CPU

....

Error Formulating Crash Report:
Failed while requesting activity/breadcrumb diagnostics

Solution

  • 0x000000008badf00d

    This is a hard coded error for the app watchdog. "Ate bad food".

    It means that your app is being terminated on launch because it is taking too long for the application:didFinishLaunchingWithOptions: function to return.

    My guess is that you're making a long core data call or network request in there.

    The crash here is on startup though. Not a crash that's happening after a long period of time.

    I suspect that your app is being terminated by the OS due to memory pressure from another app but then when launching the app is trying to continue doing something that it is no longer actually doing and getting stuck somewhere.

    What does your application:didFinishLaunchingWithOptions: function do?