From 1fe3ba2dfd86650aaefa68196ecc4a0e48b2ddca Mon Sep 17 00:00:00 2001 From: Marc Shilling Date: Wed, 6 Jun 2018 16:14:30 -0400 Subject: [PATCH 1/3] Send the cookie's expiration date in getAll response --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index 11a38abd..62bb1f5b 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -104,12 +104,15 @@ @implementation RNCookieManagerIOS rejecter:(RCTPromiseRejectBlock)reject) { NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSMutableDictionary *cookies = [NSMutableDictionary dictionary]; + NSDateFormatter *formatter = [NSDateFormatter new]; + [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"]; 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:[formatter stringFromDate:c.expiresDate] forKey:@"expiresDate"]; [cookies setObject:d forKey:c.name]; } resolve(cookies); From 99755036a07dbf72b88f17e6c34125641a5970a6 Mon Sep 17 00:00:00 2001 From: Marc Shilling Date: Thu, 14 Jun 2018 10:37:22 -0400 Subject: [PATCH 2/3] expose expireDates and other properties in the get() method as well --- ios/RNCookieManagerIOS/RNCookieManagerIOS.h | 2 ++ ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 27 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.h b/ios/RNCookieManagerIOS/RNCookieManagerIOS.h index 185af88f..f0504d63 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.h +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.h @@ -7,4 +7,6 @@ @interface RNCookieManagerIOS : NSObject +@property (nonatomic, strong) NSDateFormatter *formatter; + @end diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index 62bb1f5b..0032b99b 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -7,6 +7,21 @@ @implementation RNCookieManagerIOS +- (instancetype)init +{ + self = [super init]; + if (self) { + self.formatter = [NSDateFormatter new]; + [self.formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"]; + } + return self; +} + ++ (BOOL)requiresMainQueueSetup +{ + return NO; +} + RCT_EXPORT_MODULE() RCT_EXPORT_METHOD(set:(NSDictionary *)props @@ -73,7 +88,13 @@ @implementation RNCookieManagerIOS rejecter:(RCTPromiseRejectBlock)reject) { NSMutableDictionary *cookies = [NSMutableDictionary dictionary]; for (NSHTTPCookie *c in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url]) { - [cookies setObject:c.value forKey:c.name]; + 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); } @@ -104,15 +125,13 @@ @implementation RNCookieManagerIOS rejecter:(RCTPromiseRejectBlock)reject) { NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSMutableDictionary *cookies = [NSMutableDictionary dictionary]; - NSDateFormatter *formatter = [NSDateFormatter new]; - [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"]; 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:[formatter stringFromDate:c.expiresDate] forKey:@"expiresDate"]; + [d setObject:[self.formatter stringFromDate:c.expiresDate] forKey:@"expiresDate"]; [cookies setObject:d forKey:c.name]; } resolve(cookies); From 3e3ec8383d4d289faf51e9b4ceb3896802b6a5a1 Mon Sep 17 00:00:00 2001 From: Marc Shilling Date: Tue, 6 Nov 2018 19:39:15 -0500 Subject: [PATCH 3/3] fix crash if expiresDate is nil --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index 47609f69..4b72c2dd 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -152,7 +152,10 @@ -(NSString *)getDomainName:(NSURL *) url [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"]; + NSString *expiresStr = [self.formatter stringFromDate:c.expiresDate]; + if (expiresStr) { + [d setObject:expiresStr forKey:@"expiresDate"]; + } [cookies setObject:d forKey:c.name]; } resolve(cookies); @@ -240,7 +243,10 @@ -(NSString *)getDomainName:(NSURL *) url [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"]; + NSString *expiresStr = [self.formatter stringFromDate:c.expiresDate]; + if (expiresStr) { + [d setObject:expiresStr forKey:@"expiresDate"]; + } [cookies setObject:d forKey:c.name]; } }