Infopedia
Infopedia

Reputation: 386

App Crash while using React-Native-Contacts

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.

Upvotes: 2

Views: 4072

Answers (4)

Alex Joseph
Alex Joseph

Reputation: 1

Add both this to the AndroidManifest.xml. It doesn't show in the documentation but you need to add this to access the contacts.I got the same problem with the new reat version(from 2023).

  <uses-permission android:name="android.permission.WRITE_CONTACTS" />
  <uses-permission android:name="android.permission.READ_CONTACTS" />

Upvotes: 0

Tiago Barroso
Tiago Barroso

Reputation: 387

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.

Upvotes: 0

Irfan Khan
Irfan Khan

Reputation: 511

//Try it 
const addContact = () => {
    PermissionsAndroid.requestMultiple([
      PermissionsAndroid.PERMISSIONS.WRITE_CONTACTS,
      PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
    ])
    Contacts.getAll().then(contacts => {
      // console.log('hello',contacts);
      setMblContacts(contacts);
    })
  }

Upvotes: 0

Sylchauf
Sylchauf

Reputation: 316

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

Upvotes: 1

Related Questions