From b31b2e941220922ba2d20842d258c64725343f4f Mon Sep 17 00:00:00 2001 From: Alessandro Gerelli Date: Tue, 8 Nov 2022 13:30:54 +0100 Subject: [PATCH 1/4] Support for tvOS --- ios/RNCookieManagerIOS/RNCookieManagerIOS.h | 12 +++++---- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 28 +++++++++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.h b/ios/RNCookieManagerIOS/RNCookieManagerIOS.h index f780534..ff82768 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.h +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.h @@ -1,13 +1,15 @@ -/** - * Copyright (c) Joseph P. Ferraro - * - * This source code is licensed under the MIT license found in the - * LICENSE file here: https://github.com/joeferraro/react-native-cookies/blob/master/LICENSE.md. +/** + * Copyright (c) Joseph P. Ferraro + * + * This source code is licensed under the MIT license found in the + * LICENSE file here: https://github.com/joeferraro/react-native-cookies/blob/master/LICENSE.md. */ #import +#if __has_include() #import +#endif @interface RNCookieManagerIOS : NSObject diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index 0e76dba..cf59524 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -55,6 +55,7 @@ + (BOOL)requiresMainQueueSetup } if (useWebKit) { +#if __has_include() if (@available(iOS 11.0, *)) { dispatch_async(dispatch_get_main_queue(), ^(){ WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore]; @@ -65,6 +66,9 @@ + (BOOL)requiresMainQueueSetup } else { reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); } +#else + reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); +#endif } else { [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie]; resolve(@(YES)); @@ -110,7 +114,8 @@ + (BOOL)requiresMainQueueSetup rejecter:(RCTPromiseRejectBlock)reject) { if (useWebKit) { - if (@available(iOS 11.0, *)) { +#if __has_include() + if (@available(iOS 11.0, *) && __has_include("")) { dispatch_async(dispatch_get_main_queue(), ^(){ NSString *topLevelDomain = url.host; @@ -134,7 +139,12 @@ + (BOOL)requiresMainQueueSetup } else { reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); } - } else { +#else + reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); + return; +#endif + } + else { NSMutableDictionary *cookies = [NSMutableDictionary dictionary]; for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url]) { [cookies setObject:[self createCookieData:cookie] forKey:cookie.name]; @@ -149,6 +159,7 @@ + (BOOL)requiresMainQueueSetup rejecter:(RCTPromiseRejectBlock)reject) { if (useWebKit) { +#if __has_include() if (@available(iOS 11.0, *)) { dispatch_async(dispatch_get_main_queue(), ^(){ // https://stackoverflow.com/questions/46465070/how-to-delete-cookies-from-wkhttpcookiestore#answer-47928399 @@ -163,6 +174,10 @@ + (BOOL)requiresMainQueueSetup } else { reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); } +#else + reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); + return; +#endif } else { NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (NSHTTPCookie *c in cookieStorage.cookies) { @@ -183,6 +198,7 @@ + (BOOL)requiresMainQueueSetup NSMutableArray * foundCookiesList = [NSMutableArray new]; if (useWebKit) { +#if __has_include() if (@available(iOS 11.0, *)) { dispatch_async(dispatch_get_main_queue(), ^(){ NSString *topLevelDomain = url.host; @@ -209,6 +225,10 @@ + (BOOL)requiresMainQueueSetup } else { reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); } +#else + reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); + return; +#endif } else { NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (NSHTTPCookie *c in cookieStorage.cookies) { @@ -227,6 +247,7 @@ + (BOOL)requiresMainQueueSetup rejecter:(RCTPromiseRejectBlock)reject) { if (useWebKit) { +#if __has_include() if (@available(iOS 11.0, *)) { dispatch_async(dispatch_get_main_queue(), ^(){ WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore]; @@ -237,6 +258,9 @@ + (BOOL)requiresMainQueueSetup } else { reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); } +#else + reject(@"", NOT_AVAILABLE_ERROR_MESSAGE, nil); +#endif } else { NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; resolve([self createCookieList:cookieStorage.cookies]); From 6afdd38087ece0bdb83c89f4ae1e48d3131d2e76 Mon Sep 17 00:00:00 2001 From: Alessandro Gerelli Date: Tue, 8 Nov 2022 14:16:07 +0100 Subject: [PATCH 2/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a560361..bf69fa6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,9 @@ This module was ported from [joeferraro/react-native-cookies](https://github.com ## Platforms Supported - ✅ iOS +- ✅ tvOS - ✅ Android +- ✅ AndroidTV - ❌ Currently lacking support for Windows, macOS, and web. Support for these platforms will be created when there is a need for them. Starts with a posted issue. ## Expo From 9b5f7c5cdf6c6d3167f09158eb2c18becdf8155e Mon Sep 17 00:00:00 2001 From: Alessandro Gerelli Date: Fri, 11 Nov 2022 14:31:34 +0100 Subject: [PATCH 3/4] Fixed __has_include usage on iOS --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index cf59524..b492fe5 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -115,7 +115,7 @@ + (BOOL)requiresMainQueueSetup { if (useWebKit) { #if __has_include() - if (@available(iOS 11.0, *) && __has_include("")) { + if (@available(iOS 11.0, *)) { dispatch_async(dispatch_get_main_queue(), ^(){ NSString *topLevelDomain = url.host; From 17004069e77390b404605134c1efc57d9c65ed96 Mon Sep 17 00:00:00 2001 From: Alessandro Gerelli Date: Fri, 11 Nov 2022 15:25:57 +0100 Subject: [PATCH 4/4] Updated podspec to support tvOS --- react-native-cookies.podspec | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/react-native-cookies.podspec b/react-native-cookies.podspec index ec1b754..85c3d94 100644 --- a/react-native-cookies.podspec +++ b/react-native-cookies.podspec @@ -11,7 +11,9 @@ Pod::Spec.new do |s| s.author = { package["author"]["name"] => package["author"]["email"] } s.source = { :git => "git@github.com:react-native-community/cookies.git", :tag => "v#{s.version}" } s.requires_arc = true - s.platform = :ios, "7.0" + s.platform = { :ios => "7.0", :tvos => "7.0" } + s.ios.deployment_target = "7.0" + s.tvos.deployment_target = "7.0" s.preserve_paths = "*.framework" s.source_files = "ios/**/*.{h,m}" s.dependency "React-Core"