react-native-cookie获取cookie

组件安装

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')
}

MainApplication.java

import com.psykar.cookiemanager.CookieManagerPackage;

@Override
protected List 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=/;'
  });
  

你可能感兴趣的:(react-native-cookie获取cookie)