UIAlertView Causes Crash in iOS SDK 6.0 - iphone

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.

Delete this method and use the other method:
[myAlertView show];
Try this Method:
[myAlertView performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:YES];

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.

Related

Getting memory leaks in my iPhone application project how should I resolve it?

I am getting memory leaks in one of the method which I used in my iOS project. I am not able to find out what is happening as I am new in iOS development.
http://screencast.com/t/y2lOtssY2NjO
You are calling init twice on your alertView.
I think that makes the issue.
Change that like:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:str message:kAlertMessage delegate:self cancelButtonTitle:nil otherButtonTitles:#"Install now", #"Cancel", nil];
Please refer this question : What happens if i call init more than once
The static analyser is pointing out the leak on UIAlertView .Initialize the alertView only once.
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:str.....and so on
You can find via instrument here is tutorial for click here that will tell you or Xcode->product->analyze

UIWebView Error Delegate Method vs Reachability

I'm in the process of submitting my app to the App Store, but I read that I must notify the user if the internet connection is down when my app needs it. The Apple page mentioned Reachability as well. Currently, though, I'm using the UIWebView delegate method didFailLoadWithError...
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Error Loading" message:[error localizedDescription] delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[errorAlert show];
}
...and it's working fine. My question is, will my app be rejected for not using Reachability to do this, or is it fine doing what I am currently doing?
Thanks in advance.
No, you're perfectly ok using didFailLoadWithError:.
Reachability class could be used to check if host is up (or internet connection at all) before even trying to load some page. But it is not neccessery, as long as you handle the possible errors - which obviously you do.
EDIT:
It is still a good practice to know wheather you will be able to reach a certain host or not. You could even modify GUI for each case (instead of just reporting an error). But this can always be done in update :)

applicationWillTerminate problem

I want to show the UIAlertView when user Click the Iphone Home button( means Close the application)
I have done these Code
- (void)applicationWillTerminate:(UIApplication *)application
{
NSString *errorString =#"Testing";
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:errorString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
}
But UIAlertView is not Showing. please help
Thanks in Advance
The user aims to close your app when he/she presses the home button. Apple suggest to let him/her to that. What I want to say: Don't do that. I think it is even not possible.
Look at Problem with applicationShouldTerminate on iPhone:
The alert view is never shown because
the 'show' method does not block, and
therefore, the end of
'applicationWillTerminate' is reached
immediately after you create the
alert view and try to show it. I
believe this is by design. You can't
really begin asynchronous operations
in 'applicationWillTerminate'.
applicationWillTerminate: may not be called in the newer version of iOS when pressing the Home button because the app could be only entering the background mode, not actually terminating.
Even if it is actually called (either the app is really terminated, or you're moving the code to applicationWillEnterForeground:), showing the alert is useless because the alert is associated with the active app, and your app has gone inactive by the time the alert is shown! So what happened really is, the alert is gone when the user press the home button, and when they resume your app, they see a mysterious alert popping up.
Don't ask if the user wants to quit your app. This isn't the norm in iOS. Instead, save all states in applicationDidEnterBackground:, and restore them in applicationWillEnterForeground: and application:didFinishLaunchingWithOptions:, making the user feel as if the app has never been terminated.
You might not want to use applicationWillTerminate but rather applicationWillResignActive. Check older posts like this one for more info.
You can't show a uialertview when application receive SIGKILL(Exit) Command.You can call any file or background functions in applicationWillTerminate - To do that you need to set a key in your plist.
UIApplicationExitsOnSuspend - Boolean - YES.

OpenFeint and Phonegap view problem

I am testing my app on a ipod Touch 4g iOS 4.2. Please note I tested the app on an iphone 2G with iOS 4.2 and this was not an issue.
The initial OpenFeint approval view launches, but the Phonegap view immediately lauches soon after so that the user has no time to enable/ignore Openfeint.
Even worse, the top of the phonegap view is clipped off and you can see the the Openfeint approval screen sitting there behind it.
I can use the app and openfeint works in offline mode registering high score and achievements.
My impression of Openfeint is that its view should go straigh to the top whenever it launches but for some reason it's not happening here.
I'm trying a few UIView methods and property changes but no luck so far.
Anyone come across this or understand how either of the view systems work.
I'll continue my debugging and report back but let me know if anyone out there has a good idea and/or insight.
Thanks
Nigel
I think worked this out. May be a few bugs. Require more thorough testing. Will report back.
Basically I disabled the default Openfeint Approval process and set up my own one using the OpenfeintDelegate.h
(BOOL)showCustomOpenFeintApprovalScreen
{
SCNetworkReachabilityRef reach = SCNetworkReachabilityCreateWithName(kCFAllocatorSystemDefault, "google.com");
SCNetworkConnectionFlags flags;
SCNetworkReachabilityGetFlags(reach, &flags);
if(kSCNetworkReachabilityFlagsReachable & flags) {
// The internet can be accessed using the current connection.
UIAlertView *alert = [ [UIAlertView alloc] initWithTitle:#"OpenFeint Approval"
message:#"Do you want the awesome leaderboard, acheivement and challenge features offered by OpenFeint? (Remember this data will be stored on OpenFeint servers)"
delegate:self
cancelButtonTitle:#"No thanks"
otherButtonTitles:#"Yes", nil
];
[alert show];
[alert release];
}
return YES;
}

iOS4 (UIAlertView) why this code causes memory leaks?

suppose you create a new iOS app from scratch, with just one single window.
then you put this code in the appDelegate application didFinishLaunching method :
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle:#"alert"
message:#"message"
delegate:nil /* same problem with 'delegate:self' */
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[myAlert show];
[myAlert release];
build and run in simulator 4.1, attach instrument, and...
this causes each time a memory leak.
in simulator 3.1.2 on leopard, no problem at all.
Of course, in a real app, the UIalertView is trigerred by a button, but the result is identical.
What is the problem ?
is UIAlertView buggy until iOS4 ?
Don't check for leaks in a simulator. It doesn't have the same memory model so reports leaks when there aren't any.
Test on a real device and if the leak is still there, report it as a bug to Apple :)