确认用户在点击后想要拨打电话号码

时间:2011-05-27 15:55:17

标签: iphone ios

我想显示一个弹出窗口,询问用户是否想在用户点击某个号码时拨打该号码。

我该怎么做?目前,当我点击该号码时,它会自动调用它。

4 个答案:

答案 0 :(得分:10)

你也可以这样做:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt:0123456789"]];

获取提示并在之后返回您的应用。

答案 1 :(得分:3)

创建UIAlertView,并将委托设置为self,如果selectedButtonIndex是警报中yes按钮的buttonIndex,请拨打该号码,如果没有,请不要拨打该号码。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Do you want to call..." delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert setTag:02];
[alert show];
[alert release];

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (alertView.tag == 02 && buttonIndex != alertView.cancelButtonIndex) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://phonenumber"]];
    }
} 

答案 2 :(得分:3)

我认为你所寻找的东西就像UIWebView自动对电话号码所做的那样。它会弹出一个UIAlertView来询问用户是否想在拨出之前拨打该号码。为此,请将您的类设为UIAlertViewDelegate并执行以下操作:

UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle: nil
                            message: phonenum
                            delegate: self
                            cancelButtonTitle:@"Cancel"
                            otherButtonTitles:@"Call",nil];
[alert show];
[alert release];

此外,将以下方法添加到同一个类:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"tel://%@", phoneNum]]];
    }
}

当用户与其进行交互时,警报视图将回调此方法。 buttonIndex == 0确保您只在用户点击“呼叫”按钮时拨打该号码。

答案 3 :(得分:0)

您应该使用UIAlertView方法。 该文档在this link 中提供。我建议您查看该文档,一切都是自我解释的。

但你可能需要这样的东西。

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Really call?" message:@"Do you want to call this number?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];
// optional - add more buttons:
[alert addButtonWithTitle:@"Yes"];
[alert show];
相关问题