When I want to get a specified cookie item which response by the server with WKWebview , I have met some trouble.
The Charles tool can view the cookie item in response,When I debug the app the Safari developer storage also can view the cookie item,But I can not use iOS function to get it. Here is some test.
WKHTTPCookieStore *cookieStore = self.webView.configuration.websiteDataStore.httpCookieStore;
[cookieStore getAllCookies:^(NSArray<NSHTTPCookie *> * Nonnull cookies) {
for (NSHTTPCookie *cookie in cookies) {
NSLog(@"CookieStore cookie name is %@",cookie.name);
}
}];
[[NSHTTPCookieStorage sharedHTTPCookieStorage].cookies enumerateObjectsUsingBlock:^(NSHTTPCookie * Nonnull obj, NSUInteger idx, BOOL * Nonnull stop) {
NSLog(@"NSHTTPCookieStorage cookie name is %@",obj.name);
}];
[self.webView evaluateJavaScript:@"document.cookie;" completionHandler:^(id Nullable ret, NSError * _Nullable error) {
NSLog(@"documents cookies is %@ error is %@",ret,error);
}];
All test log have no the cookie , If the 'WKHTTPCookieStore' or ' NSHTTPCookieStorage' are different with the Safari developer cookie storage ? If YES ,How can i get the cookie?
The Charles tool can view the cookie item in response,When I debug the app the Safari developer storage also can view the cookie item,But I can not use iOS function to get it. Here is some test.
WKHTTPCookieStore *cookieStore = self.webView.configuration.websiteDataStore.httpCookieStore;
[cookieStore getAllCookies:^(NSArray<NSHTTPCookie *> * Nonnull cookies) {
for (NSHTTPCookie *cookie in cookies) {
NSLog(@"CookieStore cookie name is %@",cookie.name);
}
}];
[[NSHTTPCookieStorage sharedHTTPCookieStorage].cookies enumerateObjectsUsingBlock:^(NSHTTPCookie * Nonnull obj, NSUInteger idx, BOOL * Nonnull stop) {
NSLog(@"NSHTTPCookieStorage cookie name is %@",obj.name);
}];
[self.webView evaluateJavaScript:@"document.cookie;" completionHandler:^(id Nullable ret, NSError * _Nullable error) {
NSLog(@"documents cookies is %@ error is %@",ret,error);
}];
All test log have no the cookie , If the 'WKHTTPCookieStore' or ' NSHTTPCookieStorage' are different with the Safari developer cookie storage ? If YES ,How can i get the cookie?