我在网络视图中有这个bool功能,检查关键字“youtube”,如果链接中有关键字“youtube”,它将在应用网页视图而不是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;
}
答案 0 :(得分:1)
您可以使用knowurl服务从微小缩短的链接
扩展原始网址- (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;
}
}