在应用程序之外加载 YouTube [英] Load YouTube outside Application

查看:30
本文介绍了在应用程序之外加载 YouTube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 UIWebView 显示包含 YouTube 缩略图的页面.当我点击它时,它会在应用程序中加载它,但我希望它在 YouTube 应用程序的应用程序之外加载.如何做到这一点?

I have a simple UIWebView showing a page including YouTube thumbnail. When I click it, it loads it inside the application, but I want it to be loaded outside application in the YouTube-app. How can this be done?

谢谢.

推荐答案

应该像这样加载 YouTube-video-url 一样简单:

It should be as simple as loading the YouTube-video-url like this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=abcde12345"]];

它不能在模拟器中工作,因为它没有 YouTube 应用程序,但它可以在 iPhone 上工作(我希望,未经测试).

It won't work in the simulator because it doesn't have the YouTube-app, but it will work on the iPhone (i hope, untested).

(我也看到你的接受率很低,你应该点击你认为是最佳答案的答案旁边的小✔.这样,想知道同样事情的人可以找到最有用的答案快速回答,发布答案的人将获得认可.)

下面是一个示例,说明您可以采取哪些措施来捕获 YouTube 网址并在 YouTube 应用中而不是在您的应用中打开它们:

Here is an example of what you could do to catch the YouTube-urls and opening them in the YouTube-app instead of in your app:

- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    // Determine if we want the system to handle it.
    NSURL *url = request.URL;
    if ([url.host isEqual:@"youtube.com"] && ([url.query rangeOfString:@"watch"] != 0)) {
        if ([[UIApplication sharedApplication]canOpenURL:url]) {
            [[UIApplication sharedApplication]openURL:url];
            return NO;
        }
    }
    return YES;
}

这未经测试,但应该可以工作:)

This is not tested, but should work :)

这篇关于在应用程序之外加载 YouTube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆