Here’s the solution that allows the session cookie to be set and sent back to the server in future request headers, which allows the Security Provider to function properly.
This plugin needs to be added to the project: ‘cordova-plugin-wkwebview-inject-cookie’.
Once that’s been added, you need to implement it by adding the following JavaScript to your ‘index.js’ file, just before the app is initialised:
document.addEventListener('deviceready', () => {
wkWebView.injectCookie('domain.com/path');
console.log('Ready');
});
You then need to add this code to the ‘CDVWKWebViewEngine.m’ file that’s installed by the ‘cordova-plugin-wkwebview-engine’ plugin:
@try {
[configuration.preferences setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
}
@catch (NSException *exception) {}
@try {
[configuration setValue:@TRUE forKey:@"allowUniversalAccessFromFileURLs"];
}
@catch (NSException *exception) {}
It needs to be added inside ‘createConfigurationFromSettings’, just before the configuration is returned.
If you’re using PhoneGap Build, this won’t be included when it installs ‘cordova-plugin-wkwebview-engine’, so you’ll need to add this plugin instead: ‘cordova-plugin-wkwebviewxhrfix’.
You then need to add this to your app’s ‘config.xml’ file, to stop WKWebView from using iCloud storage:
preference name="BackupWebStorage" value="local"
That’s it!