the*_*lim 5 android android-permissions react-native react-native-contacts react-hooks
我想在我的 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);
})
}, []);
Run Code Online (Sandbox Code Playgroud)
我到处寻找解决方案,但没有关于这个问题,谢谢你提前帮助我。
the*_*tar 11
API 已在版本 6 中更新。从回调(版本 5 使用回调)更改为 promise 对我有用。我的意思是改变 -
Contacts.getAll((err, contacts) => { });Run Code Online (Sandbox Code Playgroud)
到 -
Contacts.getAll()
.then((contacts) => {
// work with contacts
})
.catch((e) => { //handle error })Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1176 次 |
| 最近记录: |