6

I want to display the list of contacts on my AVD but Im facing an error (I tried linking the package but it did nothing):

My code :

    const [contact, setContact] = useState([]);
  
    useEffect(() => {
      PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
        {
          'title': 'Contacts',
          'message': 'This app would like to view your contacts.'
        }
      ).then(() => {
        Contacts.getAll((err, contacts) => {
          if (err === 'denied'){
            // error
          } else {
            // contacts returned in Array
            setContact(contacts);
            console.log(contact);
          }
        })
      })
      .catch((err)=> {
          console.log(err);
      })
    }, []);

The error :

enter image description here

I searched everywhere for a solution but there's nothing about this issue, thanks for helping me by advance.

therealwalim
  • 252
  • 1
  • 4
  • 18
  • what you are getting in contact – mainak Dec 09 '20 at 19:17
  • I'm getting nothing, the only thing that display is the error even if I console.log() nothing shown in the console – therealwalim Dec 09 '20 at 19:41
  • After clearing cache and retarting the emulator I got this error on the console : ```[Error: Exception in HostFunction: Malformed calls from JS: field sizes are different. [[8,39],[4,0],[[36,2000,1607543301566,false]],1583]]``` – therealwalim Dec 09 '20 at 19:49

2 Answers2

15

The APIs has been updated in version 6. Changing from callback (version 5 uses callback) to promise worked for me. I mean change -

Contacts.getAll((err, contacts) => { });

to -

Contacts.getAll()
    .then((contacts) => {
      // work with contacts
    })
    .catch((e) => { //handle error })
thebstar
  • 168
  • 1
  • 4
1

With the updated API version, you need to change the callback syntax to promise .then and .catch such as

Contacts.getAll()
    .then(contacts => { //your code here })
    .catch(e => { //handle error })