Unable to use under WKWebView
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[x] feature request
Current behavior
When running it in an ionic app using the cordova-plugin-wkwebview-engine plugin which switches the rendering engine from UIWebWiew to WKWebView I get the following error:
XMLHttpRequest cannot load file:///Users/arroyo/Library/Developer/CoreSimulator/Devices/75D80D9A-1804-4F70-A65F-648A7DCDEE51/data/Containers/Bundle/Application/305DDE17-69E4-4CDA-B7AB-49C0CEED9F6B/AstroPrint.app/www/assets/i18n/config.json. Cross origin requests are only supported for HTTP.
Expected/desired behavior
The config.json can be read without using XMLHttpRequest.
Reproduction of the problem
What is the expected behavior?
The error does not happen.
What is the motivation / use case for changing the behavior?
Using WKWebView is much faster in iOS. Current my project can’t migrate there because of this error.
Please tell us about your environment:
- ng2-translate version: 3.1.x
- Angular version: 2.0.0
- Browser: [ iOS 10 WKWebView ]
- Language: [ TypeScript 2.0]
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (1 by maintainers)
Top GitHub Comments
This plugin seemed to fix my issues: github.com/oracle/cordova-plugin-wkwebview-file-xhr No loader required
Basically it allows file:// paths in wkwebview as far as I can understand.
I google a lot and finally got the ngx-translate to work: First, upgrade cordova and ionic cli to latest version
`xxx:Tabs u$ cordova -v 7.1.0
xxx:Tabs u$ ionic -v 3.16.0
xxx:Tabs u$ ionic info
cli packages: (/Users/xxx/NPM/lib/node_modules)
global packages:
local packages:
System:
Environment Variables:
Misc:
create a brand new project
The new project will use wkwebview as default, and there are some error with the usage docs: https://ionicframework.com/docs/developer-resources/ng2-translate/ we should use HttpClientModule instead of HttpModule For the app.module.ts
For app.component.ts
After that, create i18n folder in src/assets create en.json { “HELLO” : “hello” }
For page usage, you can use pipe
or manually:
Hope you save your life with these code.