Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions ios/RNCookieManagerIOS/RNCookieManagerIOS.h
Original file line number Diff line number Diff line change
@@ -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 <React/RCTBridgeModule.h>

#if __has_include(<WebKit/WebKit.h>)
#import <WebKit/WebKit.h>
#endif

@interface RNCookieManagerIOS : NSObject <RCTBridgeModule>

Expand Down
26 changes: 25 additions & 1 deletion ios/RNCookieManagerIOS/RNCookieManagerIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ + (BOOL)requiresMainQueueSetup
}

if (useWebKit) {
#if __has_include(<WebKit/WebKit.h>)
if (@available(iOS 11.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^(){
WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore];
Expand All @@ -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));
Expand Down Expand Up @@ -110,6 +114,7 @@ + (BOOL)requiresMainQueueSetup
rejecter:(RCTPromiseRejectBlock)reject)
{
if (useWebKit) {
#if __has_include(<WebKit/WebKit.h>)
if (@available(iOS 11.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^(){
NSString *topLevelDomain = url.host;
Expand All @@ -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];
Expand All @@ -149,6 +159,7 @@ + (BOOL)requiresMainQueueSetup
rejecter:(RCTPromiseRejectBlock)reject)
{
if (useWebKit) {
#if __has_include(<WebKit/WebKit.h>)
if (@available(iOS 11.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^(){
// https://stackoverflow.com/questions/46465070/how-to-delete-cookies-from-wkhttpcookiestore#answer-47928399
Expand All @@ -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) {
Expand All @@ -183,6 +198,7 @@ + (BOOL)requiresMainQueueSetup
NSMutableArray<NSHTTPCookie *> * foundCookiesList = [NSMutableArray new];

if (useWebKit) {
#if __has_include(<WebKit/WebKit.h>)
if (@available(iOS 11.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^(){
NSString *topLevelDomain = url.host;
Expand All @@ -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) {
Expand All @@ -227,6 +247,7 @@ + (BOOL)requiresMainQueueSetup
rejecter:(RCTPromiseRejectBlock)reject)
{
if (useWebKit) {
#if __has_include(<WebKit/WebKit.h>)
if (@available(iOS 11.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^(){
WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore];
Expand All @@ -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]);
Expand Down
4 changes: 3 additions & 1 deletion react-native-cookies.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Pod::Spec.new do |s|
s.author = { package["author"]["name"] => package["author"]["email"] }
s.source = { :git => "[email protected]: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"
Expand Down