0

我正在尝试在我的 web 视图中打开某些链接,这些链接将在 safari 中显示。这是我到目前为止的代码。

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

问题是如果链接包含关键字“google”,我只想打开 safari。关于做什么的任何提示?

4

1 回答 1

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;
}
于 2013-03-07T22:22:14.310 回答