react-native-keychain: Failure on setGenericPassword()
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);
});
}
}
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 10
- Comments: 19
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';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 …
Thanks @vonovak, your comment helped me to get it working with android. In addition to the
rnpm link, I had to add toMainApplication.java:That fixed it for Android. Still need to sort out iOS though. FYI @oblador
@Moumene see step 2: https://facebook.github.io/react-native/docs/linking-libraries-ios.html