views:

151

answers:

2

Hi, I'm having some strange behaviour ocurring when I try to run my Iphone app without using Xcode. If I run it by choosing Build & Run in Xcode it runs just fine, but if I do it by disconnecting the USB cable and tapping on the app on the Iphone, it crashes, yielding an unhelpful crash log.

Is there any difference between these 2 scenarios that could be causing this behaviour?

A: 

After having run the app out of XCode, have you terminated it? With iOS 4 it will continue to run in the background, and when you tap on the app on the iPhone, it just brought to the foreground.

Double click on the home button and see if it's still running. If so, tap on the app until the minus sign appears and tap it.

Codo
+1  A: 

The difference is that if you run it via Xcode, the debugger is attached and a lot of restrictions are not applied. For example, if an app starts up it must respond with a few seconds otherwise it's killed. If you run it with the debugger, that restriction is lifted. Same when exiting: if you hit the home button (on iOS < 4 or iOS >= 4 without multitasking) then an app gets five seconds to exit. Not so with the debugger attached.

It might help if you post the error message from the crash log.

DarkDust
What do you mean by "must respond with a few seconds"? Our app is making a long initialization process which usually lasts more than 20 seconds when it starts. Maybe our app should be doing the initialization process in a background thread instead of the main thread?
Diego
I've just tested my app in an Ipod Touch 2G and then in an Iphone 3GS, and it didn't crash in the 3GS, so I guess your idea of initializing in a background selector is the way to go. I'll try that and report back
Diego
The `applicationDidFinishLaunching` or `application:didFinishLaunchingWithOptions:` must return in a timely manner. You can simply test this with `sleep`. If you insert a `sleep(30)` your app is going to be killed if not run by the debugger. So long-running init tasks should be run in a separate task (or `performSelectorInBackground:withObject:` and send a notification once that's done). One thing to remember here is that if that background task needs to modify GUI elements you will probably need to do so via `performSelectorOnMainThread:withObject:waitUntilDone:`.
DarkDust
That did the trick, thanks!
Diego