Created
June 12, 2012 19:22
-
-
Save robcolburn/2919562 to your computer and use it in GitHub Desktop.
How to open only some urls in WebView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
From @craigpfau - http://craigpfau.com/2012/02/phonegap-ios-uiwebview-and-safari-app-links/ | |
To just enable UIWebView for the single URL I used this code [projectFolder > Classes > MainViewController.m] | |
*/ | |
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType | |
{ | |
NSURL *url = request.URL; | |
if ([url.absoluteString rangeOfString:@"URLToOpenInUIWebView.com"].location != NSNotFound) { | |
return YES; | |
} | |
else { | |
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType]; | |
} | |
} |
Author
robcolburn
commented
Jun 14, 2012
via email
Hi Nate,
Unfortunately, I haven't used 1.7, so I'm not sure exactly what you'll need
to modify there. You might try Craig's original snippet though (it's the
initial commit to this gist). Note that he's modifying a different source
file.
##
Robert Wayne Colburn
Hey - I tried using Craigs old script and that didn't work. So then I updated cordova to 8.1 and now I am getting these warnings:
'UIViewController' may not respond to 'webView.shouldStartLoadWithRequest:navigationType:
I'm really racking my brain, tried pretty much everything imaginable to fix this issue. Any help you can provide would be GREATLY appreciated. Thanks!
Odd man, not sure. I'd try this.
- Fire up X-Code, and make a fresh PhoneGap in the normal way. As you normally would, set the whitelist to *, keep that option to open all whitelisted links in view turned off..
- Set up an index with some trivial content.
<body>
<p><a href="http://www.google.com" target="_blank">1. Googe</a></p>
<p><a href="http://www.yahoo.com" target="_blank">2. Yahoo</a></p>
</body>
- Then make the revision in this gist, changing "URLToOpenInUIWebView.com" to "google.com".
- That should make it so Google opens in the view, and Yahoo in Safari.
Once you've got that working, try to figure out what's different in your app.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment