Home

Awesome

react-native cookie manager library. npm version

Installation / 安装

$ npm install react-native-cookiemanager --save

Configuration / 配置

IOS

Android

Update Gradle Settings
// file: android/settings.gradle
...

include ':react-native-cookiemanager'
project(':react-native-cookiemanager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cookiemanager/android')

Update App Gradle Build
// file: android/app/build.gradle
...

dependencies {
    ...
    compile project(':react-native-cookiemanager')
}
Register React Package
...
import com.heng.cookie.CookieManagerPackage;

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {

    private ReactInstanceManager mReactInstanceManager;
    private ReactRootView mReactRootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .addPackage(new CookieManagerPackage()) // register cookie manager package
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null);
        setContentView(mReactRootView);
    }
...

...
import com.heng.cookie.CookieManagerPackage;

public class MainActivity extends ReactActivity {

...

     @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new CookieManagerPackage());
    }

...
import com.heng.cookie.CookieManagerPackage;
...

public class MainApplication extends Application implements ReactApplication {


    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        protected boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
                    new CookieManagerPackage()
            );
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }
}

Use / 使用


import CookieManager from 'react-native-cookiemanager';

let options = {
  name: '',
  value: '',
  domain: '',
  origin: '',
  path: '',
  expiration: '',
};

CookieManager.setCookie(options);

CookieManager.getCookie('you url',(res) => {
  alert(JSON.stringify(res));
});

CookieManager.removeAllCookies();