我想打电话,我使用下面的代码。
- (void)callPhoneNumber:(NSString *)phoneNumber
{
UIWebView * webView2 = [[UIWebView alloc] init];
// Remove non-digits from phone number
phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""];
// Make a call
NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phoneNumber]];
[webView2 loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:webView2];
}
在拨打电话之前,我要求用户使用UIActionSheet
. 当用户选择一个选项时,我会根据该选项拨打电话。
问题是如果我不显示UIActionSheet
并直接拨打电话,上面的代码可以正常工作。它会提示一个警报,要求用户确认拨打电话。但是在显示UIActionSheet
如果我调用上述方法之后,它不会显示确认警报。
奇怪的是,在这之后,如果我从 Xcode 中停止应用程序,那么应用程序就会被放置在离子背景中。但我也在设备的主屏幕上看到了确认警报。它如何显示在设备的主屏幕上而不是在应用程序中?
以前有人遇到过吗?可能是什么原因?
编辑:我也试过下面的代码。但它有同样的问题。每当上面的 webview 代码有效时,下面的代码也有效。当它不起作用时也是如此。
NSString *phoneNumberURL = [NSString stringWithFormat:@"telprompt:%@", phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumberURL]];
编辑:为操作表和委托添加代码。
我首先显示一个警报。在按下警报按钮时,我会显示操作表。并从操作表中选择选项我拨打电话。
# pragma mark - ALERT VIEW DELEGATE
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag == MY_TAG)
{
// Ask to select option
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Option" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Option1", @"Option2", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
}
}
#pragma mark - UIActionSheet Methods
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// If not pressed cancel button.i.e. selected one of the options
if (buttonIndex != actionSheet.cancelButtonIndex)
{
// Place a call
[self callPhoneNumber:@"1234567890"];
}
}