How to synchronize cookie between native and DWKWebView ?
wendux opened this issue · comments
There are two ways to do this:
-
With JavaScript
NSString * script=@"document.cookie=\"uname=xx; uid=34\""; [dwebview evaluateJavaScript:script completionHandler:nil];
-
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: