From 570ef45dda7fce28c7cc3d9d3976ef53f8c70932 Mon Sep 17 00:00:00 2001 From: w Date: Thu, 26 Apr 2018 18:40:43 +0800 Subject: [PATCH] Set cookie from cookiesWithResponseHeaderFields --- ios/RCTWKWebView/RCTWKWebView.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ios/RCTWKWebView/RCTWKWebView.m b/ios/RCTWKWebView/RCTWKWebView.m index e5b73277..72853cc9 100644 --- a/ios/RCTWKWebView/RCTWKWebView.m +++ b/ios/RCTWKWebView/RCTWKWebView.m @@ -360,6 +360,18 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView #pragma mark - WKNavigationDelegate methods +- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler { + if (_sendCookies) { + NSHTTPURLResponse *response = (NSHTTPURLResponse *)navigationResponse.response; + NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:response.URL]; + for (NSHTTPCookie *cookie in cookies) { + [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie]; + } + } + + decisionHandler(WKNavigationResponsePolicyAllow); +} + #if DEBUG - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposit ion, NSURLCredential * _Nullable))completionHandler { NSURLCredential * credential = [[NSURLCredential alloc] initWithTrust:[challenge protectionSpace].serverTrust];