【问题标题】:stop youtube videos opening youtube app in xcode/cordova 1.6.1停止在 xcode/cordova 1.6.1 中打开 youtube 应用程序的 youtube 视频
【发布时间】:2012-05-02 10:42:00
【问题描述】:

我正在使用适用于 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 ];
    }
}

【问题讨论】:

    标签: ios xcode cordova youtube


    【解决方案1】:

    我会在方法的开头为 url 登录,然后在 if/elseif/else 的每个子句中添加一个日志语句,这样你就可以看到被拦截的 url 以及该方法对每个 URL 的作用.

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

    【讨论】:

      【解决方案2】:

      看看http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html 这可能会有所帮助。

      它说要这样做:

      NSString *htmlString = @"<html><head>
      <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head>
      <body style=\"background:#F00;margin-top:0px;margin-left:0px\">
      <div><object width=\"212\" height=\"172\">
      <param name=\"movie\" value=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param>
      <param name=\"wmode\" value=\"transparent\"></param>
      <embed src=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"
      type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"212\" height=\"172\"></embed>
      </object></div></body></html>";
      
      [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.your-url.com"]];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-20
        • 2015-06-29
        • 1970-01-01
        • 2011-01-08
        • 2011-10-04
        • 2012-05-08
        • 1970-01-01
        • 2016-03-23
        相关资源
        最近更新 更多