首页 > 解决方案 > react-native-contacts getAll 返回 null

问题描述

根据此链接,我使用 react-native-contact 在 android 设备中打开联系人列表,以便用户可以选择一个并将其添加到列表中。但是当我单击按钮打开联系人列表时,react-native-contacts getAll 返回 null。这是我使用的代码:

 openContactlist() {


Contacts.getAll((err, contacts) => {
  if (err) {
   // throw err;
    alert("NO");
  }
  // contacts returned
  alert("yes");

})

 }

在反应本机代码的渲染中,有一个按钮,通过单击它可以调用上面的函数:

<Button
                title="From contact list"
                onPress={this.openContactlist}
              />

错误:

 null is not an object (evaluating '_react-native-contacts.getall')

在此处输入图像描述

标签: androidreactjsreact-nativereact-native-contacts

解决方案


一个原因可能是您没有正确链接 react-native-contact

您还必须按照以下步骤链接 -

对于 Android: https ://github.com/rt2zz/react-native-contacts#android

对于 IOS: https ://github.com/rt2zz/react-native-contacts#ios


推荐阅读