我正在使用适用于 ios 的 Cordova/phonegap 框架在 xcode 中构建一个应用程序,该框架显示一些 html,其中包含一些嵌入的 youtube 播放器代码。iOS 在点击此 youtube 播放器时似乎会将用户重定向到 youtube 应用程序。在科尔多瓦 1.5.0 中,以下代码有效,但在 1.6.1 中似乎没有。任何想法为什么或需要改变什么才能让它发挥作用?
阻止 youtube 打开的代码和行为自我的链接
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
NSString* urlString = [url absoluteString];
if([urlString rangeOfString:@"http://www.youtube.com/embed"].location != NSNotFound) {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
else if (([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"])) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
}