From 5d54969674d2754e931dc1da90dda67b9bb1b337 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 3 Jul 2019 14:35:02 +0200 Subject: [PATCH 1/2] Fix clearAll(useWebKit = true) --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 23 +++++++-------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index 47609f69..eb9de5b1 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -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 *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 *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); }); } else { reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); From c0bfc05829a9e7774994c21abdd658a52e91ce74 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 15 Jul 2019 13:29:17 +0200 Subject: [PATCH 2/2] Resolve promise in completionHandler --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index eb9de5b1..ee49641a 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -171,9 +171,10 @@ -(NSString *)getDomainName:(NSURL *) url NSSet *websiteDataTypes = [NSSet setWithArray:@[WKWebsiteDataTypeCookies]]; NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0]; [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes - modifiedSince:dateFrom - completionHandler:^{}]; - resolve(nil); + modifiedSince:dateFrom + completionHandler:^() { + resolve(nil); + }]; }); } else { reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil);