首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >dataDetectorTypes电话链接问题

dataDetectorTypes电话链接问题
EN

Stack Overflow用户
提问于 2009-12-31 10:37:57
回答 1查看 5.8K关注 0票数 3

这是对this question的重新表述

当我设置myWebView.dataDetectorTypes =UIDataDetectorTypeNone时,电话链接(在html标记中)的处理方式如下:

如何使用shouldStartLoadWithRequest委托方法处理电话链接?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-01-18 11:05:32

我还没有找到问题的原因,但我找到了解决办法。

我写的不是像这个电话号码这样的锚中的电话链接,而是写allo:myphonenumber。

因此,调用shouldStartLoadWithRequest方法。我可以在我的NSURLRequest对象中替换allo: by tel:。

编辑,这是代码:

代码语言:javascript
复制
- (BOOL)webView:(UIWebView *)webView
    shouldStartLoadWithRequest:(NSURLRequest *)request
     navigationType:(UIWebViewNavigationType)navigationType; {

      NSURL *requestURL = [[ request URL] retain];
      // Check to see what protocol/scheme the requested URL is.

      if ( 
          // ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] ) &&
          ( navigationType == UIWebViewNavigationTypeLinkClicked )
          ) {

        // Stats
        [self recordTouch: [self tagToZone:[[webView superview] tag]]];

        // Substitution allo -> tel
        NSURL *newURL = [[NSURL alloc] initWithString: [[[request URL] absoluteString] stringByReplacingOccurrencesOfString: @"allo:" withString: @"tel:"]];
        [requestURL release];

        //return YES;

        // Launch
        return ![ [ UIApplication sharedApplication ] openURL: [newURL autorelease]];
      }

      // Auto release
      [requestURL release];
      return YES;
    }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1984883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档