2

My App is crashing while using any method of react-native-contacts.

  function getPhoneRecords() {
 PermissionsAndroid.requestMultiple([
  PermissionsAndroid.PERMISSIONS.WRITE_CONTACTS,
  PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
]).then(() => {
  Contacts.getAll((err, contacts) => {
    if (err) {
      console.log(err, 'failed to fetch phone Records!');
    } else {
      setPhoneRecords(contacts);
    }
  });
});}

Here is the function to getAllContacts but whenever this function executes my app crashes with no error. How can I solve this issue? Thanks in Advance.

Infopedia
  • 376
  • 2
  • 14
  • Did you wrote permission inside AndroidManifest.xml? – Aswin C May 23 '20 at 09:42
  • I did, But after including this app build fails with an error it is not compatible with gradle 6.0 also, Google play store rejects the application if we use such permissions in the manifest file. – Infopedia May 23 '20 at 09:45

3 Answers3

1

If it crash on iOS :

Check if you have updated your Info.plist file. You must have the key «Privacy - Contacts Usage Description» with a sentence in value.

Follow the documentation : https://github.com/morenoh149/react-native-contacts#ios-2

If it crash on Android :

Check if you have updated your AndroidManifest.xml file. You must request permission, like iOS.

Follow the documentation : https://github.com/morenoh149/react-native-contacts#permissions

Sylchauf
  • 186
  • 1
  • 9
  • But Play Store Rejects the application if we include such permissions in the manifest file. My app got rejected by including SMS permissions. – Infopedia May 23 '20 at 10:00
  • react-native-contacts does not need SMS permissions. SMS permission is a sensitive permission. If you need this permission, follow this steps : https://support.google.com/googleplay/android-developer/answer/9214102?hl=en – Sylchauf May 23 '20 at 10:20
  • Build Fails after includiing the permissions with this error, Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. – Infopedia May 23 '20 at 11:03
  • 1
    It worked, after including the permissions and run these commands: cd android && gradlew clean – Infopedia May 23 '20 at 11:13
0
//Try it 
const addContact = () => {
    PermissionsAndroid.requestMultiple([
      PermissionsAndroid.PERMISSIONS.WRITE_CONTACTS,
      PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
    ])
    Contacts.getAll().then(contacts => {
      // console.log('hello',contacts);
      setMblContacts(contacts);
    })
  }
Irfan Khan
  • 461
  • 5
  • 7
0

I recently had the same experience running live via React Native with hot reload.

It was solved when I uninstalled and reinstalled the app.

I hope it works for someone else.

Tiago Barroso
  • 329
  • 4
  • 4