Display UIAlertView before opening phone.app

一世执手 提交于 2020-01-16 16:57:18

问题


I have a view on map with a button and a label on the button. On the label i have phone number that comes from a plist. The variable of the phone number in the plist called "storePhone" and i implemented it in this way:

text4.text = myAnn.storePhone;

I made this method for pressing the button and opening the phone.app for dialing the number. Everything works great but i want a UIViewAlert to say to the user something like:"your going to dial this number, are you sure?" before the phone.app is open.

How can i do that?

This is my button methode:

-(IBAction)callToStore
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", text4.text]];
    [[UIApplication sharedApplication] openURL:url];
}

Thanks.


回答1:


I did it.
This is how you do it:

- (IBAction)moreInfoViewAlert:(id)sender
{
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"חיוג לסניף"
                                                  message:@"הנך עומד/ת לבצע חיוג, האם את/ה בטוח?"
                                                 delegate:self
                                        cancelButtonTitle:@"ביטול"
                                        otherButtonTitles:@"חיוג", nil];
    [message show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

    if([title isEqualToString:@"חיוג"])
    {
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", text4.text]];
        [[UIApplication sharedApplication] openURL:url];
    }
}

Attach the IBAction method to your button and you're good to go.



来源:https://stackoverflow.com/questions/8478198/display-uialertview-before-opening-phone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!