0

如果链接被小 url 或类似的东西缩短,我怎样才能让这个功能工作?它似乎首先通过微型 url 服务器,从而导致无法读取与谷歌相关的关键字。

  -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest{ NSRange nameRange = [[inRequest.URL absoluteString] rangeOfString:@"google" options:NSCaseInsensitiveSearch];

if(nameRange.location == NSNotFound)
{
    [[UIApplication sharedApplication] openURL:[inRequest URL]];
    return NO;
}
return YES;
}
4

2 回答 2

0

你为什么不尝试删除if ( inType == UIWebViewNavigationTypeLinkClicked )条件,这样你就可以在 url 中抓住重定向。请参见下面的代码。

 -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    if ([[inRequest.URL absoluteString] rangeOfString:@"google"].location==NSNotFound){
    [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }
    return YES;
}
于 2013-03-12T17:08:12.960 回答
0

用这个

NSRange nameRange = [[inRequest.URL absoluteString] rangeOfString:@"google" options:NSCaseInsensitiveSearch];

            if(nameRange.location == NSNotFound)
            {
                [[UIApplication sharedApplication] openURL:[inRequest URL]];
                return NO;
            }
于 2013-03-12T17:12:51.293 回答