DataDetectorTypes telephone line problem

this is a reformulation of this question

When I set myWebView.dataDetectorTypes = UIDataDetectorTypeNone; telephone links (in the href html tag) are processed like this:

alt text

How can I handle phone links using the shouldStartLoadWithRequest delegate method instead ?

+3
source share
1 answer

I have not yet found the cause of the problem, but found a solution.

Instead of writing phone links in anchors like tel: myphonenumber, I write allo: myphonenumber.

shouldStartLoadWithRequest. allo: tel: NSURLRequest .

, :

- (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

Source: https://habr.com/ru/post/1726969/


All Articles