Giter Site home page Giter Site logo

tsjing / react-native-sensitive-info Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mcodex/react-native-sensitive-info

0.0 2.0 0.0 44.13 MB

Android Shared Preferences and iOS Keychain for React Native

License: MIT License

JavaScript 9.06% Java 23.46% Python 7.71% Objective-C 59.78%

react-native-sensitive-info's Introduction

#React Native Sensitive Info

npm version

This module is the next generation of react-native-get-shared-prefs.

Introduction

react-native-sensitive-info manages all data stored in Android Shared Preferences and iOS Keychain. You can set and get all key/value using simple methods.

Install

Install react-native-sensitive-info using:

npm i -S react-native-sensitive-info

Linking project

Automatically

rnpm link react-native-sensitive-info

Manually

iOS

In XCode, in the project navigator:

  • Right click Libraries
  • Add Files to [your project's name]
  • Go to node_modules/react-native-sensitive-info
  • Add the .xcodeproj file

In XCode, in the project navigator, select your project.

  • Add the libRNSensitiveInfo.a from the RNSensitiveInfo project to your project's Build Phases โžœ Link Binary With Libraries
  • Click .xcodeproj file you added before in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic').
  • Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React and $(SRCROOT)/../../React - mark both as recursive. (Should be OK by default.)

Run your project (Cmd+R)

Android

Go to settings.gradle inside your android project folder and paste this lines there:

include ':react-native-sensitive-info'

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

and paste it into build.gradle:

compile project(':react-native-sensitive-info')

In your MainActivity.java add:

import br.com.classapp.RNSensitiveInfo.RNSensitiveInfoPackage; //<- You must import this

protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new RNSensitiveInfoPackage(), // <- Add this line
    );
}

Sync gradle and go :)

#Methods

##Since version >= 3.0.0

We unified our library's methods to bring more efficiency and simplify the usability for other developers. We hope that you enjoy it. :)

setItem(key, value, options): You can insert data into shared preferences & keychain using this method.

getItem(key, options): This promise will get value from given key.

deleteItem(key, options): (New method since this version) It will delete value from given key

getAllItems(options): Will retrieve all keys and values from Shared Preferences & Keychain

"Options" is a new parameter (optional) that you can pass to our methods. But what does it do? Now, you can select which keychain's service (iOS) and shared preferences's name (android) you can use. To do so:

SInfo.setItem('key1', 'value1', {
sharedPreferencesName: 'mySharedPrefs',
keychainService: 'myKeychain'});

But if you prefer to not use it, our default sharedPreferencesName is: shared_preferences and keychainService is: app

If you used Android's getDefaultSharedPreferences in your project the shared preference's name that you are looking for is: com.mypackage.MyApp_preferences. In other hands if you used iOS's Keychain the default service is: app which is our default too.

How to use?

Here is a simple example:

import SInfo from 'react-native-sensitive-info';

SInfo.setItem('key1', 'value1', {
sharedPreferencesName: 'mySharedPrefs',
keychainService: 'myKeychain'});

SInfo.setItem('key2', 'value2');

SInfo.getItem('key1', {
sharedPreferencesName: 'mySharedPrefs',
keychainService: 'myKeychain'}).then(value => {
    console.log(value) //value1
});

SInfo.getItem('key2').then(value => {
    console.log(value) //value2
});

SInfo.getAllItems({
sharedPreferencesName: 'mySharedPrefs',
keychainService: 'myKeychain'}).then(values => {
    console.log(values) //value1
});

#Contributing

Pull requests are welcome :)

Future Works

  • Add support for Android's keystore

react-native-sensitive-info's People

Contributors

hilkeheremans avatar mcodex avatar samin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.