Search code examples
iosxcodecordovasession-cookiesios14

Cookies wont sync in iOS 14 + XCode 12 to Cordova main window when XHR calls made from nativeXHR or web proxy


I am using a Cordova based iOS app which uses HTTP Session cookies to maintain server session. Recently apple enforced ITP to iOS 14 apps built using XCode 12.3. So when we use XCode 12.x to build apps targeted for iOS 14, any XHR call to our server will be treated as third party call and all the session cookies are dropped from adding to webview. This completely broke our production app.

There are plugins like nativeXHR which works like a proxy and make API call in native. This works for XHR calls however, any Single Sign On operations which rely on cookies are now failing. I am trying to make a SSO based URL call on a inapp browser, but it fails as there are no authenticated cookies present in In app browser. Cookies stored in native cookieStore cannot be synced to cordova main window or to In app browser window

I tried implementing webproxy suggested by NiklasMerz in PR #1030 Cordova implementation, added proxy plugin and In app browser PR #825 to use same process pool. Still I am not able to sync cookies between native and Cordova web views.

I also tried adding app bound domains to my info.plist and added same WkWebViewData store across all web views as in WkProcessPool.

if (@available(iOS 14.0, *)) {
    configuration.limitsNavigationsToAppBoundDomains = YES;
    WKWebsiteDataStore *dStore =[[CDVWebViewProcessPoolFactory sharedFactory] sharedDataStore]; // I used a nonPersistant data store, but same object for all instances of webview
    configuration.websiteDataStore = dStore;
} else {
    // Fallback on earlier versions
}

All my efforts didn't work. Appreciate any help to identify the root cause for not able to sync cookies between nativeXHR/webproxy and cordova main webview.


Solution

  • Cookies started work after setting, however just works for ourdomain.com

    <preference name="scheme" value="https" />
    <preference name="hostname" value="ourdomain.com" />