React-native-contacts: Crashing on iOS

Created on 6 Nov 2019  ·  5Comments  ·  Source: morenoh149/react-native-contacts

I followed the steps in the README to implement react-native-contacts, but every time I use Contacts it crashed my app. My is a functional element and the below is my code for getting contacts. I've tried re-implementing it multiple times to no avail. Is this a problem with my React Native version?

useEffect(() => {
    console.log('Running useEffect');

    // This prints: `Permissions – null – "undefined"`
    Contacts.checkPermission((err, result) => console.log('Permissions', err, result));

    // This crashes app
    Contacts.getAll((err, contacts) => console.log('Contacts', err, contacts));
  }, []);

React Native: 0.61.4
React Native Contacts: 5.0.4

Most helpful comment

Fixed by adding below to Info.plist - according to the instructions this only needs to be done for "react native below 60". Is this an error in the README?

<key>NSContactsUsageDescription</key>
<string>Reason for accessing contacts</string>

All 5 comments

Fixed by adding below to Info.plist - according to the instructions this only needs to be done for "react native below 60". Is this an error in the README?

<key>NSContactsUsageDescription</key>
<string>Reason for accessing contacts</string>

@prathd I was facing the same issue yesterday. But I fixed it by adding

<key>NSContactsUsageDescription</key> <string>Reason for accessing contacts</string>.

I think it's a mistake in the README file. It would be better if it's updated.
Thank you. 👍

Just a note, I just had to do what prathd and AmalaLiza suggested with the latest release (5.2.0) on the latest react native (0.62.2) after having the same issue.

@mpraksti-alchemy we instruct the user on how to add NSContactsUsageDescription to Info.plist through xcode's UI at https://github.com/morenoh149/react-native-contacts#ios-2 did that not work for you? Does the readme need improvement?

None from above worked for me, any suggestions please?

Was this page helpful?
0 / 5 - 0 ratings