Ios 无法使用UIWebView拨打电话
我想使用Ios 无法使用UIWebView拨打电话,ios,objective-c,ios7,webview,uiwebview,Ios,Objective C,Ios7,Webview,Uiwebview,我想使用UIWebView打电话。我尝试了下面的代码,如果我简单地放一个按钮,然后在下面的代码中单击“执行”,它就可以正常工作。但目前在点击按钮时,我调用了一个api,并在响应时执行下面的代码 // Make a call to given phone number - (void)callPhoneNumber:(NSString *)phoneNumber { if (!self.webView) { webView = [[UIWebView alloc]
UIWebView
打电话。我尝试了下面的代码,如果我简单地放一个按钮,然后在下面的代码中单击“执行”,它就可以正常工作。但目前在点击按钮时,我调用了一个api,并在响应时执行下面的代码
// Make a call to given phone number
- (void)callPhoneNumber:(NSString *)phoneNumber
{
if (!self.webView)
{
webView = [[UIWebView alloc] init];
[self.view addSubview:self.webView];
self.webView.delegate = self;
}
// Remove non-digits from phone number
phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""];
// Make a call
NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phoneNumber]];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}
它甚至没有调用webview委托方法
原因可能是什么
请注意,我只想使用webview打电话,所以请不要建议使用本机联系人应用程序。使用webview可保持应用程序内的流量。通话结束时,用户仅在应用程序中。使用本机应用程序,如果用户想要返回到我的应用程序,用户必须手动打开该应用程序。要拨打电话号码,您必须拨打
-[UIApplication openURL:][/code>:
NSString *phoneNumber = @"+5512345678";
NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", phoneNumber]];
[[UIApplication sharedApplication] openURL:phoneNumberURL];
为什么不用这个
NSString *phoneNumberURL = [@"telprompt://" stringByAppendingString: phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumberURL]];
通话结束后,用户将自动返回应用程序。我希望这就是您希望使用webview实现的目标
如果要通过UIWebView调用,请使用以下示例:
+ (void)callWithString:(NSString *)phoneString
{
[self callWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneString]]];
}
+ (void)callWithURL:(NSURL *)url
{
static UIWebView *webView = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
webView = [UIWebView new];
});
[webView loadRequest:[NSURLRequest requestWithURL:url]];
}
您确定self.webView
已初始化吗
更改:webView=[[UIWebView alloc]init]代码>
到:self.webView=[[UIWebView alloc]init]代码>
这:[nsstringwithformat:@“tel:phoneNumber”]
不起作用;请尝试:[nsstringwithformat:@“tel:%@”,phoneNumber]
然而,就我个人而言,我从未尝试过用这种方式打电话。[nsurlRequestWithURL:url]
永远不会起作用。@Michael为什么它永远不会起作用?请查看我的答案。为什么要通过调用webview上的方法拨打该号码?它就是不这样工作。复制:@Michael它在其他控制器中工作。telprompt://
也不工作。但是tel://
确实会打电话。但这不是我想要的,因为它不要求确认。