forked from kimwoongkyu/react-native-cookies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (32 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react';
import { NativeModules, Platform } from 'react-native';
const invariant = require('invariant');
const RNCookieManagerIOS = NativeModules.RNCookieManagerIOS;
const RNCookieManagerAndroid = NativeModules.RNCookieManagerAndroid;
let CookieManager;
if (Platform.OS === 'ios') {
invariant(RNCookieManagerIOS,
'react-native-cookies: Add RNCookieManagerIOS.h and RNCookieManagerIOS.m to your Xcode project');
CookieManager = RNCookieManagerIOS;
} else if (Platform.OS === 'android') {
invariant(RNCookieManagerAndroid,
'react-native-cookies: Import libraries to android "react-native link react-native-cookies"');
CookieManager = RNCookieManagerAndroid;
} else {
invariant(CookieManager, 'react-native-cookies: Invalid platform. This library only supports Android and iOS.');
}
const functions = [
'setFromResponse',
'getFromResponse',
'clearByName'
];
module.exports = {
getAll: (useWebKit = false) => CookieManager.getAll(useWebKit),
clearAll: (useWebKit = false) => CookieManager.clearAll(useWebKit),
//clearAll: (useWebKit = false) => Platform.OS === 'ios' ? CookieManager.clearAll(useWebKit) : CookieManager.clearAll(),
get: (url, useWebKit = false) => CookieManager.get(url, useWebKit),
set: (cookie, useWebKit = false) => CookieManager.set(cookie, useWebKit),
};
for (var i = 0; i < functions.length; i++) {
module.exports[functions[i]] = CookieManager[functions[i]];
}