I wish to know when the users are actually placing a call from my application (UIWebView) and not just tapping on the phone number.
How can I get the result of what the user selected when he receives the call/cancel popup after pressing a telephone link in my app?
There is some info regarding this on Opening tel: links from UIWebView.
How Things Work & What You Want
The OS is not going to handle showing the Call/Cancel alert dialog for you. That is up to you. It shows up in Safari because the Safari app's shouldStartLoadWithRequest method undoubtedly responds to the tel: scheme by showing a UIAlertView. Your conditional for if ([url.scheme isEqualToString:#"tel"]) should, when YES, trigger a UIAlertView with a Call and Cancel button. On Call, you will tell the sharedApplication to openURL; on Cancel, you will not issue the call & you will also want to return NO so your app does not attempt to loadWithRequest
Code Example:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
//OK clicked
} else {
}
}
- (void) _showAlert:(NSString*)title
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:#"Check your networking configuration." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
Hope this helped you in some way.
Best Regards
Linus
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
It's Irritating ...!!!
I googled about this problem, found some Relative Questions but not Satisfactory Answers.
So I have One - (IBAction) method that adds some UITextField's Values to NSMutableArray when "Add" Button is Clicked. I am simply trying to show UIAlertView, if the UITextField is empty.
My Code :
- (IBAction)addButtonPressed:(id)sender
{
if ([textField1.text length]==0 || [textField2.text length]==0 || !someFlag)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"MyApp" message:#"Please Enter Valid Data..." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
else
{
// Code to add textField's value to Array.
}
}
My Problem :
Whenever I press "Add" Button with empty textField , UIAlertView appears thrice.
1) For the First Time It appears with "Close" Button. (I have never added...) It disappears within some time.
2) Second Time It appears with "OK" Button. (That's what I added...) It disappears when I press "OK" Button.
3) Third Time It appears with "Close" Button again. It disappears when I press "Close" Button.
EDIT :
Similar Question : UIAlertView Pops Up Three Times per Call Instead of Just Once.
Can someone help me to found solution from this ?
Your code contains no issues. There's not 3 it's only 2 alerts. here's the flow of alert view:
As soon as you click on add button there called 2 selector (may be one inside other OR two IBAction by one button) which contains alert view code in them
Now that alert2 (with cancel button) get called before alert1(with ok button)
Then alert1 get called and hide alert2
Now when you resolve alert1(by clicking on ok button) alert2 shows up again
Now what you need to do is to check "if your button is not connected with 2 IBActions", which that should be as you have no such code to call another alert in this method. And check if it helps.
Strange....!!!
Sometimes it happens that you Totally Neglect certain lines of your code When you are Over-Irritated. It happend to me also. I neglected one method that is called from -addButtonPressed Method , Which has One AlertView (With "Close" Button of course) inside it.
That's the Solution itself !!!
yes I have face same problem but my case is different than you .
You should try [textfield.text isEqualToString:#""]; because this is the standard way to compare empty text field in Objective-C.
Check that you dismiss your alert view properly sometimes we don't give focus on dismissing the alert view so because of that your alert view remain active and when you reopen you are app it shows 2 to 3 times depending on your condition. So you can use the delegate did dismiss alert view with button index for dismissing the alert view in view did disappear. I am not sure but it should work for you Good luck dude.
And I am not sure but I think your IBAction Button is overwrite for each time when you clicked in any button so you should check it also.
Try below code......let me know it is working or not!!!!
what you have done is you have given other button nil 2 times..so may be that is the problem...
Happy Coding!!!!
if ([textField.text length]==0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"MyApp" message:#"Please Enter Valid Data..." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
Try compare like this.
if([testBox.text isEqualToString:#""]
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:errorDesc
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
- (IBAction)addButtonPressed:(id)sender
{
if ([textField.text length]==0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Information",#"") message:NSLocalizedString(#"Txt is Empty!",#"") delegate:nil cancelButtonTitle:NSLocalizedString(#"OK",#"") otherButtonTitles:nil];
[alert show]; alert = nil;
}
else
{
// Code to add textField's value to Array.
}
}
First check that how many times you call IBAction method when Button tapped???
Other wise put instance of UIAlertView is a public.. I mean put in .h file and access it as self.yourAlertViewName in .m file.
Thanks :)
Check with below code:
if ([textField.text length]==0)
{
UIAlertView *objAlertMsg = [[UIAlertView alloc] initWithTitle:#"MyApp"
message:#"Please Enter Valid Data..."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[objAlertMsg show];
[objAlertMsg release];
}
Check that, I have set delegate to "nil" instead of "self". And make sure you have not implement delegate in view controller if it's not required.
Hope it will be helpful to you.
Cheers.
When popping a view I want to save some data, by asking confirmation. I'm asking confirmation using UIActionSheet. But irrespective of my response in action sheet, the view is changing in background, it creates some problem for me to use the response. I'm using navigation controller to switch views. How can I solve this
TIA
Better option is to use uialertview for asking confirmation.To do this follow this step:
Insure your header file contains the following:
#interface YourViewController : UIViewController <UIAlertViewDelegate>
Now when asked confirmation add this code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Message" message:#"Are You Sure" delegate:self cancelButtonTitle:#"YES" otherButtonTitles:#"NO", nil];
[alert show];
[alert release];
Now after pressing one button below delegate will be called so add in .m file of app
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the YES/NO buttons
if (buttonIndex == 0)
{
NSLog(#"NO button pressed");
}
else
{
//Save data here
NSLog(#"YES button pressed");
}
}
#PooLas If I understood you correctly, You use uiactionsheet for user confirmation, while in background (actually under actionsheet) you change view controllers. Well, you can't do that, because delegate must be attached to controller which shows it up (if i am wrong, correct me). So when you click button, you can only first dismiss actionsheet and then change view controller, but not opposite – PooLaS
i have an application in which i have implemented facebook in my app. In my app i have a page with a label and a button .when i click on the button the login page of facebook is opened.when i enter my username and password and click on the login button the login page dissapears. All this is working fine and but the problem is when i click again my button it should an alertview displaying that "this will logout from your previous account" and on the click of the ok button the session should get logged out displaying the login page.The problem is when i click the button it directly shows the login page without showing the alertview.Please help me in solving this problem.Thanks
Without seeing any of your code, i'm not too sure exactly how your logic is showing the alert, but if i was to show a confirmation alert, it would look something like this
- (IBAction)logoutButton_touchUpInside
{
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:#"Please Confirm"];
[alert setMessage:#"are you sure?"];
[alert setDelegate:self];
[alert addButtonWithTitle:#"Yes"];
[alert addButtonWithTitle:#"No"];
[alert show];
[alert release];
}
And implement the delegate method to catch the button click:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// Yes, do something
}
else if (buttonIndex == 1)
{
// No, cancel etc...
}
}
In Iphone I have to show an alert if the user clicks on home button immediately to indicate him that "The process will be stopped and he will loose the data".I have to tried to implement this using applicationWillResignActive and applicationDidEnterBackground.Can any one help me how can i achieve this?Is it appropriate to show such alert message on home button
Thanks,
Yogesh Chaudhari
Try this below code this will help you.
Its not really a way to quit the program, but a way to force people to quit.
UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:#"Hit Home Button to Exit" message:#"Tell em why they're quiting" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[anAlert show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
[[NSThread mainThread] exit]
}
}
the situation is like this:
if i don't have internet connection, i show UIAlertView to the user.
when the user press "try again", i call "do something".
the problem is the UIAlertView still show for seconds.after the user click "try again"
i tried like:
[self.view setNeedsDisplay];
but,it not works, cause even in the documents,if said the refresh will be
only when code control will return to the system, and that is not the case here.
thanking in advance.
///////////////////////////////////
if(somecondition)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"NO INTERNET CONNECTION"
delegate:self cancelButtonTitle:nil otherButtonTitles:#"Try Again", nil];
[alert show];
[alert release];
return;
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
[self DoSomthing];
}
I use this method to detect when the alert is dismissed, I added a line of code to hide it and spawn a new URLrequest, if that's what you need.
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
alert.hidden=YES;
[webnews loadRequest:[NSURLRequest requestWithURL:home]];
}
The request uses my UIWebView 'webnews' and the NSURL 'home', you will have to adapt these of course.
If you do some lengthy process in the callback from the alert, it will not hide until that callback returns.
So in other words, your doSomething method should not directly try to reconnect to the internet, but just have it spawn off the asynchronous call for doing this.
EDIT:
You may delay/detach execution of doSomething with this line of code:
[self performSelector:#selector(doSomething) withObject:nil afterDelay:0];