I am attempting to run the react-native-contacts in iOS simulator on 10.11.6. When I run this, I get:
undefined is not an object (evaluating 'Contacts.getAll')
var Contacts = require('react-native-contacts');
<F8Button
style={styles.button}
onPress={() => this._pressRow()}
caption="Import"
/>
_pressRow(){
Contacts.getAll((err, contacts) => {
if(err && err.type === 'permissionDenied'){
// x.x
} else {
console.log(contacts)
}
});
}
I'm using react-native 0.28. XCode 8.
This is almost always a linking problem. Did you run react-native link? Can you see this project in your libraries in xCode?
I had this same problem, React Native Version 0.34, XCode 7.3.
Running react-native link gave me
rnpm-install info Android module react-native-contacts is already linked
rnpm-install info iOS module react-native-contacts is already linked
I had to manually remove the RCTContacts.xcodeproj file from the LIbraries folder in Xcode. When I readded the library through XCode, the react-native-contacts module worked
I also imported the code with this line instead of what is shown in the docs.
import Contacts from 'react-native-contacts';
In a different issue this issue is linked as a workaround. But I'm actually working with Android. I still have this problem
I also have this issue on android
I had this problem too and one change that I had to do was to replace the "settingsDir" with "rootProject.projectDir" in the second line below when you add to settings.gradle file
include ':react-native-contacts'
project(':react-native-contacts').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-contacts/android')
This might present as an issue on when there are no contacts. The android simulator by default does not have any contacts. Try adding one or more contacts and try again
I tried all ways on github ,but still the problem on Android, works fine on iOS
I solved this problem on Android, we could open MainApplicaiton.java file and
import com.rt2zz.reactnativecontacts.ReactNativeContacts;
then add the code protected
List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VectorIconsPackage(),
new ReactNativeContacts()
);
}
};
I did all of the above to make this work, the final change that had me stuck was changing
import { Contacts } from 'react-native-contacts'; to import Contacts from 'react-native-contacts';
Most helpful comment
I solved this problem on Android, we could open
MainApplicaiton.javafile andthen add the code protected