[英]confirm user wants to call a phone number after click
我想显示一个弹出窗口,询问用户是否要在用户单击号码时拨打该号码。
我怎么做? 目前,当我点击号码时,它会自动调用它。
你也可以这样做:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt:0123456789"]];
获得提示并在之后返回您的应用程序。
创建一个UIAlertView,delegate设置为self,如果selectedButtonIndex是alert中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"]];
}
}
我认为您正在寻找的是类似于 UIWebView 自动对电话号码执行的操作。 它会弹出一个 UIAlertView 来询问用户是否想在拨出之前拨打该号码。 为此,请将您的 class 设为 UIAlertViewDelegate 并执行以下操作:
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: nil
message: phonenum
delegate: self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Call",nil];
[alert show];
[alert release];
另外,在同一个class中添加如下方法:
- (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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.