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 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..b492fe5 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,6 +114,7 @@ + (BOOL)requiresMainQueueSetup rejecter:(RCTPromiseRejectBlock)reject) { if (useWebKit) { +#if __has_include() if (@available(iOS 11.0, *)) { 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]); 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"