UIWebView在iPhone上的手机链接检测 [英] UIWebView phone links detection on iphone

查看:129
本文介绍了UIWebView在iPhone上的手机链接检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中有一些奇怪的东西。我肯定忘记了什么,但我不知道什么。我尝试在UIWebView中处理电话,短信mailto和http链接。

there is something strange in my code. I'm sure to forget something but i don't know what. I try to handle phone, sms mailto and http links in an UIWebView.

这是我如何尝试:

1 /实例化UIWebView:

1/ instantiate the UIWebView :

webview = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)]; 
webview.opaque = NO;
webview.backgroundColor = [UIColor clearColor];
webview.userInteractionEnabled = YES;
webview.dataDetectorTypes = UIDataDetectorTypeAll;

2 /设置适当的委托:

2/ set the appropriate delegate :

[webview setDelegate: self];

3 /实现委托方法(简化版本):

3/ implement the delegate method (simplified version here) :

- (BOOL)webView:(UIWebView *)webView
 shouldStartLoadWithRequest:(NSURLRequest *)request
  navigationType:(UIWebViewNavigationType)navigationType; {

  NSURL *requestURL = [[ request URL] retain];
  NSLog(@">>> %@", [requestURL scheme]);
  [requestURL release];
  return YES;
}

使用我的调试设备,当我触摸http链接时,会打印NSLog。当我触摸一个电话链接,我有这样的确认消息:

With my debug device when i touch an http link, the NSLog is printed. When i touch a tel link i have this kind of confirmation message :

使用iPhone模拟器,NSLog可以正确打印tel和http链接。

With the iPhone Simulator, tel and http links are correctly printed by NSLog.

推荐答案

现在任何人都可以这样做:

For anyone looking at this now, this will do it:

self.webView.dataDetectorTypes = UIDataDetectorTypeNone;

这篇关于UIWebView在iPhone上的手机链接检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆