ios - 停止 youtube 视频在 xcode/cordova 1.6.1 中打开 youtube 应用程序

标签 ios xcode cordova youtube

我正在使用适用于 ios 的 Cordova/phonegap 框架在 xcode 中构建一个应用程序,它显示一些 html,其中包含一些嵌入的 youtube 播放器代码。 iOS 似乎在点击此 youtube 播放器时将用户重定向到 youtube 应用程序。在 cordova 1.5.0 中,以下代码有效,但在 1.6.1 中似乎无效。有什么想法为什么需要改变或需要改变什么才能让它发挥作用吗?

阻止 youtube 打开的代码和行为 self 的链接

- (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 ];
    }
}

最佳答案

我会在该方法的开头放置 logging for url,然后在 if/elseif/else 的每个子句中添加一个日志语句,这样您就可以看到哪些 url 被拦截以及该方法对每个 url 做了什么.

也许 youtube 请求的字符串不再匹配硬编码的“http://www.youtube.com/embed”?值得一看。

关于ios - 停止 youtube 视频在 xcode/cordova 1.6.1 中打开 youtube 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10253120/

相关文章:

node.js - Ionic2 安装后的 Ionic 安装

ios - CDVURLProtocol - 触发 ajax 调用时未执行 startLoading 方法

ios - 从字符串中取回日期

iphone - NSPredicate 不工作

php - 将数据从 php 导入 tableview 的最佳方法

ios - 调用 navigationController popViewControllerAnimated 时不调用 viewController 的 dealloc

ios - 快速向左或向右滑动

ios - 在 Swift 中调试时 Xcode 崩溃

ios - 使用 Google Maps SDK for iOS Ver.1.9.0 提交我的应用程序时出现警告

javascript - Cordova/Phonegap 在主 Cordova webview 中加载外部站点