Error Notification - iphone

i have a refresh button, when i press it it refreshes my xml file and puts it in the tableview, what i want is, when i dont have connection to my xml file, i want it to show me a pop up that tells me there is no conntion to the server.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"No Connection" delegate:refreshButton cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
hope you can help
any idea how ?

Check the return code from your http request. If it is a code that signifies no network connection, you can show the alert view.
I suggest using ASIHTTPRequest if you aren't already. It lets you set failure blocks that will execute when the request doesn't complete successfully.

Related

Close Alert View Via Code

I've got an alert:
UIAlertView *connectionError = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Connection Failed" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
I want to know how I can programatically close an alert view when I hit a certain event in my code. I know there is no distinct call to just close out an alert, and I've seen people make calls straight to buttons, however, I'm not sure how to call the cancel button on an alert.
Is this even the right way to go about it? Or is there a better path?
You can use -dismissWithClickedButtonIndex:animated: method for dismissing alert view:
[connectionError dismissWithClickedButtonIndex: connectionError.cancelButtonIndex
animated: YES];
That's the only public API for dismissing alerts, so you should use it.
Declare you alert view in .h file
then call this function
[connectionError dismissWithClickedButtonIndex:0 animated:YES];
Hope it helps..

How to exit the app after an error in user friendly manner?

I need to protect my code against possible errors. If they arise then there's no point to run the app further, so I need to bring to the user some message and then exit the app. So, I'm checking the conditions and then bringing alert:
if (someError){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"No database file exist. App will close now." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
And in the delegate method I'm closing the app using NSAssert:
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSAssert(0, #"closing");
}
}
Also, I have included delegate protocol in header. However, the app just brings alert but after pressing OK it just freezes, and I'm getting some message "CoreAnimation: ignoring exception: closing". What am I missing or what other options exits?
You should not do that, it is against Apple HIG (Human Interface Guidelines):
iPhone applications should never quit programmatically because doing so looks like a crash to the user.
It is always better to provide some kind of feedback to the user about the error that occured and provide a way to restart the process without restarting the app. However, if you really, really want, you can use
exit(0);

how to display alert when networking connection is disable?

i am new to iphone in my app i am connecting to database through web services it working correctly,but i want to displat alert when network connection is disable.please any help me how to alert when net connection is disable,
thanks in advance.
Have a look at this S.O. entry
In particular, the main point of interest for you is the first one, about using the Reachability framework to detect network connectivity.
Use UIAlertView to display alerts
When you get notified by your delegate/Observer for the network disable state, you could show message in UIAlertView.
//show an alert to let the user know that they can't connect...
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Network Status" message:#"Network is not available. Please try again later." delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
you could also use the Reachability API's to know the state of network connection.
iPhone SDK: Testing Network Reachability

How to check whether user has click on skip button or publish button in FBConnect in iPhone?

I have integrated FBConnect with my iPhone app.
Now i want to display a custom alert view if user has publish some post.
But i didn't get how to make sure that user has tapped "Publish" button or "Skip" button in dialog box.
Same way i have functionality of post image on wall and i want to check whether image has posted successfully or not.How i can achieve above 2 things?
Plz gv ur answer ASAP.
Thnks in advance to all
If the user publishes, then you'll get a call back to dialogCompleteWithUrl with something like this:
fbconnect://success/?post_id=12345
If the user presses Skip, you'll get this (no post_id):
fbconnect://success
Thought this would save more time for others
-(void)dialogCompleteWithUrl:(NSURL *)url
{
NSString *responseURL = [url absoluteString];
NSLog(#"[%#]",responseURL);
if ([responseURL rangeOfString:#"post_id"].length>0) {
///Publish response received here...
UIAlertView *feedPostedAlert = [[UIAlertView alloc]initWithTitle:#"Success" message:#"Feed posted to your wall successfully" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[feedPostedAlert show];
[feedPostedAlert release];
}
}

Objective C - Making UIAlertView wait for user input?

I have a UIAlertView set up with a textfield like so:
//***first set of code***
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"User Input Required" message:#"Please enter data into the field" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alert addTextFieldWithValue:nil label:#"[Enter Text]"];
[[alert textField] becomeFirstResponder];
[alert show];
[alert release];
//***second set of code***`
How can I make it so that the user is required to click a button (I have that method already set up to send the input to a string) BEFORE any of the 'second set of code' is fired off?
I need that second set of code to be contained in the same section as the alert (so I can't just run it within the 'dismissWithClickedButtonIndex' method) and that second set of code is using the string obtained from the user input, so that is why I don't want that code to run prior to the user clicking a button.
Don't you just love it when people say "don't do it that way"... and then never give you any good/correct way you SHOULD be doing it.
Thanks.
You can't do that. show message in UIAlertView won't stop for user input. Associated delegates will need to handle the code you are planning to put in //***second set of code*** section.
Having said that, let me give you some advice. addTextFieldWithValue message is an undocumented API feature. Do not use it. It used to be a long time ago that approval process from Apple for you APP would let you pass even if your application used that addTextFieldWithValue message. But nowadays that does not happen anymore. Your application will be automatically rejected if it is using that undocumented feature. Here is a blog entry on the topic.
Hope it helps.