react-native-sensitive-info-fix
v5.0.0
Published
react-native-sensitive-info manages all data stored in Android Shared Preferences and iOS Keychain. You can set, get and delete keys/values using simple methods.
Downloads
44
Maintainers
Readme
React Native Sensitive Info
react-native-sensitive-info 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.
| RN SensitiveInfo Version | Description | |--------------------------|----------------------------------| | 4.0+ | Compatible with RN 0.40+ | | <= 3.0.2 | Compatible with RN 0.40 or below |
Install
Install react-native-sensitive-info
using:
npm i -S react-native-sensitive-info
Linking project
Automatically
react-native 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 MainApplication.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 :)
Changelog
Since version >= 5.0.0
We introduced Android Keystore security into our library. Also, we've fixed some issues and updated example.
Thanks to all contributors who helped us on our journey :)
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',
encrypt: true});
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',
encrypt: true
});
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 always welcome :)