单击后确认用户要拨打电话号码

问题描述

| 我想显示一个弹出窗口,询问用户在单击数字时是否要呼叫该数字。 我怎么做?目前,当我单击该号码时,它会自动进行呼叫。     

解决方法

        创建一个将委托设置为self的UIAlertView,如果selectedButtonIndex是警报中“是”按钮的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\"]];
    }
} 
    ,        您也可以:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@\"telprompt:0123456789\"]];
获取提示,然后返回到您的应用。     ,        我认为您正在寻找的是类似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确保仅在用户按下“呼叫”按钮时才呼叫该号码。     ,        您应该使用UIAlertView方法。 该链接中提供了文档。我建议您看一下该文档,所有内容都是不言而喻的。 但是您可能需要这样的东西。
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];
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...