Reputation: 299
The InAppBrowser in Cordova 2.3.0 isn't loading URLs properly. I understand this has to do with the new method of whitelisted URLs and how they only apply to the main Cordova WebView and not plugins.
I've read an article on how to use your whitelist URLs for plugins, but it's very vague and I'm not sure where to add the code they suggest.
Instructions from Step 3 in above referenced link suggest:
Step 3). Network connections by plugins are no longer checked by the whitelist. To use the whitelist for your plugin network connections, you have to set the "User-Agent" header of your connection to the user-agent of the viewController.
`CDVViewController* vc = ((CDVViewController*)self.viewController);
NSString* userAgent = vc.userAgent;
// then set the User-Agent header of your network connection...`
The article does not say where to add this code. I'm assuming it goes in MainViewController.m, but I'm not sure. I've tried placing it in the init function in that file and it didn't work. I also don't know what they mean by "then set the User-Agent header of your network connection..." Where do I set this?
Has anyone had any success with this? If so, I would love some help. I'm really stuck here.
Thanks!
Upvotes: 3
Views: 4715
Reputation: 299
The reason I kept getting the webView:didFailLoadWithError was due to the URL being passed in without being encoded. A regular URL like google.com worked fine, but more complicated URL with params caused the load error. The work around for this is to encode the URL before calling window.open:
var URL = encodeURI(e.data.url);
var ref = window.open(URL, '_blank', 'location=yes');
This solved the problem using Cordova 2.5.
Upvotes: 1
Reputation: 1091
I posted this here:Phonegap/Cordova 2.3.0 iOS Whitelist Ignored
If you use storyboards. Add this to your MainViewController or your controller : CDVViewController
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
self = [self init];
}
return self;
}
Upvotes: 0
Reputation: 2511
This goes in the config.xml of your phonegap project.
Add the following tag in between the <cordova>
tag
<access origin="https://example.com" />
this tag allows any secure requests to example.com
Access elements control the Android whitelist. Domains are assumed blocked unless set otherwise
Upvotes: 0