2013-03-07 91 views
0

我想在Safari瀏覽器中顯示我的網頁視圖中打開某些鏈接。這是我迄今爲止的代碼。網絡視圖在某些關鍵字的Safari瀏覽器中打開鏈接

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType { 
if (inType == UIWebViewNavigationTypeLinkClicked) { 
    [[UIApplication sharedApplication] openURL:[inRequest URL]]; 
    return NO; 
} 
return YES; 
} 

問題是我想只打開Safari瀏覽器,如果鏈接包含關鍵字「谷歌」。有關如何做的任何提示?

回答

1

您可以檢查這個樣子,它會達到目的

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType { 
    if (inType == UIWebViewNavigationTypeLinkClicked) { 
     if ([[inRequest.URL absoluteString] rangeOfString:@"google" options:NSCaseInsensitiveSearch].location!=NSNotFound){ 
     [[UIApplication sharedApplication] openURL:[inRequest URL]]; 
     return NO; 
     } 
    } 
return YES; 
} 
+0

酷,如果我想的相反說在Safari中打開的所有鏈接除非谷歌的關鍵字我切換返回值的權利。如果([[inRequest.URL absoluteString] rangeOfString:@「google」]。位置== NSNotFound){} – 2013-03-07 22:33:27

+0

)然後從檢查 – nsgulliver 2013-03-07 22:34:13

+0

取出'!' shouldStartLoadWithRequest:(的NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)法菜單{ 如果(法菜單== UIWebViewNavigationTypeLinkClicked){ 如果([[inRequest.URL absoluteString] rangeOfString:@ 「谷歌」]。位置== NSNotFound){ [[ UIApplication sharedApplication] openURL:[inRequest URL]]; return NO; } } return YES; } – nsgulliver 2013-03-07 22:34:43

相關問題