开发者

Intermittent freezing on iPad

I have an iPad application that builds and runs perfectly the first time. But if I exit the application and open it again, the interface is completely unresponsive. If I exit and open another time, it never gets past the splash screen.

What's strange is that if I wait a minute or two before opening it again, it always runs fine.

Any ideas on what might be going on or where I should start my debugging efforts? I would throw in breakpoints and see what's going on, but by the time I start the application a second time, the debugger has already exited. Is there a way to keep the debugger and console running through multiple executions of an app?

Thanks,

Luke

Edit: Here's some code I use for NSUserDefaults - could this be the problem?

In viewDidLoad in my main view controller:

bgnum = [prefs integerForKey:@"bgnum"];
menuVisible = [prefs boolForKey:@"menuVisible"];
songTitles = [[NSMutableArray alloc] initWithArray:[prefs arrayForKey:@"songTitles"]];
numberOfSongs = [prefs integerForKey:@"numberOfSongs"];

In viewWillDisappear:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

[prefs setBool:menuVisible fo开发者_如何转开发rKey:@"menuVisible"];
[prefs setInteger:bgnum forKey:@"bgnum"];
[prefs setObject:songTitles forKey:@"songTitles"];
[prefs setInteger:numberOfSongs forKey:@"numberOfSongs"];

[prefs synchronize];


I'd look at what's happening in your initialization code, loadView, didFinishLaunching, etc., and trace it out. It's easy to get 3 or 4 methods deep in that stuff and do too much there when some of it should be lazy. With out more information or any sample code it's all wild guesses. One such guess is user defaults or anything that you're loading from a file or dictionary up front? I could see how something there could cycle through several states.


There's a big difference between "exiting the application and opening it again" which in context implies you are doing it rather quickly and "waiting a minute or two".

I have a rather large application that I develop on which routinely takes several seconds to "unload" on the iPad, which results in me rapidly exiting and re-entering causing the application to appear in a partially configured state, and causing unusual behavior.

This could be due to the fact that your application hasn't completely dealloc'd and closed its threads out, and thus when you launch it again quickly, the thread is resumed (and on 3.2 or earlier, will be unstable since it's already started killing itself off).

Do some timings... see what the threshold is for "it crashes" and "it works". If it's more than 10 seconds, then I would say something is wrong. Less than that, and you could be seeing what I just described,


With the device connected, run the app in debug mode from xCode and then exit the app. Now, disconnect the USB cable and run your app again - is it completely frozen? If you rotate the device, does your view orientation change? Once the app is terminated, plug your USB back in and go to xCode->Window->Organizer.

You should see your iPad device on the left of the screen. Select it and you should see some tabs on the right for Console and Crash report. Select your app from the dropdown and look to see if any console messages have been logged, or if a crash has occured - you should get a stack trace if it did which should help.

I once had a similar problem when I had NSZombieEnabled as an active argument in my executable, so that could be worth investigating too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜