react-native-contacts getAll 返回 null [英] react-native-contacts getAll return null
本文介绍了react-native-contacts getAll 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据这个
解决方案
按照react-native-contacts文档中提到的步骤,在最后添加一个catch块,对我有用.
PermissionsAndroid.request(权限Android.PERMISSIONS.READ_CONTACTS,{'title': '联系人','message': '这个应用程序想要查看你的联系人.'}).then(() => {con.getAll((错误,联系人)=> {如果(错误 === '拒绝'){//错误} 别的 {//数组中返回的联系人控制台日志(联系人);}})}).catch((错误)=> {控制台日志(错误);})
according to this link I used react-native-contact to open contact list in android device so the user can choose one and and add it to list. but when I click a button to open a contact list, react-native-contacts getAll returns null. here is a code that I use:
openContactlist() {
Contacts.getAll((err, contacts) => {
if (err) {
// throw err;
alert("NO");
}
// contacts returned
alert("yes");
})
}
in render of react native code there is a button that by clicking on it it call above function:
<Button
title="From contact list"
onPress={this.openContactlist}
/>
error:
null is not an object (evaluating '_react-native-contacts.getall')
解决方案
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);
})
这篇关于react-native-contacts getAll 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文