During the development of my last project I have experienced a strange behavior, iOS app didn't crash when I was launching it from Xcode, but it crashed when I was launching it on the iPad.

The application is based on cocos3d framework and it crashed when it was starting up in the initializeWorld method, apparently without any reason.

The reason was very simple, but it was very difficult to find:

"iPhone OS uses a watchdog timer when applications are launched. If an application takes too long to complete its initial startup, the operating system terminates the application. Applications terminated for this reason will have the exception code 0x8badf00d and related information noted in the associated crash report"

Instead, when Xcode launches an application, the watchdog timer is disabled to compensate for additional overhead that may be incurred when Xcode attaches the debugger. As a result, your application's long startup may initially escape your attention if you are exclusively testing by running from Xcode.

Moreover in the device log I found something like the following:




Application Specific Information:

com.yourcompany.TestFade3 failed to launch in time

Elapsed total CPU time (seconds): 20.770 (user 20.770, system 0.000), 52% CPU

Elapsed application CPU time (seconds): 19.963, 50% CPU

Thread 0 name:  Dispatch queue: com.apple.main-thread




It was clear that the watchdog was expiring….

As Apple says:

"The best applications launch quickly, allowing the user to interact with the application as soon as possible. To provide a quality user experience, you should routinely evaluate and work to improve the launch time of your application. If considerable work must be done at launch, consider performing that work on a secondary thread and visually indicating the activity."

I solved this problem adding a loading screen to my app, in this way the app starts quickly and then all needed resource are loaded when the loading screen is active.