3

It seems everyone knows about the dumb little but in PhoneGap that doesn't allow you to have iFrames in your application. There are a number of fixes out there but they are either for legacy versions of PhoneGap, don't work or cause other issues. Here is what I have tried so far:

  1. OpenAllWhitelistURLsInWebView

  2. http://craigpfau.com/2012/02/phonegap-ios-uiwebview-and-safari-app-links/

  3. How can I open an external link in Safari not the app's UIWebView?

Nothing seems to work. Here is what I'm trying to accomplish:

  1. Video embeds from vimeo (iframe) stay in app, externalhosts: vimeo.com a.vimeocdn.com b.vimeocdn.com
  2. All other links go out to safari

Here are my app details:

ios 5.1.1 | Cordova 1.7.0 | JqueryMobile | Jquery 1.7.1

Community
  • 1
  • 1
nate8684
  • 539
  • 1
  • 9
  • 27
  • I am not sure how much it will help but I have a sample application using Cordova 1.7 in iOS 5 running fine with Vimeo - https://github.com/dhavaln/cordova-examples/tree/master/ios-cordova-video – dhaval Jun 14 '12 at 17:41
  • Do you have other link with the app that link out to safari? I'm able to get the video to embed, however then all my links launch within my program instead of calling up safari... – nate8684 Jun 14 '12 at 17:48
  • yes i could do that, i have updated the above github project with the changes – dhaval Jun 14 '12 at 19:19

1 Answers1

7

I have a sample application here which does open the Vimeo video inside the app but opens the other urls in Safari.

I changed the below function in MainViewController.m

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = [request URL];
    NSString *host = [request.URL host];

    if(host != NULL || host != nil){
        if ([host rangeOfString:@"vimeo.co"].location != NSNotFound) {
            return YES;
        }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 ];
            }
        }
    }

    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
dhaval
  • 7,611
  • 3
  • 29
  • 38
  • Thanks for the post. Do you know if this will work in Cordova 1.8.1? I pasted it in and have two warnings: Unused variable 'result' & control may reach end of non-void function...thoughts? – nate8684 Jun 14 '12 at 19:50
  • 1
    i m using cordova 1.7.1 so not sure how this will work in 1.8.1, also i have fixed the warnings – dhaval Jun 14 '12 at 19:52
  • 1
    Oh Man...after countless of tried solutions, this one FINALLY works! Thanks you so much for solving this headache. I do still have the two warnings, should I worry about them? Is apple going to not approve my because of them? Let me know, thanks again! – nate8684 Jun 14 '12 at 19:58
  • 1
    please update the warning code from the above code, i have fixed that in the above code snippet – dhaval Jun 14 '12 at 19:59
  • Yep, sorry commented afterwords. Your fixes work. Thanks you so much, can't really say how much you just helped me out! – nate8684 Jun 14 '12 at 20:01
  • Hey, quick question. My (maps://maps.google.com) map links don't seem to be working now. Could that little fix have caused issues with those links? If so, how could I fix the issue? – nate8684 Jun 15 '12 at 14:03
  • I can't even get the map to open in safari. It launches the maps program (ios) and then doesn't pin the location. Thoughts? – nate8684 Jun 15 '12 at 14:47
  • it is difficult to say what could be the issue, can you checkout my source from github and check in it, may be something missed – dhaval Jun 15 '12 at 15:07
  • I started a new project without your script and I'm having the same issues. See here: http://stackoverflow.com/questions/11055492/problems-with-ios-map-links – nate8684 Jun 15 '12 at 17:30
  • I tried putting the same urls in my setup and it worked. I have committed fresh code to github, can you take update and check again. – dhaval Jun 15 '12 at 17:44
  • I pasted your revised code (not exactly sure what changed), but it still doesn't pin the location on the map. Launches map, but doesn't pan and pin location. This is what i get in my log: – nate8684 Jun 15 '12 at 17:56
  • AppDelegate::shouldStartLoadWithRequest: Received Unhandled URL maps://maps.google.co.uk/?q=loc:OxfordSt,+Westminster,+LondonW1&sll=51.514958,-0.144463 – nate8684 Jun 15 '12 at 17:56
  • Sorry, was looking at the wrong code. That did work, is there an easy way to pull that code needed for the maps link. I had something similar in my link but yours is much more detailed. Where did you pull that from? – nate8684 Jun 15 '12 at 19:37
  • The actual link http://www.google.com/maps?q=2392+Mount+Joy+Road,+Manheim,+PA&hl=en&sll=37.0625,-95.677068&sspn=55.806079,113.90625&oq=2392+Mount+Joy+Ra&t=h&hnear=2392+Mt+Joy+Rd,+Manheim,+Pennsylvania+17545&z=17 ... – nate8684 Jun 15 '12 at 19:53
  • from your recent question http://stackoverflow.com/questions/11055492/problems-with-ios-map-links – dhaval Jun 15 '12 at 19:54
  • Thanks for this solution. I had a problem getting it to work, took some time to figure out that adding player.vimeo.com to the External hosts list in Cordova.plist is not enough, also had to add a.vimeocnd.com and *.google-analytics.com. * will also work of course... Thanks! – Overbeeke Nov 13 '12 at 09:28
  • When i put the video in fullscreen when holding the device in landscape-modus, the device acts like it is in portrait when returning from fullscreen. Does anyone have a clue? – Overbeeke Nov 13 '12 at 09:31