Commit 0c921ce0 authored by laurent l's avatar laurent l

add custom webview to sync ios cookies before webview creation

parent c4d52fc2
......@@ -22,6 +22,7 @@ import {
import { RadSideDrawer } from 'nativescript-ui-sidedrawer';
import { WebView } from 'ui/web-view';
import { OAuthWebViewClient } from './utils/oauth-webview-client';
import { MbaWebView } from './utils/mba-web-view';
import * as LocalNotifications from "nativescript-local-notifications";
import * as imageSource from "tns-core-modules/image-source";
......
import { WebView } from 'ui/web-view'
export class MbaWebView extends WebView {
}
export class MbaWebView extends WebView {
}
import { WebView } from 'ui/web-view'
import { Cookies } from '../../models/';
export class MbaWebView extends WebView {
createNativeView() {
const jScript = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'initial-scale=1.0'); document.getElementsByTagName('head')[0].appendChild(meta);";
const wkUScript = WKUserScript.alloc().initWithSourceInjectionTimeForMainFrameOnly(jScript, WKUserScriptInjectionTime.AtDocumentEnd, true);
const wkUController = WKUserContentController.new();
wkUController.addUserScript(wkUScript);
let websiteDataStore = WKWebsiteDataStore.nonPersistentDataStore();
new Cookies().getCookies().forEach((cookie) => {
websiteDataStore.httpCookieStore.setCookieCompletionHandler(cookie, () => { });
});
const configuration = WKWebViewConfiguration.new();
configuration.websiteDataStore = websiteDataStore;
configuration.userContentController = wkUController;
configuration.preferences.setValueForKey(
true,
"allowFileAccessFromFileURLs"
);
return new WKWebView({
frame: CGRectZero,
configuration: configuration
});
}
}
......@@ -2,15 +2,7 @@ import { WebView } from 'ui/web-view'
export class Cookies {
public syncHttpToWebView(webview: WebView): Promise<any> {
let promises: Array<Promise<any>>;
promises = this.getCookies().map((cookie) => {
return new Promise((resolve, reject) => {
webview.ios.configuration.websiteDataStore.httpCookieStore.setCookieCompletionHandler(cookie, resolve);
})
})
return Promise.all(promises);
return Promise.resolve()
}
......
<Page xmlns:nsDrawer="nativescript-ui-sidedrawer" xmlns:shared="views/shared" loaded="{{ onWebsitePageLoaded }}">
<Page xmlns:nsDrawer="nativescript-ui-sidedrawer"
xmlns:mwv="controllers/utils/mba-web-view"
xmlns:shared="views/shared" loaded="{{ onWebsitePageLoaded }}">
<Page.actionBar>
<ActionBar title="{{ page_title }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goBack }}"/>
......@@ -18,7 +20,7 @@
<nsDrawer:RadSideDrawer.mainContent>
<GridLayout columns="*" rows="*" iosOverflowSafeArea="false">
<WebView id="webView" height="100%" col="0" row="0"/>
<mwv:MbaWebView id="webView" height="100%" col="0" row="0"/>
<ActivityIndicator id="activity-indicator" color="orange" col="0" row="0" />
</GridLayout>>
</nsDrawer:RadSideDrawer.mainContent>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment