Reputation: 320
I am following this blog to set up react-native-contacts. After following the steps when I try to get all contacts
Contacts.getAll().then((contacts) => {
console.log(contacts)
})
I get this error.
TypeError: Cannot read property 'getAll' of null
For some reason importing Contacts from react-native-contacts appears to be null?
I am not sure if there is an issue with my set up. I followed up by reading over react-natives-contacts set up instructions.
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
{
'title': 'Contacts',
'message': 'This app would like to view your contacts.',
'buttonPositive': 'Please accept bare mortal'
}
)
.then(Contacts.getAll()
.then((contacts) => {
// work with contacts
console.log(contacts)
})
.catch((e) => {
console.log(e)
}))
-----------------------------
// in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS" />
I am using RN 0.69 so auto linking should be enabled? not sure what am I missing?
Upvotes: 0
Views: 1404
Reputation: 320
I am pretty new to react-native/mobile development so this may be obvious or not but I figured out the problem.
<key>Privacy - Contacts Usage Description</key>
<string>insert message about accessing contacts...</string>
What you WANT to do is open up Xcode and add the key and string from the drop down selecting Privacy - Contacts Usage Description and adding the string within info.plist
<key>NSContactsUsageDescription</key>
<string>insert message about accessing contacts...</string>
$ npx react-native start run-ios
. Probably a noob mistake but there is my solution. Successfully accessing contacts now👍🏻Upvotes: 1