1

Distributed a build through TestFlight. The ad-hoc build works fine on iPhone 5,but will open and then crash on iPhone 4 and 4s. If compiled and run through Xcode (directly to Phone with dev provisioning profile) the build runs on both iPhone 5, 4s and 4.

Has anyone ran into this?

Eric
  • 4,063
  • 2
  • 27
  • 49
  • Get the logs from the phones. – Kevin Feb 08 '13 at 19:00
  • from log: failed to launch in time Elapsed total CPU time (seconds): 22.910 (user 22.910, system 0.000), 57% CPU Elapsed application CPU time (seconds): 17.455, 43% CPU – Eric Feb 08 '13 at 19:09
  • 1
    If your app doesn't finish starting up (I believe this is essentially return from the `application:DidFinishLaunchingWithOptions:` method) in a certain amount of time, it's killed by the system. Either you have an infinite loop or you are trying to do way too much in that method. It's possible that you have a bug that only affects new (clean) installs, try deleting the app and trying again on your phone/simulator. – Kevin Feb 08 '13 at 19:15
  • not infinite and works ok on iPhone 5, caching a bunch of images – Eric Feb 08 '13 at 19:16
  • Caching a bunch of images could certainly explain it. That would take a while and go slower on the older phones. Put that code into a separate thread (`dispatch_async`). – Kevin Feb 08 '13 at 19:17
  • OK Cool, this has to be it. Is there a way to override that timeout? – Eric Feb 08 '13 at 19:18
  • You can't override it directly, but as I said, do it in a separate thread. – Kevin Feb 08 '13 at 19:19

1 Answers1

1

The first thing to do debugging testflight errors (or any other, for that matter) is to get the error log, and read and understand the error message. In this case the error is:

failed to launch in time

If your app doesn't finish starting up (I believe this is essentially return from the application:DidFinishLaunchingWithOptions: method) in a certain amount of time, it's killed by the system. Either you have an infinite loop or you are trying to do way too much in that method. In this case, the app caches images in that method, which evidently is fast enough to finish in time on the iPhone 5 but not earlier ones. The solution is to queue a dispatch_async call (see Dispatch Queues) that caches the images in the background, and return quickly from the app launch method.

Kevin
  • 53,822
  • 15
  • 101
  • 132
  • Your answer is dead on, but in my specific app, it's tough because I'm needing to cache a dozen images that are required to be available immediately. I'm thinking a HUD to block so the app has a chance to launch fully. – Eric Feb 08 '13 at 19:32
  • Throw up a loading screen and use [a semaphore](http://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html) to wait for it to finish. – Kevin Feb 08 '13 at 19:35
  • One more thing. Can you think of why it would directly build and work on iPhone 4 but not via TestFLight? – Eric Feb 08 '13 at 20:13
  • I believe when launching from XCode the timeout is lengthened, in order to account for the debugger. I don't think it's dropped altogether, but it's possible. – Kevin Feb 08 '13 at 21:32