2013-03-12 91 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