@@ -6,9 +6,71 @@ Cookie manager for react native.
66
77```
88yarn add react-native-cookies
9+ ```
10+
11+ ### Linking
12+
13+ #### Automatic (recommended)
14+
15+ ```
916react-native link react-native-cookies
1017```
1118
19+ #### Manual
20+
21+ If automatic linking does not work, you can manually link this library by following the instructions below:
22+
23+ ##### iOS
24+
25+ 1 . Open your project in Xcode, right click on ` Libraries ` and click `Add
26+ Files to "Your Project Name"` Look under ` node_modules/react-native-cookies/ios` and add ` RNCookieManagerIOS.xcodeproj`.
27+ 2 . Add ` libRNCookieManagerIOS.a ` to `Build Phases -> Link Binary With Libraries.
28+ 3 . Clean and rebuild your project
29+
30+ ##### Android
31+
32+ Run ` react-native link ` to link the react-native-cookies library.
33+
34+ Or if you have trouble, make the following additions to the given files manually:
35+
36+ ** android/settings.gradle**
37+
38+ ``` gradle
39+ include ':react-native-cookies'
40+ project(':react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cookies/android')
41+ ```
42+
43+ ** android/app/build.gradle**
44+
45+ ``` gradle
46+ dependencies {
47+ ...
48+ compile project(':react-native-cookies')
49+ }
50+ ```
51+
52+ ** MainApplication.java**
53+
54+ On top, where imports are:
55+
56+ ``` java
57+ import com.psykar.cookiemanager.CookieManagerPackage ;
58+ ```
59+
60+ Add the ` CookieManagerPackage ` class to your list of exported packages.
61+
62+ ``` java
63+ @Override
64+ protected List<ReactPackage > getPackages() {
65+ return Arrays . asList(
66+ new MainReactPackage (),
67+ new CookieManagerPackage ()
68+ );
69+ }
70+ ```
71+
72+
73+
1274### Usage
1375
1476``` javascript
@@ -24,9 +86,7 @@ CookieManager.set({
2486 version: ' 1' ,
2587 expiration: ' 2015-05-30T12:30:00.00-05:00'
2688}).then ((res ) => {
27- console .log (' cookie set!' );
28- console .log (err);
29- console .log (res);
89+ console .log (' CookieManager.set =>' , res);
3090});
3191
3292// Set cookies from a response header
@@ -37,39 +97,39 @@ CookieManager.setFromResponse(
3797 ' user_session=abcdefg; path=/; expires=Thu, 1 Jan 2030 00:00:00 -0000; secure; HttpOnly' )
3898 .then ((res ) => {
3999 // `res` will be true or false depending on success.
40- console .log (' set cookie result ' , res);
100+ console .log (' CookieManager.setFromResponse => ' , res);
41101 });
42102
43103// Get cookies as a request header string
44104CookieManager .get (' http://example.com' )
45105 .then ((res ) => {
46- console .log (' cookies for url ' , res); // => 'user_session=abcdefg; path=/;'
106+ console .log (' CookieManager.get => ' , res); // => 'user_session=abcdefg; path=/;'
47107 });
48108
49109// list cookies (IOS ONLY)
50110CookieManager .getAll ()
51111 .then (res) => {
52- console .log (' all cookies ' , res);
112+ console .log (' CookieManager.getAll => ' , res);
53113 });
54114
55115// clear cookies
56116CookieManager .clearAll ()
57117 .then (res) => {
58- console .log (' cookies cleared ' , res);
118+ console .log (' CookieManager.clearAll => ' , res);
59119 });
60120
61121// clear a specific cookie by its name (IOS ONLY)
62122CookieManager .clearByName (' cookie_name' )
63123 .then (res) => {
64- console .log (' cookie cleared ' , res);
124+ console .log (' CookieManager.clearByName => ' , res);
65125 });
66126
67127```
68128
69- ### Roadmap
129+ ### TODO
70130
71131- Proper ` getAll ` dictionary by domain
72132- Proper error handling
73133- Anything else?
74134
75- PR's welcome!
135+ PR's welcome!
0 commit comments