Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-在UIWebView中处理重定向_Ios_Objective C_Uiwebview - Fatal编程技术网

iOS-在UIWebView中处理重定向

iOS-在UIWebView中处理重定向,ios,objective-c,uiwebview,Ios,Objective C,Uiwebview,我在web视图中有一个bool函数,它可以检查关键字“youtube”,如果链接中有关键字“youtube”,它将在应用程序web视图中打开,而不是在safari中打开。这是正确的,但我遇到了一个问题。如果youtube链接被缩短,它将在safari中打开。有没有办法防止这种情况。我仍然需要在safari中打开除youtube之外的所有其他关键字 -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest

我在web视图中有一个bool函数,它可以检查关键字“youtube”,如果链接中有关键字“youtube”,它将在应用程序web视图中打开,而不是在safari中打开。这是正确的,但我遇到了一个问题。如果youtube链接被缩短,它将在safari中打开。有没有办法防止这种情况。我仍然需要在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;
}
您可以使用该服务从微小的缩短链接扩展原始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;
     }    
}

我知道的唯一方法是手动检查链接的重定向(例如NSURLConnection)。