react-native-cookies
Cookie manager for react native.
Looking for Maintainers
I no longer use this library and I'm looking for maintainer(s) to take full control over the development and release cycle.
Installation
yarn add react-native-cookies
Linking
Automatic (recommended)
react-native link react-native-cookies
Manual
If automatic linking does not work, you can manually link this library by following the instructions below:
iOS
- Open your project in Xcode, right click on
Libraries
and clickAdd Files to "Your Project Name"
Look undernode_modules/react-native-cookies/ios
and addRNCookieManagerIOS.xcodeproj
. - Add
libRNCookieManagerIOS.a
to `Build Phases -> Link Binary With Libraries. - Clean and rebuild your project
Android
Run react-native link
to link the react-native-cookies library.
Or if you have trouble, make the following additions to the given files manually:
android/settings.gradle
include ':react-native-cookies'project(':react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cookies/android')
android/app/build.gradle
dependencies { ... compile project(':react-native-cookies')}
MainApplication.java
On top, where imports are:
Add the CookieManagerPackage
class to your list of exported packages.
@Overrideprotected List<ReactPackage> { return Arrays.;}
Usage
; // set a cookie (IOS ONLY)CookieManager; // Set cookies from a response header// This allows you to put the full string provided by a server's Set-Cookie // response header directly into the cookie store.CookieManager ; // Get cookies as a request header stringCookieManager ; // list cookies (IOS ONLY)CookieManager ; // clear cookiesCookieManager ; // clear a specific cookie by its name (IOS ONLY)CookieManager ;
WebKit-Support (iOS only)
React Native comes with a WebView component, which uses UIWebView on iOS. Introduced in iOS 8 Apple implemented the WebKit-Support with all the performance boost.
To use this it's required to use a special implementation of the WebView component (e.g. react-native-wkwebview).
This special implementation of the WebView component stores the cookies not in NSHTTPCookieStorage
anymore. The new cookie-storage is WKHTTPCookieStore
and implementes a differnt interface.
To use this CookieManager with WebKit-Support we extended the interface with the attribute useWebKit
(a boolean value, default: FASLE
) for the following methods:
Method | WebKit-Support | Method-Signature |
---|---|---|
getAll | Yes | CookieManager.getAll(useWebKit:boolean) |
clearAll | Yes | CookieManager.clearAll(useWebKit:boolean) |
get | Yes | CookieManager.get(url:string, useWebKit:boolean) |
set | Yes | CookieManager.set(cookie:object, useWebKit:boolean) |
Usage
; const useWebKit = true; // list cookies (IOS ONLY)CookieManager ; // clear cookiesCookieManager ; // Get cookies as a request header stringCookieManager ; // set a cookie (IOS ONLY)const newCookie: = name: 'myCookie' value: 'myValue' domain: 'some domain' origin: 'some origin' path: '/' version: '1' expiration: '2015-05-30T12:30:00.00-05:00'; CookieManager ;
TODO
- Proper
getAll
dictionary by domain - Proper error handling
- Anything else?
PR's welcome!