Stop YouTube video opening YouTube application in xcode / cordova 1.6.1

I am creating an application in xcode using the Cordova / phonegap framework for ios, which displays some html that has YouTube player code embedded in it. IOS seems to redirect the user to the youtube app when it hits this player. The following code worked in cordov 1.5.0, but in 1.6.1 it does not look. Any ideas why or what needs to be changed to make it work?

to stop youtube opening and links to yourself.

- (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 ];
    }
}
+3
source share
2 answers

logging url , if/elseif/else, , URL- .

, youtube "http://www.youtube.com/embed"? .

0

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"]];
0

All Articles