0
votes

I'm building an app which mainly displays public data from a website. A few items require authentication to read. I don't want to recreate the entire website in the app so I'd like to have the user log in via a web view or browser popup and grab the cookie containing the token from this session. I would then use it to authenticate my in-app rest calls in order to fetch the data. This should work on iOS and Android but I couldn't come up with a functioning solution yet. How would one read and write cookies from the phone browser / webview? I'm using the latest Angular (9) and NativeScript.

1

1 Answers

0
votes

For android

The webview UI

  <WebView height="1200px" src="https://www.nativescript.org"
    (loadFinished)="onLoadFinished($event)"></WebView>

The typescript code

  import * as application from 'application';
  declare const android;

  ....
  ....
  ....

  onLoadFinished(args: LoadEventData) {
    android.webkit.CookieManager.getInstance().getCookie(<cookie name>)
    android.webkit.CookieManager.getInstance().setCookie(<cookie name>, <cookie value>)
  }

For IOS seems it is little bit complicated

Refer StackOverflow set cookie in IOS nativescript