|
1 | | -/** |
2 | | - * Copyright (c) Joseph P. Ferraro |
3 | | - * |
4 | | - * This source code is licensed under the MIT license found in the |
5 | | - * LICENSE file here: https://github.com/joeferraro/react-native-cookies/blob/master/LICENSE.md. |
| 1 | +/** |
| 2 | + * Copyright (c) Joseph P. Ferraro |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file here: https://github.com/joeferraro/react-native-cookies/blob/master/LICENSE.md. |
6 | 6 | */ |
7 | 7 |
|
8 | 8 | #import "RNCookieManagerIOS.h" |
@@ -181,22 +181,14 @@ -(NSString *)getDomainName:(NSURL *) url |
181 | 181 | if (useWebKit) { |
182 | 182 | if (@available(iOS 11.0, *)) { |
183 | 183 | dispatch_async(dispatch_get_main_queue(), ^(){ |
184 | | - WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore]; |
185 | | - [cookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *allCookies) { |
186 | | - for(NSHTTPCookie *currentCookie in allCookies) { |
187 | | - // Uses the NSHTTPCookie directly has no effect, nor deleted the cookie nor thrown an error. |
188 | | - // Create a new cookie with the given values and delete this one do the work. |
189 | | - NSMutableDictionary<NSHTTPCookiePropertyKey, id> *cookieData = [NSMutableDictionary dictionary]; |
190 | | - [cookieData setValue:currentCookie.name forKey:NSHTTPCookieName]; |
191 | | - [cookieData setValue:currentCookie.value forKey:NSHTTPCookieValue]; |
192 | | - [cookieData setValue:currentCookie.domain forKey:NSHTTPCookieDomain]; |
193 | | - [cookieData setValue:currentCookie.path forKey:NSHTTPCookiePath]; |
194 | | - |
195 | | - NSHTTPCookie *newCookie = [NSHTTPCookie cookieWithProperties:cookieData]; |
196 | | - [cookieStore deleteCookie:newCookie completionHandler:^{}]; |
197 | | - } |
198 | | - resolve(nil); |
199 | | - }]; |
| 184 | + // https://stackoverflow.com/questions/46465070/how-to-delete-cookies-from-wkhttpcookiestore#answer-47928399 |
| 185 | + NSSet *websiteDataTypes = [NSSet setWithArray:@[WKWebsiteDataTypeCookies]]; |
| 186 | + NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0]; |
| 187 | + [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes |
| 188 | + modifiedSince:dateFrom |
| 189 | + completionHandler:^() { |
| 190 | + resolve(nil); |
| 191 | + }]; |
200 | 192 | }); |
201 | 193 | } else { |
202 | 194 | reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); |
|
0 commit comments