UIWebView doesn't detect phone number links

2019-05-18 12:49发布

I'm building an app with a UIWebView in it.

The webView should load html that includes tel: links:

<a href="tel:123456789">call me</a>

The webView doesn't make the "call me" link to be clickable.

I tried

webView.dataDetectorTypes = UIDataDetectorTypePhoneNumber

But doesn't work.

I looked in all the stackOverflow Q&A's and found no answer specific to this problem.

Thanks for your help, Nur

2条回答
在下西门庆
2楼-- · 2019-05-18 13:30

Below code worked for me

Add the web view

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

and the delegate method

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
                                            navigationType:(UIWebViewNavigationType)navigationType
{
     if ([url.scheme isEqualToString:@"tel"])
     {
         [[UIApplication sharedApplication] openURL:url];
     }
}

and my html file

  <html>
  <head>
  <h1>HTML PAGE</h1>
  </head>
  <a href="tel:123456789"> call me </a>
  </html>
查看更多
We Are One
3楼-- · 2019-05-18 13:31

replace

<a href="tel:123456789"> call me </a>

with

<a href="tel://123456789">call me</a>

Hope it works for you.

查看更多
登录 后发表回答