2

キーワード「youtube」をチェックするこのbool関数がWebビューにあり、リンクにキーワード「youtube」がある場合、サファリではなくアプリのWebビューで開きます。これは正しく機能しますが、問題がありますに走った。youtube のリンクをhttps://bitly.com/で短縮するとサファリで開きます。これを防ぐ方法はありますか。YouTube を除く他のすべてのキーワードをサファリで開くには、まだhttps://bitly.com/が必要です。

-(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 に答える