$ npm install react-native-secure-storage --save
$ react-native link react-native-secure-storage
If you use React Native version >= 0.60, need additionally run:
$ cd ios && pod install && cd ..
- In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜react-native-secure-storageand addRNSecureStorage.xcodeproj - In XCode, in the project navigator, select your project. Add
libRNSecureStorage.ato your project'sBuild Phases➜Link Binary With Libraries - Run your project (
Cmd+R)<
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNSecureStoragePackage;to the imports at the top of the file - Add
new RNSecureStoragePackage()to the list returned by thegetPackages()method
- Append the following lines to
android/settings.gradle:include ':react-native-secure-storage' project(':react-native-secure-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-secure-storage/android') - Insert the following lines inside the dependencies block in
android/app/build.gradle:compile project(':react-native-secure-storage')
- In Visual Studio add the
RNSecureStorage.slninnode_modules/react-native-secure-storage/windows/RNSecureStorage.slnfolder to their solution, reference from their app. - Open up your
MainPage.csapp
- Add
using Com.Reactlibrary.RNSecureStorage;to the usings at the top of the file - Add
new RNSecureStoragePackage()to theList<IReactPackage>returned by thePackagesmethod
- getItem(String key, SecureStoreParams options)
- setItem(String key, String value, SecureStoreParams options)
- deleteItem(String key, SecureStoreParams options)
- getAllItems(SecureStoreParams options)
interface SecureStoreParams {
keychainService: string; //used for iOS
sharedPreferencesName: string; //used for Android
}import RNSecureStorage from 'react-native-secure-storage';
const storeParams = {
keychainService: 'accounts_example_app_ios',
sharedPreferencesName: 'accounts_example_app_android',
}
async function RNSecureStorageExample () {
await RNSecureStorage.setItem('sunny_day', '365', storeParams);
const saveValue = await RNSecureStorage.getItem('sunny_day', storeParams);
const allEntries = await RNSecureStorage.getAllItems(storeParams);
//all Entries is an object with key as string and value as string;
await RNSecureStorage.deleteItem('sunny_day', storeParams);
}