XHR POST not working in iOS12 after using WKWebView

Hi! I’m having an issue on making POST XHR request when it’s accessed from iOS 12 but works fine with Android, Chrome and <= iOS 13. I’m already stuck on this problem for a day now and my deadline is getting nearer. I read a lot of article that this is about CORS in WKWebView but I already have my backend configured to:

allow_origin = ['*'];

Everytime I build the project and login it always returns me this 0 Unknown Error error:

{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":"https://test.dummy.com/api/auth_user/","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://test.dummy.com/api/auth_user/: 0 Unknown Error","error":{"isTrusted":true}}

Here’s my config.xml:

<platform name="ios">
    <feature name="CDVWKWebViewEngine">
        <param name="ios-package" value="CDVWKWebViewEngine" />
    <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
    <preference name="WKWebViewOnly" value="true" />

Here’s my package.json:

 "dependencies": {
    "@angular/common": "~9.1.6",
    "@angular/core": "~9.1.6",
    "@angular/forms": "~9.1.6",
    "@angular/platform-browser": "~9.1.6",
    "@angular/platform-browser-dynamic": "~9.1.6",
    "@angular/router": "~9.1.6",
    "@ionic-native/core": "^5.0.7",
    "@ionic-native/http": "^5.26.0",
    "cordova-ios": "^6.0.0",
    "cordova-plugin-advanced-http": "^2.5.1",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^4.2.1",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",

I’m using the HttpClient from @angular/common/http to fetch my resource. I’m fetching my resources from a service like this:

loginUser(credentials) {
    return this.http.post('https://test.dummy.com/api/auth_user/', credentials);

Thank you very much! :slight_smile:

Hello all,
I’m facing the same problem here. Did you @heyypatrick find any solutions for that ?

Hi @Aymane

I fixed this by using this Ionic native library instead of using Angular’s HTTPClientModule. You have to re-write all your code for server requests. I think the issue is connected with iOS’s deprecation for applications using UIWebView. For a short-term fix, you have to set the minimum iOS version to iOS13. :slight_smile: