Skip to content
This repository was archived by the owner on Jan 24, 2020. It is now read-only.

iOS fixes + cleanup #135

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 6 additions & 26 deletions ios/RNCookieManagerIOS/RNCookieManagerIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,7 @@ -(NSString *)getDomainName:(NSURL *) url
reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil);
}
} else {
NSMutableDictionary *cookies = [NSMutableDictionary dictionary];
for (NSHTTPCookie *c in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url]) {
NSMutableDictionary *d = [NSMutableDictionary dictionary];
[d setObject:c.value forKey:@"value"];
[d setObject:c.name forKey:@"name"];
[d setObject:c.domain forKey:@"domain"];
[d setObject:c.path forKey:@"path"];
[d setObject:[self.formatter stringFromDate:c.expiresDate] forKey:@"expiresDate"];
[cookies setObject:d forKey:c.name];
}
resolve(cookies);
resolve([self createCookieList:[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url]]);
}
}

Expand Down Expand Up @@ -230,21 +220,6 @@ -(NSString *)getDomainName:(NSURL *) url
}
}

RCT_EXPORT_METHOD(getAll:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSMutableDictionary *cookies = [NSMutableDictionary dictionary];
for (NSHTTPCookie *c in cookieStorage.cookies) {
NSMutableDictionary *d = [NSMutableDictionary dictionary];
[d setObject:c.value forKey:@"value"];
[d setObject:c.name forKey:@"name"];
[d setObject:c.domain forKey:@"domain"];
[d setObject:c.path forKey:@"path"];
[d setObject:[self.formatter stringFromDate:c.expiresDate] forKey:@"expiresDate"];
[cookies setObject:d forKey:c.name];
}
}

-(NSDictionary *)createCookieList:(NSArray<NSHTTPCookie *>*)cookies
{
NSMutableDictionary *cookieList = [NSMutableDictionary dictionary];
Expand All @@ -262,6 +237,11 @@ -(NSDictionary *)createCookieData:(NSHTTPCookie *)cookie
[cookieData setObject:cookie.name forKey:@"name"];
[cookieData setObject:cookie.domain forKey:@"domain"];
[cookieData setObject:cookie.path forKey:@"path"];

if (cookie.expiresDate) {
[cookieData setObject:[self.formatter stringFromDate:cookie.expiresDate] forKey:@"expiresDate"];
}

return cookieData;
}

Expand Down