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

查看:93
本文介绍了在应用程序外部加载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视频网址一样简单:

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天全站免登陆