UIAlertView Causes Crash in iOS SDK 6.0

2019-03-23 12:09发布

问题:

I recently submitted an app to App Store that has not been accepted yet. Meanwhile, I downloaded Xcode 4.5 and tested my app in iPhone 6.0 Simulator.

However, when I intend to show an UIAlertView, the app crashes on [myAlertView show] line with EXC_BAD_ACCESS error. It works fine with iPhone 5.1 Simulator.

Here's my code:

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Are you sure?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[myAlertView show];  

Is that normal? What am I doing wrong with my code?

Also, do you think I should resend my app to Apple?(Just asking your advice)

Thanks in advance.

Edit: Apple has rejected the app because of iOS 6 crash.

回答1:

See this related Question: UIAlertView shown from background thread and with no delegate creates EXC_BAD_ACCESS

User input and UI calls must come from the main thread. Many of them will work "most" of the time on other threads, but sometimes will crash. They are more likely to crash differently (more or less often) on a device than the simulator, but it's possible Apple made changes that affect that difference in iOS6.

And to your second question, I would answer yes, I would upload an updated binary for review as soon as you fix the issue, especially if you can reproduce this on a device (I strongly encourage you to attempt to reproduce it on a device). Otherwise, you may A) get accepted with a bug your users hate, or B) get rejected and have a an even longer delay and possibly more scrutiny. If you send an updated binary before review finishes it does put you at the "back of the line" AFAIK, but better than the alternatives.



回答2:

Delete this method and use the other method:

 [myAlertView show];  

Try this Method:

 [myAlertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];