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

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

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

创build一个UIAlertView代理设置为self,如果selectedButtonIndex是alert中的yesbutton的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自动到电话号码。 它会popup一个UIAlertView来询问用户是否想在拨出之前拨打该号码。 要做到这一点,让你的class级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确保您只在用户点击“呼叫”button时调用该号码。

你应该使用UIAlertView方法。 文档在此链接中提供。 我build议你看看这个文档,一切都是自我解释的。

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

 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];