I'm building an app that will access a specific user's YouTube uploads. For this, I'm using Google's GData Objective-C client library. I use it to get access to the user's uploads feed and return an NSArray of GDataEntryYouTubeVideos. Using GDataEntryYouTubeVideo's htmlLink method, I load the url into a UIWebView with some special HTML code. However, the UIWebView just shows a red page.
The url that htmlLink returns is an https. When I manually replace https with http, the video loads in the UIWebView as expected. The following code does not load the YouTube video:
- (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];
}
The html code in htmlString is from this blog post on YouTube's API blog.
If I replace the htmlLinkString creation line with this:
NSString *htmlLinkString = [[[youTubeVideo HTMLLink] href] stringByReplacingOccurrencesOfString:@"https://" withString:@"http://"];
then the UIWebView properly loads the video.
I'm not sure what I'm missing here. Do I need to do something more in order to load an https url into a UIWebView? Or is there something I'm missing in the GData library that returns a standard non-secure URL?