Return-native-contacts returns undefined
I'm trying to get a list of contacts of a device, but return-native-contacts is returning undefined.
I installed the package and linked it as stated on the GitHub project page https://github.com/rt2zz/react-native-contacts
I also added permissions for the manifest file. How to do it?
source to share
This is mainly due to the lack of a connection reference as the builtins are required:
After npm install react-native-contacts
(or yarn add
) you need to link the material with
react-native link react-native-contacts
Then you need to rebuild your project ( react-native run-android
or build in Android Studio). Simply linking the native library is not enough to "reload" in the simulator or on the device.
You also need to add some more permissions to AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
source to share
My stack:
- react-native: 0.45.1
- contact-native-contacts: ^ 1.0.0 "
I was still getting the error after linking the module as above. Finally resolved the issue after adding the following to ReactNativeContacts.java
( /node_modules/react-native-contacts/android/src/main/java/com/rt2zz/reactnativecontacts
):
import com.facebook.react.bridge.JavaScriptModule;
@override public List<Class<? extends JavaScriptModule>> createJSModules() { return Collections.emptyList(); }
source to share