来自JS的错误调用:字段大小不同[[8,39],[4,0]

我想在我的 AVD 上显示联系人列表,但我遇到了错误(我尝试链接包但它什么也没做):

我的代码:

    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);
      })
    }, []);

错误 :

我到处寻找解决方案,但没有关于这个问题,谢谢你提前帮助我。

回答

API 已在版本 6 中更新。从回调(版本 5 使用回调)更改为 promise 对我有用。我的意思是改变 -

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

到 -

Contacts.getAll()
    .then((contacts) => {
      // work with contacts
    })
    .catch((e) => { //handle error })

  • This not an issue with the lib as the documentation clearly mentions this usage. Also you can check out the typing for the getAll method. https://github.com/morenoh149/react-native-contacts/blob/master/index.d.ts

以上是来自JS的错误调用:字段大小不同[[8,39],[4,0]的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>