且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

react-native-contacts getAll 返回 null

更新时间:2023-12-03 18:03:10

Follow the steps mentioned in the documentation of react-native-contacts, and add a catch block at the end, it worked for me.

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