从UIWebView在Safari中打开(使用youtube.com)

时间:2013-01-24 20:32:26

标签: javascript ios uiwebview youtube

这是我曾经遭遇过的最不幸的事情。我有一个UIWebView。它转到http://m.youtube.com。我希望我按下的任何后续链接然后发送到Safari,而不是UIWebView。简单吧?这是你一遍又一遍找到的代码:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {

        [[UIApplication sharedApplication] openURL:request.URL];
        return NO;
    }

    return YES;
}

但这不起作用。所以我将UIWebViewNavigationTypeLinkClicked更改为UIWebViewNavigationTypeOther。当视图加载时,这会在Safari中立即打开。再也不是我想要的。所以我这样做了:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if (navigationType == UIWebViewNavigationTypeOther) {

        NSLog(@"It works!");

//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[urlArr objectAtIndex:indexPath.row]]];
       return YES;
   }

   return NO;
}

检查后续点击是否经过这里,但他们没有。日志只显示“它有效!”当视图最初加载时。任何后续点击都不会显示任何内容。

所以我一直在寻找一个URL更改和Javascript更改,但仍然没有。还有什么我可以做的吗?

(顺便提一下,我应该提一下,这个代码可以在任何其他网站上运行,比如stackoverflow.com - 任何后续链接点击,我都会被带到Safari。它只适用于YouTube)< /强>

当我按下youtube上的链接时,这是我从日志中获得的信息:

2013-01-24 21:08:25.886 HatFilms[30079:c07] [MPAVController] Autoplay: Enabling autoplay
2013-01-24 21:08:25.886 HatFilms[30079:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2013-01-24 21:08:25.887 HatFilms[30079:c07] setting movie path: http://r1---sn-5n3-n1qe.c.youtube.com/videoplayback?mv=m&mt=1359061639&ms=au&yms=Ag6pZvjqA20&source=youtube&key=yt1&el=watch&upn=g2ConWh5QJ0&id=201015c58a31c984&cp=U0hUTlBTVF9LS0NONF9ITVhCOlhkN3FFcm5zWDY5&ip=31.205.57.12&newshard=yes&fexp=909714%2C901802%2C919358%2C914066%2C916625%2C902534%2C920704%2C912806%2C922403%2C922405%2C929901%2C913605%2C925710%2C929104%2C920201%2C913302%2C919009%2C911116%2C926403%2C910221%2C901451&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&sver=3&expire=1359086161&dnc=1&app=youtube_mobile&ratebypass=yes&itag=18&signature=A434075DABFEBB44E5F0588B7430D04A931684B0.648F49C3F4D254E29B970A6AA68BAC1C08280B97&ipbits=8
2013-01-24 21:08:25.887 HatFilms[30079:c07] [MPAVController] Autoplay: Enabling autoplay
2013-01-24 21:08:25.895 HatFilms[30079:c07] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0

如果我记录UIWebView收到的所有内容:

2013-01-24 21:50:31.642 HatFilms[30372:c07] [MPAVController] Autoplay: Enabling autoplay
2013-01-24 21:50:31.642 HatFilms[30372:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2013-01-24 21:50:31.642 HatFilms[30372:c07] setting movie path: http://r1---sn-5n3-n1qe.c.youtube.com/videoplayback?expire=1359086161&key=yt1&sver=3&app=youtube_mobile&el=watch&signature=44DA69CF58A649EAA813EE2A8E91B38BB164CB9D.2DA718585DEDB6F55E4ABBDD247602E713981C83&source=youtube&upn=3Qgzgd7FAjY&newshard=yes&ratebypass=yes&ipbits=8&itag=18&yms=Ag6pZvjqA20&fexp=909714%2C901802%2C919358%2C914066%2C916625%2C902534%2C920704%2C912806%2C922403%2C922405%2C929901%2C913605%2C925710%2C929104%2C920201%2C913302%2C919009%2C911116%2C926403%2C910221%2C901451&ip=31.205.57.12&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&cp=U0hUTlBTVF9LS0NONF9ITVhCOlhkN3FFcm5zWDY5&dnc=1&id=201015c58a31c984&mv=m&mt=1359064215&ms=au
2013-01-24 21:50:31.643 HatFilms[30372:c07] [MPAVController] Autoplay: Enabling autoplay
2013-01-24 21:50:31.646 HatFilms[30372:c07] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2013-01-24 21:50:32.333 HatFilms[30372:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2013-01-24 21:50:32.349 HatFilms[30372:c07] [MPAVController] Autoplay: _streamLikelyToKeepUp: 0 -> 1
2013-01-24 21:50:32.350 HatFilms[30372:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2013-01-24 21:50:32.768 HatFilms[30372:c07] [MPAVController] Autoplay: Enabling autoplay
2013-01-24 21:50:32.786 HatFilms[30372:c07] [MPAVController] Autoplay: Enabling autoplay

感谢您寻找

0 个答案:

没有答案