UIWebView doesn't detect phone number links

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 11:11:51

问题


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


回答1:


replace

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

with

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

Hope it works for you.




回答2:


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>


来源:https://stackoverflow.com/questions/11430058/uiwebview-doesnt-detect-phone-number-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!