Attempting to get setup with react-native-keychain but I am receiving the error below.
TypeError: Cannot read property 'setGenericPasswordForService' of undefined(…)
I've installed the npm library and linked it with rnpm. I checked my Libraries folder in XCode to confirm RNKeychain.xcodeproj was installed and I can see the library installed in the Linked Binaries as well.
import Keychain from 'react-native-keychain';
export default class Init extends Component {
componentDidMount() {
var username = 'zuck';
var password = 'poniesRgr8';
Keychain
.setGenericPassword(username, password)
.then(function() {
console.log('Credentials saved successfully!');
}).catch(function(error) {
console.log('Could not set Generic Password. ', error);
});
}
}
I had the same issue, but a simple re-run of react-native run-ios fixed it for me. Hope this helps someone else who comes across this error.
@digitaldavenyc same here... I tried restarting, cleaning rebuilding and what not, but keep getting this error. did you manage so resolve it?
RN: 0.31, react-native-keychain: 3.2, iOS simulator
Update - I compiled the app for Android and run it on a device, and got the same error.
I run react-native init test, npm install react-native-keychain and rnpm link.
Then I copied the example code from the readme and run - and got the same error.. so it looks like something is broken when working with RN 0.31.
@Kufert I'm running it successfully on RN 0.31 on although I linked it with one of the previous versions. Have you tried it with npm install --save react-native-keychain?
Thanks @vonovak, your comment helped me to get it working with android. In addition to the rnpm link, I had to add to MainApplication.java:
...
import com.oblador.keychain.KeychainPackage; // <-- added
....
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new KeychainPackage() // <-- added
That fixed it for Android. Still need to sort out iOS though. FYI @oblador
@Kufert have you tried following the manual installation steps?
@Kufert same for me on iOS, can you get this working?
I'm getting this same error anytime I try to login on Android.
RN: 0.35
Keychain: 0.32
Genymotion Simulator
None of the above fixes have solved the problem for me. Can anyone verify that they've gotten it to work on Android with RN 0.35?
I'm having the same problem (iOS)
I followed the Readme instructions. Tried with react-native link, with rnpm link, using the Podfile and adding manually.
Still, I keep on getting the same error
{ [TypeError: undefined is not an object (evaluating 'RNKeychainManager.setGenericPasswordForService')]
line: 73951,
column: 18,
sourceURL: 'http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false' }
Any help?
I face the same problem and successfully solved by changing to version 0.3.2.
Any further information? Didn't work for me to change the downgrade the version. Using RN 0.40.0.
Please make sure the native module is linked correctly and that you're importing the js module correctly. If you use RN >= 0.40 you need to use the newest release.
Thanks, it works now with the latest version on RN >= 0.40 my issue was that the binary wasn't linked.
how did you mange to link the binary @akullpp ? i'm in the same error with keychain on ios simulator
thanks buddy
@Moumene see step 2: https://facebook.github.io/react-native/docs/linking-libraries-ios.html
Thanks for the response @akullpp
I did this before but what i was doing wrong is the import.
Import Keychain from 'react-native-keychain' instead of
Import * as Keychain .....
I'm getting this error on "react-native": "0.40.0","react-native-keychain": "^1.1.0" and fixes with import * as Keychain from 'react-native-keychain'; instead of import Keychain from 'react-native-keychain';
I feel dumb ... readme is correct and the example works,
don't bother with different imports and such.
package.json if you're wondering how similar it is to yours:
"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-i18n": "^1.0.0",
"react-native-keychain": "^1.2.0",
"react-native-vector-icons": "^4.1.1",
"react-navigation": "^1.0.0-beta.11"
},
I simply forgot to run react-native run-android thus not compiling the android side of things...
I had the same issue. I resolved it by running pod install on my iOS folder. Voilà , it's working now.
Most helpful comment
I'm getting this error on
"react-native": "0.40.0","react-native-keychain": "^1.1.0"and fixes withimport * as Keychain from 'react-native-keychain';instead ofimport Keychain from 'react-native-keychain';