Search code examples
ioscordova

Cordova GET request looses server-side cookie on IOS


We are running a Cordova App which works perfectly fine except for GET requests on IOS. In this scenario, the session cookies won't be transferred to the server. Usually, we use POST requests for our rest api calls. Exceptions are images which we load via GET requests. Therefore, authorized users won't be recognized as logged-in by the server when loading images.

Everything works perfectly when running the webapp oon the browser on the same device. Also, there are no problems on android. My guess is that because of the different http method, the webview chooses to not use the same cookies. This might be related to the cordova whitelist plugin which is now deprecated.

The cookie is being generated on the server on login.

Cordova/plugin versions:

"cordova-ios": "^6.2.0",
"cordova-plugin-splashscreen": "^6.0.0",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-plugin-vibration": "^3.1.1",
"cordova-plugin-wkwebview-engine": "^1.2.2",
"cordova-plugin-wkwebview-file-xhr": "^3.0.0",
"ios": "^0.0.1"

Cordova ios preferences:

<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />
<preference name="WKWebViewOnly" value="true" />

Solution

  • There are a few things you need to fix. Both these plugins are now obsolete with cordova-ios 6+

    "cordova-plugin-wkwebview-engine": "^1.2.2",
    "cordova-plugin-wkwebview-file-xhr": "^3.0.0"
     
    

    This is also obsolete

    <preference name="WKWebViewOnly" value="true" />
    

    By default the webview is now WKwebview so you don't need the xhr plugin and the plugin you use is then also obsolete. Remove them and add instead cordova-plugin-ios-xhr

    Then go from there, hope this helps