使用 React-Native-Contacts 时应用崩溃

App Crash while using React-Native-Contacts

我的应用程序在使用任何 react-native-contacts 方法时崩溃。

  function getPhoneRecords() {
 PermissionsAndroid.requestMultiple([
  PermissionsAndroid.PERMISSIONS.WRITE_CONTACTS,
  PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
]).then(() => {
  Contacts.getAll((err, contacts) => {
    if (err) {
      console.log(err, 'failed to fetch phone Records!');
    } else {
      setPhoneRecords(contacts);
    }
  });
});}

这是 getAllContacts 的函数,但每当执行此函数时,我的应用程序都会崩溃且没有错误。 我该如何解决这个问题?提前致谢。

如果它在 iOS 崩溃:

检查您是否更新了 Info.plist 文件。您必须拥有键值 «Privacy - Contacts Usage Description» 和一个句子。

遵循文档:https://github.com/morenoh149/react-native-contacts#ios-2

如果它在 Android 崩溃:

检查您是否更新了 AndroidManifest.xml 文件。您必须请求许可,例如 iOS.

遵循文档:https://github.com/morenoh149/react-native-contacts#permissions

//Try it 
const addContact = () => {
    PermissionsAndroid.requestMultiple([
      PermissionsAndroid.PERMISSIONS.WRITE_CONTACTS,
      PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
    ])
    Contacts.getAll().then(contacts => {
      // console.log('hello',contacts);
      setMblContacts(contacts);
    })
  }