Last active
January 16, 2019 11:01
-
-
Save marcel-ploch/4f3d60a46738aa87f4e3d396f122e5f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../../../../references.d.ts" /> | |
import {Injectable} from '@angular/core'; | |
import * as application from 'application'; | |
import {WebViewHeader} from './webview-header.abstract.service'; | |
declare const android; | |
@Injectable() | |
export class AndroidWebviewHeader extends WebViewHeader { | |
constructor() { | |
super(); | |
} | |
/** | |
* Set the cookie header for the webview | |
* @param header | |
* @param url | |
*/ | |
public setHeader(header: string, url: string): void { | |
try { | |
const localAndroidApp: any = application.android; | |
// Native CookieSyncManager for Android | |
const cookieSyncManager: any = android.webkit.CookieSyncManager.createInstance(localAndroidApp.context); | |
// Native cookieManager for Android | |
const cookieManager: any = android.webkit.CookieManager.getInstance(); | |
const splittedHeader: Array<string> = header.split(';'); | |
cookieManager.removeSessionCookie(); | |
cookieManager.setCookie(this._betCommunityStore.getActiveBetCommunity().url, `${splittedHeader[0]};${splittedHeader[1]};${splittedHeader[2]};`); | |
cookieManager.setAcceptCookie(true); | |
cookieManager.flush(); | |
cookieSyncManager.sync(); | |
} catch (error) { | |
console.log(error.message); | |
} | |
} | |
/** | |
* Removes the current cookie header | |
*/ | |
public removeHeader(): void { | |
const localAndroidApp: any = application.android; | |
const cookieSyncManager: any = android.webkit.CookieSyncManager.createInstance(localAndroidApp.context); | |
const cookieManager: any = android.webkit.CookieManager.getInstance(); | |
cookieManager.removeSessionCookie(); | |
cookieManager.setCookie(this._betCommunityStore.getActiveBetCommunity().url, ``); | |
cookieManager.flush(); | |
cookieSyncManager.sync(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where to get the webview-header.abstract.service file?