组件安装
yarn add react-native-cookies
手动link(再也不会自动link了)
写下Android的link操作
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')
}
<font color="red">MainApplication.java</font>
import com.psykar.cookiemanager.CookieManagerPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.asList(
new MainReactPackage(),
new CookieManagerPackage()
);
}
使用
获取cookie是需要登录操作以后根据登录url获取的
CookieManager.get('http://example.com')
.then((res) => {
console.log('CookieManager.get =>', res); // => 'user_session=abcdefg; path=/;'
});
网友评论