这是我做过的最令人沮丧的事情。我有一个 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
感谢您的关注