我正在构建一个带有 UIWebView 的应用程序。
webView 应该加载包含 tel: 链接的 html:
<a href="tel:123456789">call me</a>
webView 不会使“呼叫我”链接成为可点击的。
我试过了
webView.dataDetectorTypes = UIDataDetectorTypePhoneNumber
但不起作用。
我查看了所有的 stackOverflow Q&A,并没有找到特定于这个问题的答案。
谢谢你的帮助,努尔
代替
<a href="tel:123456789"> call me </a>
和
<a href="tel://123456789">call me</a>
希望对你有效。
下面的代码对我有用
添加网页视图
web = [[UIWebView alloc] initWithFrame:WEBVIEW_FRAME];
web.dataDetectorTypes = UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber;
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"new" ofType:@"html"] isDirectory:NO]];
web.delegate =self;
[self.view addSubview:web];
和委托方法
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if ([url.scheme isEqualToString:@"tel"])
{
[[UIApplication sharedApplication] openURL:url];
}
}
和我的 html 文件
<html>
<head>
<h1>HTML PAGE</h1>
</head>
<a href="tel:123456789"> call me </a>
</html>