I tried to implement the solution he provided and it worked for my server. But this isnât the all solution for my app because Iâm also using the Yelp V3 API which doesnât allow *.
To solve the same issue while debugging in the browser, I was using the Ionic proxy. For that reason I thought that this could also solve the issue while using WKWebView, but it turns out that the Ionic proxy on iOS doesnât work while using WKWebView or I donât know how to set up the Ionic proxy while running iOS.
Do someone noticed the same behavior? Has someone a solution to use a proxy while using WKWebView in a Ionic2 project?
thx. already got that in my index.html file. doesnât worked.
WKWebView only allow âAccess-Control-Allow-Origin: *â in header which is not usable und unfortunately this configuration doesnât changed it.
I think that the use of a proxy would solve it. But the Ionic proxy, if Iâm not wrong, only work for browser use (ionic serve). Or maybe there is a way to âincludeâ it in a build?
Thx for the hints. Youâre right, Cordova and wkwebview doesnât seems really mature right now and that CORS limitation is a little bit driving me crazy.
In the other hand, once I installed everything, I tweaked temporarily my server with CORS: * and tried my app on my iPhone 4s (iOS 9) and Iâve to say that the performance were better. Maybe not once every views are loaded but at least at the first load of each view, it was really an improvement in loading time, that was quite visual.
Thatâs why I still donât totally gave up the idea of adding the wkwebview support ⌠but if a next beta of Ionic2 will improve loading time, that wonât be necessary
Cors issue are now partially solved in the WkWebView.
With partially I mean that CORS issue with your own server could be solved (add ionic.local or http://localhost:8080) to your CORS header.
If you use third party services which doesnât accept CORS requests, the only solution, I guess, is to route these queries to your own backend as a middlepoint which reroute then these requests to the third party services you want to use.
It is not a silver bullet. Using XLMHttpRequest directly without Http service still doesnât work. But solves my problems, may be it could be helpful for you.
On your repo I see following line :
âEven though there is a way to solve CORS issue without changing serverâs response header by using Cordova HTTP pluginâ
Would you mind giving me some direction on how to do this? I assume the idea is to use this plugin as a proxy but I am not sure how to implement it in order to bypass CORS restriction. I donât have control of the backed. If you have any resource I can use that will really help.
@sneas Thank you very much for the plugin. I have integrated it and doesnât have any problem with CORS but occasionally I am getting error message on âtoo many http redirectsâ. Do you have any clue? I am also using the HttpInterceptor together with this.
The error is triggered by Cordova plugin (https://github.com/silkimen/cordova-plugin-advanced-http) which is being used by ionic-native-http-connection-backend library to perform requests. And apparently itâs being caused by cyclic redirection on server. Does the app work correctly in browser when cordova plugin is disabled?
Btw removing Cordova plugin is not necessary. ionic-native-http-connection-backend automatically falls back to XmlHttpRequest usage when app runs in browser.