【发布时间】:2011-09-21 15:12:21
【问题描述】:
我正在构建一个可以访问特定用户的 YouTube 上传内容的应用。为此,我使用了 Google 的 GData Objective-C 客户端库。我使用它来访问用户的上传提要并返回 GDataEntryYouTubeVideos 的 NSArray。使用 GDataEntryYouTubeVideo 的 htmlLink 方法,我使用一些特殊的 HTML 代码将 url 加载到 UIWebView 中。但是,UIWebView 只是显示一个红色页面。
htmlLink 返回的 url 是 https。当我手动将 https 替换为 http 时,视频会按预期加载到 UIWebView 中。以下代码不会加载 YouTube 视频:
- (void)viewDidLoad
{
[super viewDidLoad];
GDataServiceGoogleYouTube *youtubeService = [[GDataServiceGoogleYouTube alloc] init];
NSURL *uploadUrl = [GDataServiceGoogleYouTube youTubeURLForUserID:@"higaara" userFeedID:kGDataYouTubeUserFeedIDUploads];
void(^handler)(GDataServiceTicket *ticket, GDataFeedBase *feed, NSError *error) = ^(GDataServiceTicket *ticket, GDataFeedBase *feed, NSError *error)
{
NSLog(@"handler");
// Get the link from the youtube entry
GDataEntryYouTubeVideo *youTubeVideo = [feed firstEntry];
NSString *htmlLinkString = [[youTubeVideo HTMLLink] href];
// Create an html string to load into the web view
NSString *htmlString = [NSString stringWithFormat:@"<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=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed
src=\"%@\"type=\"application/x-shockwave-flash\" wmode=\"transparent\"
width=\"212\" height=\"172\"></embed></object></div></body></html>",
htmlLinkString, htmlLinkString];
NSURL *tempurl = [NSURL URLWithString:@"http://onnati.net/apptrap"];
[webView loadHTMLString:htmlString tempurl];
};
[youtubeService fetchFeedWithURL:uploadUrl completionHandler:handler];
}
htmlString 中的 html 代码来自 YouTube 的 API 博客上的 blog post。
如果我用这个替换 htmlLinkString 创建行:
NSString *htmlLinkString = [[[youTubeVideo HTMLLink] href] stringByReplacingOccurrencesOfString:@"https://" withString:@"http://"];
然后 UIWebView 正确加载视频。
我不确定我在这里缺少什么。 我需要做更多的事情才能将 https url 加载到 UIWebView 中吗? 或者我在 GData 库中缺少返回标准非安全 URL 的东西?
【问题讨论】:
-
这也发生在我身上。但仅适用于 iOS
-
我在 iOS 4 上也遇到了这个问题 - 还没有解决。不过,iOS 5 及更高版本运行良好。
-
关注这篇文章的信息:stackoverflow.com/questions/1779511/…
标签: ios youtube-api gdata-api