-
Notifications
You must be signed in to change notification settings - Fork 984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
breaking: Use WKURLSchemeHandler for serving app content #781
Conversation
I think You mentioned that it was implemented in the Maybe it could be placed in that file? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM. 👍
I tested:
cordova platform add
cordova build ios
- Tested with default
config.xml
- Tested with modified
config.xml
<platform name="ios">
<allow-navigation href="cdv://*" />
<preference name="scheme" value="cdv" />
<preference name="hostname" value="foobar" />
</platform>
- Tested with CORS request remote
- Tested with Fetch request remote
- Tested with Fetch request local file
You can rebase this PR with master and it should fix the failing tests now. I just merged in #782 which fixed the failing tests with the latest node. This will now unblock the reviewing/merging hold up. |
d1bf609
to
a334d24
Compare
/me bot did not see request but pre-confirmed, rebase complete. |
@@ -46,7 +46,7 @@ - (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName names | |||
- (void)parserDidStartDocument:(NSXMLParser*)parser | |||
{ | |||
// file: url <allow-navigations> are added by default | |||
self.allowNavigations = [[NSMutableArray alloc] initWithArray:@[ @"file://" ]]; | |||
self.allowNavigations = [[NSMutableArray alloc] initWithArray:@[ @"file://", @"app://" ]]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this "app://" scheme fixed? (In this case, do we expect that the user add allow-navigation
directive in config.xml in order to allow his own scheme?)
I think it is better to use [settings cordovaSettingForKey:@"scheme"];
here instead of fixed "app://", if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change the default by using the preference scheme
option. But if they change, the must add allow-navigation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I thought to only allow the default one, but we can easily allow the configured one without an additional allow-navigation, will change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the user can enter an invalid scheme (i.e. http, https, etc) that will default to "app", instead of reading directly from settings, I've created an appScheme
in the view controller and use that for allowing the navigation.
Is there an option to continue using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good!
It could be done, but I did it this way because in your proposal you said “Update to use Scheme Handlers with WKWebView.”, not “add an option to use Scheme Handlers” or something like that. Also we have dropped iOS 10 support because of that. |
BTW, you should be able to install cordova-plugin-wkwebview-engine and that should make your app use file instead of a custom scheme. |
@dpogue from your question/concern and @jcesarmobile response, is it OK to continue with merging this PR in? Or do you have other questions? Trying to get a status on this PR. |
Going to merge since there is no response In case we decide to add the file:// back as an option, it can be done in a separate PR, or cordova-plugin-wkwebview-engine can still be used |
Thanks for your work on this! |
Hello, Able to retrieve app contents from remote http web page. But not able to retrieve app contents from remote https web page. Can you please help me on this. |
Please go to Stack Overflow or Slack for questions. Issues and pullrequests are not for questions. |
@NiklasMerz okay sure. Thanks! |
How to display local images in application storage directory (e.g. file:///var/mobile/Applications//) after add |
Got a solution, #947 |
Hi with [email protected] I have set preferences with scheme: value="app" and hostname: value="localhost" because of which my origin in api calls is going as app:localhost resulting in cors issue i tried scheme: value="http" and hostname value="myDomain" expecting origin in api call as http:myDomain . But this is not working. Any suggestions would be appreciated :) Thanks !! |
Can I configure scheme & hostname like scheme as http & hostname as myDomain ? I tried but it still showed app:myDomain in origin while doing api calls. |
Please seek support via asking on StackOverflow or in our Slack community. |
No, there are reserved schemes that can not be used for example This information had also been written already in this PR. Please read the comments as well before asking. |
breaking because serving from a custom scheme makes the apps lose existing data (localStorage, etc)
Used app as default scheme, but I'm open to using cordova, cdv or any other.
The scheme is configurable with "scheme" preference, the hostname is configurable with "hostname" preference.
App will be loaded from "app://localhost"
If the scheme is changed, it has to be allowed with an allow-navigation entry, app is allowed on the default template.
Note that at the moment, loading file urls (in example, camera image in a src tag) won't work because of cross domain requests not allowed. What we did on ionic webview plugin was to create an utility function that converts file:// urls to app://localhost/ urls, but not sure how to do it here. Put it in cordova.js?
closes: #415