wendux / DSBridge-IOS

:earth_asia: A modern cross-platform JavaScript bridge, through which you can invoke each other's functions synchronously or asynchronously between JavaScript and native.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to synchronize cookie between native and DWKWebView ?

wendux opened this issue · comments

commented

There are two ways to do this:

  1. With JavaScript

    NSString * script=@"document.cookie=\"uname=xx; uid=34\"";
    [dwebview evaluateJavaScript:script completionHandler:nil];
  2. With fly.js

    Actually, fly.js can't support synchronizing Cookies between native and DWKWebView, but it supports forwarding the http request to Native through any Javascript bridge, and fly.js has already provide the dsBridge adapter. Suppose that all HTTP requests will be sent out on native side, there's no longer need to sync Cookies to DWKWebView. all you need to do is implementing a API named onAjaxRequest in default API namespace :

    /**
     * Note: This method is for Fly.js
     * In browser, Ajax requests are sent by browser, but Fly can
     * redirect requests to native, more about Fly see  https://github.com/wendux/fly
     * @param requestInfo passed by fly.js, more detail reference https://wendux.github.io/dist/#/doc/flyio-en/native
     */
    -(void)onAjaxRequest:(NSDictionary *) requestInfo  :(void (^)(NSString * _Nullable result,BOOL complete))completionHandle{
       
    }

    More details please refer to:

    1. https://wendux.github.io/dist/#/doc/flyio-en/redirect
    2. https://wendux.github.io/dist/#/doc/flyio-en/native