From 3cebd8ea526b26635b14845bfa04c78cd61b83eb Mon Sep 17 00:00:00 2001 From: Nicolas Djambazian Date: Mon, 29 Oct 2018 12:18:41 +0100 Subject: [PATCH] Fixing subdomain issues #114 --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 25 +++------------------ 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index 47609f69..478c5e78 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -100,25 +100,6 @@ + (BOOL)requiresMainQueueSetup }]; } --(NSString *)getDomainName:(NSURL *) url -{ - NSString *separator = @"."; - NSInteger maxLength = 2; - - NSURLComponents *components = [[NSURLComponents alloc]initWithURL:url resolvingAgainstBaseURL:FALSE]; - NSArray *separatedHost = [components.host componentsSeparatedByString:separator]; - NSInteger count = [separatedHost count]; - NSInteger endPosition = count; - NSInteger startPosition = count - maxLength; - - NSMutableString *result = [[NSMutableString alloc]init]; - for (NSUInteger i = startPosition; i != endPosition; i++) { - [result appendString:separator]; - [result appendString:[separatedHost objectAtIndex:i]]; - } - return result; -} - RCT_EXPORT_METHOD( get:(NSURL *) url useWebKit:(BOOL)useWebKit @@ -128,13 +109,13 @@ -(NSString *)getDomainName:(NSURL *) url if (useWebKit) { if (@available(iOS 11.0, *)) { dispatch_async(dispatch_get_main_queue(), ^(){ - NSString *topLevelDomain = [self getDomainName:url]; - WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore]; + [cookieStore getAllCookies:^(NSArray *allCookies) { NSMutableDictionary *cookies = [NSMutableDictionary dictionary]; + for(NSHTTPCookie *currentCookie in allCookies) { - if([currentCookie.domain containsString:topLevelDomain]) { + if ([url.host containsString:currentCookie.domain]) { [cookies setObject:currentCookie.value forKey:currentCookie.name]; } }