3

I am going to use the react-native-keychain lib in my RN project but seems to be not working on my local.

RN: 0.61.5

react-native-keychain: "6.1.1",

I tried to like this.

.......

const MEMORY_KEY_PREFIX = '@MyStorage:'
let dataMemory = {}

class MyStorage {
  static syncPromise = null

  static setItem(key, value) {
    Keychain.setGenericPassword(MEMORY_KEY_PREFIX + key, value)
    dataMemory[key] = value
    return dataMemory[key]
  }

  static getItem(key) {
    return Object.prototype.hasOwnProperty.call(dataMemory, key) ? dataMemory[key] : undefined
  }

  static removeItem(key) {
    Keychain.resetGenericPassword()
    return delete dataMemory[key]
  }

  static clear() {
    dataMemory = {}
    return dataMemory
  }
}
.......

But I am facing issues.

TypeError: null is not an object (evaluating 'RNKeychainManager.SECURITY_LEVEL_ANY')

Is there any solution to fix it?

Thanks

goldvenus
  • 898
  • 1
  • 10
  • 21

2 Answers2

1

I got this error when I tried opening multiple iOS simulators. I am not sure if yours is the same case with the one I got.

For me the fix(?) was:

  1. Close all iOS simulators

  2. Run the react-native project specifically on a simulator.

    • yarn ios --simulator="iphone 8" - will run the app in iPhone 8
    • yarn ios --simulator="iphone 11" - will run the app in iPhone 11

To list all available device simulator you can run xcrun simctl list devices

PS: There is an issue in the package repo with similar error here which you might want to take a look at: https://github.com/oblador/react-native-keychain/issues/221

Indra Lukmana
  • 303
  • 3
  • 11
  • Thanks for your reply. I tried it but not working for me. I used an android emulator and shows the same issue. – goldvenus Jul 13 '20 at 14:48
1

You can fix it:

Set in Podfile

pod 'RNKeychain', :path => '../node_modules/react-native-keychain'

or

use_native_modules!

And then run

pod install
Marco Scabbiolo
  • 7,203
  • 3
  • 38
  • 46
Tatsiana
  • 21
  • 1