Skip to content
This repository has been archived by the owner on Jan 24, 2020. It is now read-only.

Fix clearAll(useWebKit = true) #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions ios/RNCookieManagerIOS/RNCookieManagerIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,13 @@ -(NSString *)getDomainName:(NSURL *) url
if (useWebKit) {
if (@available(iOS 11.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^(){
WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore];
[cookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *allCookies) {
for(NSHTTPCookie *currentCookie in allCookies) {
// Uses the NSHTTPCookie directly has no effect, nor deleted the cookie nor thrown an error.
// Create a new cookie with the given values and delete this one do the work.
NSMutableDictionary<NSHTTPCookiePropertyKey, id> *cookieData = [NSMutableDictionary dictionary];
[cookieData setValue:currentCookie.name forKey:NSHTTPCookieName];
[cookieData setValue:currentCookie.value forKey:NSHTTPCookieValue];
[cookieData setValue:currentCookie.domain forKey:NSHTTPCookieDomain];
[cookieData setValue:currentCookie.path forKey:NSHTTPCookiePath];

NSHTTPCookie *newCookie = [NSHTTPCookie cookieWithProperties:cookieData];
[cookieStore deleteCookie:newCookie completionHandler:^{}];
}
resolve(nil);
}];
// https://stackoverflow.com/questions/46465070/how-to-delete-cookies-from-wkhttpcookiestore#answer-47928399
NSSet *websiteDataTypes = [NSSet setWithArray:@[WKWebsiteDataTypeCookies]];
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes
modifiedSince:dateFrom
completionHandler:^{}];
resolve(nil);
Copy link

@tyleralves tyleralves Jul 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to put resolve(nil) within the completion handler of WKWebsiteDataStore::defaultDataStore so that it doesn't resolve prior to the cookies being deleted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Implemented in c0bfc05.

});
} else {
reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil);
Expand Down