iosuiwebviewnsstringanonymize

How to retrieve a clicked link in iOS


For security reasons, I used to use an anonymizer on mobile safari. However It was a bit annoying. If I searched for something and clicked on a link, then google returns an error message. You can try.. http://proxy2974.my-addr.org/myaddrproxy.php/http/www.google.com.au/ (search for something and click on a link -- it works fine if you test it on desktop browsers.. however it will return http://proxy2974.my-addr.org/myaddrproxy.php/http/url if you try it on iPhone or iPhone simulator)

So I decided to make my own. What I am doing is to get the URL from the text field and pass it through the anonymizer's link like urlString = [NSString stringWithFormat:@"http://proxy2974.my-addr.org/myaddrproxy.php/http/%@", urlString];

However I am still facing the same problem.. When I click on a link on google, it returns an error.. So what I want to do is to get the clicked link, stop loading the page (before it returns an error), then pass it through the anonymizer.. How can I do that? Thanks..

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

    NSLog(@"req: %@",request.URL.absoluteString);


    return YES;
}

req: http://proxy2974.my-addr.org/url?sa=t&source=web&cd=1&ved=0CFMQFjAA&url=%2Fmyaddrproxy.php%2Fhttp%2Fwww.perthnow.com.au%2Ffun-games%2Fleft-brain-vs-right-brain%2Fstory-e6frg46u-1111114517613&ei=GXAsUMaUA7H44QTys4HYDA&usg=AFQjCNGB_zOrrEZC0SKx813XGHB1xi_AlA

req: http://proxy2974.my-addr.org/myaddrproxy.php?proxy_url_sjla67z78f8viz4=url&sa=t&source=web&cd=1&ved=0CFMQFjAA&url=%2Fmyaddrproxy.php%2Fhttp%2Fwww.perthnow.com.au%2Ffun-games%2Fleft-brain-vs-right-brain%2Fstory-e6frg46u-1111114517613&ei=GXAsUMaUA7H44QTys4HYDA&usg=AFQjCNGB_zOrrEZC0SKx813XGHB1xi_AlA

req: http://proxy2974.my-addr.org/myaddrproxy.php/http/url

Solution

  • Implement this delegate method to retrieve a clicked link in UIWebView:

    - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
    {
      if(navigationType == UIWebViewNavigationTypeLinkClicked)
      {
         NSLog(@"req: %@",request.URL.absoluteString);
      }
    }