Last active
September 21, 2021 19:58
-
-
Save tigi44/9957190bd326b6e3e8608c34e37810fa to your computer and use it in GitHub Desktop.
[iOS, Objective-c] WebView Cookies (WKWebView, UIWebView)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get WKWebview Cookies (then set cookies to a request) | |
if (@available(iOS 11.0, *)) { | |
[WKWebsiteDataStore.defaultDataStore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *aCookies) { | |
NSMutableURLRequest *sRequest = [NSMutableURLRequest requestWithURL:sURL]; | |
NSDictionary *sCookieHeaderFields = [NSHTTPCookie requestHeaderFieldsWithCookies:aCookies]; | |
[sRequest setAllHTTPHeaderFields:sCookieHeaderFields]; | |
}]; | |
} | |
if (@available(iOS 11.0, *)) { | |
[self.webView.configuration.websiteDataStore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *aCookies) { | |
NSMutableURLRequest *sRequest = [NSMutableURLRequest requestWithURL:sURL]; | |
NSDictionary *sCookieHeaderFields = [NSHTTPCookie requestHeaderFieldsWithCookies:aCookies]; | |
[sRequest setAllHTTPHeaderFields:sCookieHeaderFields]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment