6
6
*/
7
7
8
8
#import " RNCookieManagerMacOS.h"
9
- #if __has_include("RCTConvert.h")
10
- #import " RCTConvert.h"
11
- #else
12
9
#import < React/RCTConvert.h>
13
- #endif
14
10
15
- static NSString * const NOT_AVAILABLE_ERROR_MESSAGE = @" WebKit/WebKit-Components are only available with macOS 10.2 and higher!" ;
11
+ static NSString * const NOT_AVAILABLE_ERROR_MESSAGE = @" WebKit/WebKit-Components are only available with macOS 10.13 and higher!" ;
16
12
static NSString * const INVALID_URL_MISSING_HTTP = @" Invalid URL: It may be missing a protocol (ex. http:// or https://)." ;
17
13
static NSString * const INVALID_DOMAINS = @" Cookie URL host %@ and domain %@ mismatched. The cookie won't set correctly." ;
18
14
@@ -47,7 +43,8 @@ + (BOOL)requiresMainQueueSetup
47
43
cookie:(NSDictionary *)props
48
44
useWebKit:(BOOL )useWebKit
49
45
resolver:(RCTPromiseResolveBlock)resolve
50
- rejecter:(RCTPromiseRejectBlock)reject) {
46
+ rejecter:(RCTPromiseRejectBlock)reject)
47
+ {
51
48
NSHTTPCookie *cookie;
52
49
@try {
53
50
cookie = [self makeHTTPCookieObject: url props: props];
@@ -58,7 +55,7 @@ + (BOOL)requiresMainQueueSetup
58
55
}
59
56
60
57
if (useWebKit) {
61
- if (@available (macOS 10.2 , *)) {
58
+ if (@available (macOS 10.13 , *)) {
62
59
dispatch_async (dispatch_get_main_queue (), ^(){
63
60
WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore ] httpCookieStore ];
64
61
[cookieStore setCookie: cookie completionHandler: ^() {
@@ -113,7 +110,7 @@ + (BOOL)requiresMainQueueSetup
113
110
rejecter:(RCTPromiseRejectBlock)reject)
114
111
{
115
112
if (useWebKit) {
116
- if (@available (macOS 10.2 , *)) {
113
+ if (@available (macOS 10.13 , *)) {
117
114
dispatch_async (dispatch_get_main_queue (), ^(){
118
115
NSString *topLevelDomain = url.host ;
119
116
@@ -152,7 +149,7 @@ + (BOOL)requiresMainQueueSetup
152
149
rejecter:(RCTPromiseRejectBlock)reject)
153
150
{
154
151
if (useWebKit) {
155
- if (@available (macOS 10.2 , *)) {
152
+ if (@available (macOS 10.13 , *)) {
156
153
dispatch_async (dispatch_get_main_queue (), ^(){
157
154
// https://stackoverflow.com/questions/46465070/how-to-delete-cookies-from-wkhttpcookiestore#answer-47928399
158
155
NSSet *websiteDataTypes = [NSSet setWithArray: @[WKWebsiteDataTypeCookies ]];
@@ -186,7 +183,7 @@ + (BOOL)requiresMainQueueSetup
186
183
NSMutableArray <NSHTTPCookie *> * foundCookiesList = [NSMutableArray new ];
187
184
188
185
if (useWebKit) {
189
- if (@available (macOS 10.2 , *)) {
186
+ if (@available (macOS 10.13 , *)) {
190
187
dispatch_async (dispatch_get_main_queue (), ^(){
191
188
NSString *topLevelDomain = url.host ;
192
189
@@ -230,7 +227,7 @@ + (BOOL)requiresMainQueueSetup
230
227
rejecter:(RCTPromiseRejectBlock)reject)
231
228
{
232
229
if (useWebKit) {
233
- if (@available (macOS 10.2 , *)) {
230
+ if (@available (macOS 10.13 , *)) {
234
231
dispatch_async (dispatch_get_main_queue (), ^(){
235
232
WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore ] httpCookieStore ];
236
233
[cookieStore getAllCookies: ^(NSArray <NSHTTPCookie *> *allCookies) {
@@ -340,4 +337,14 @@ -(NSDictionary *)createCookieData:(NSHTTPCookie *)cookie
340
337
return cookieData;
341
338
}
342
339
340
+ -(BOOL )isMatchingDomain : (NSString *)originDomain
341
+ cookieDomain : (NSString *)cookieDomain
342
+ {
343
+ if ([originDomain isEqualToString: cookieDomain]) {
344
+ return @YES ;
345
+ }
346
+ NSString *parentDomain = [cookieDomain hasPrefix: @" ." ] ? cookieDomain : [@" ." stringByAppendingString: cookieDomain];
347
+ return [originDomain hasSuffix: parentDomain];
348
+ }
349
+
343
350
@end
0 commit comments