2

我在 web 视图中有这个 bool 函数来检查关键字“youtube”,如果链接中有关键字“youtube”,它将在应用程序 web 视图而不是 safari 中打开。这工作正常,但有一个问题,我碰到了。如果 youtube 链接被https://bitly.com/缩短,它将在 safari 中打开。有没有办法防止这种情况。我仍然需要https://bitly.com/在 safari 中为除 youtube 之外的所有其他关键字打开。

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

1 回答 1

1

您可以使用knowurl服务从微小的缩短链接扩展原始 URL

- (BOOL)webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType 
 {
      @try
         {
           BOOL _returnVal = YES;

          //convert your bitly url to KowUrl if its contains `bit.ly`

          if ( inType == UIWebViewNavigationTypeLinkClicked ) 
          {
              if ([[inRequest.URL absoluteString] rangeOfString:@"youtube"].location==NSNotFound)
              {
                 [[UIApplication sharedApplication] openURL:[inRequest URL]];
                 _returnVal =  NO;
              }
           }
      }
      @catch (NSException *exception)
      {
         NSLog(@"%s\n exception: Name- %@ Reason->%@", __PRETTY_FUNCTION__,[exception name],[exception reason]);
      }
     @finally
     {
       return loadedImages;
     }    
}
于 2013-03-11T20:09:24.290 回答