From 9cde059e24a89165c0f621e73a8b254e53d6b943 Mon Sep 17 00:00:00 2001 From: James Gestier Date: Mon, 6 Jun 2022 12:12:25 +1000 Subject: [PATCH 1/3] Modified how webkit cookies are deleted in the clearAll method as previous implementation did not always delete all webkit cookies. --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index 0e76dba..d59b7d6 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -151,14 +151,15 @@ + (BOOL)requiresMainQueueSetup if (useWebKit) { if (@available(iOS 11.0, *)) { dispatch_async(dispatch_get_main_queue(), ^(){ - // 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(@(YES)); - }]; + [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:WKWebsiteDataStore.allWebsiteDataTypes + completionHandler:^(NSArray * _Nonnull records) { + [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:WKWebsiteDataStore.allWebsiteDataTypes + forDataRecords:records + completionHandler:^{ + resolve(@(YES)); + } + ]; + }]; }); } else { reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); From 508cf854e5ff552cc8abd99c21472f662ccab7bd Mon Sep 17 00:00:00 2001 From: James Gestier Date: Mon, 6 Jun 2022 14:46:30 +1000 Subject: [PATCH 2/3] Further changes to only remove cookies from the website datastore. --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index d59b7d6..7718def 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -153,7 +153,8 @@ + (BOOL)requiresMainQueueSetup dispatch_async(dispatch_get_main_queue(), ^(){ [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:WKWebsiteDataStore.allWebsiteDataTypes completionHandler:^(NSArray * _Nonnull records) { - [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:WKWebsiteDataStore.allWebsiteDataTypes + NSSet *cookieDataType = [NSSet setWithArray:@[ WKWebsiteDataTypeCookies ]]; + [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:cookieDataType forDataRecords:records completionHandler:^{ resolve(@(YES)); From 364fa0e6f47cb1c8cdeb3ee394262c735e5cacac Mon Sep 17 00:00:00 2001 From: James Gestier Date: Mon, 6 Jun 2022 15:43:22 +1000 Subject: [PATCH 3/3] Modified to only retrieve cookie website data from the website data store when clearing webkit cookies. --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index 7718def..d15854e 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -151,7 +151,8 @@ + (BOOL)requiresMainQueueSetup if (useWebKit) { if (@available(iOS 11.0, *)) { dispatch_async(dispatch_get_main_queue(), ^(){ - [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:WKWebsiteDataStore.allWebsiteDataTypes + NSSet *dataTypesToRetrieve = [NSSet setWithArray:@[ WKWebsiteDataTypeCookies ]]; + [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:dataTypesToRetrieve completionHandler:^(NSArray * _Nonnull records) { NSSet *cookieDataType = [NSSet setWithArray:@[ WKWebsiteDataTypeCookies ]]; [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:cookieDataType