Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ios/RNCookieManagerIOS/RNCookieManagerIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#endif

static NSString * const NOT_AVAILABLE_ERROR_MESSAGE = @"WebKit/WebKit-Components are only available with iOS11 and higher!";
static NSString * const INVALID_URL_MISSING_HTTP = @"Invalid URL: It may be missing a protocol (ex. http:// or https://).";

@implementation RNCookieManagerIOS

Expand Down Expand Up @@ -102,6 +103,11 @@ -(NSString *)getDomainName:(NSURL *) url
NSInteger maxLength = 2;

NSURLComponents *components = [[NSURLComponents alloc]initWithURL:url resolvingAgainstBaseURL:FALSE];

if ([components.host isEqual: @""] || components.host == nil) {
return nil;
}

NSArray<NSString *> *separatedHost = [components.host componentsSeparatedByString:separator];
NSInteger count = [separatedHost count];
NSInteger endPosition = count;
Expand All @@ -126,6 +132,11 @@ -(NSString *)getDomainName:(NSURL *) url
dispatch_async(dispatch_get_main_queue(), ^(){
NSString *topLevelDomain = [self getDomainName:url];

if (topLevelDomain == nil) {
reject(@"", INVALID_URL_MISSING_HTTP, nil);
return;
}

WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore];
[cookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *allCookies) {
NSMutableDictionary *cookies = [NSMutableDictionary dictionary];
Expand Down