2013-03-12 90 views
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; 
} 
+0

你想..你想,当我们得到谷歌则开什么http://www.google.com – Rajneesh071 2013-03-12 17:01:07

+0

没有,当点击时,“谷歌”这个关键字来了它应该能够识别它并在Web视图中的实际应用程序中打开它的链接。如果没有关键字“谷歌”,那么它会打开Safari浏览器。但是,当谷歌链接被小网址等缩短时,不会发生这种情况。 – 2013-03-12 17:04:10

+0

检查我的答案,你能提供NSLog的[inRequest.URL absoluteString] – Rajneesh071 2013-03-12 17:23:26

回答

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; 
} 
0

使用此

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

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

对不起,迟到的回应。我更新了我的代码,似乎并未在safari中打开任何其他关键字链接。 – 2013-03-12 17:44:17