0
ログインページを読み込むWKWebViewがあります。ログインに成功した後に設定された "iPlanetDirectoryPro"クッキー(下図参照)です。だから、別のWKWebViewで使用するために保存しようとしています。面白いのは "sharedHTTPCookieStorage"には "iPlanetDirectoryPro"以外のCookieが含まれています。WKWebViewからクッキーを取得する方法
- は、共有proccessプールを作成し、この最初のWKWebViewと私は「iPlanetDirectoryProで」を使用しようとしている1のために同じ設定を使用:私がこれまで試したどのような
。
私はクッキーを取得するためにdecidePolicyForNavigationResponseこのデリゲートメソッドを使用:
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{ 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); }
のWebViewのJavaScriptのコマンドdocument.cookieを評価します。