问题描述
我正在使用react native expo开发移动应用程序。
Expo SDK版本为37.0.0
为了过滤和显示我的联系人,我使用了“ expo-contacts”包。 但是我无法使用“字段”选项过滤联系人。
我的代码部分:
useEffect(() => {
(async () => {
const { status } = await Contacts.requestPermissionsAsync();
if (status === "granted") {
const { data } = await Contacts.getContactsAsync({
fields: [Contacts.PHONE_NUMBERS]
});
if(data.length > 0)
console.log(data);
}
})();
},[]);
但是我无法过滤联系人,我得到了所有联系人。
解决方法
更正您的代码如下:注意 Contacts.PHONE_NUMBERS 无效
useEffect(() => {
(async () => {
const { status } = await Contacts.requestPermissionsAsync();
if (status === 'granted') {
const { data } = await Contacts.getContactsAsync({
fields: [Contacts.Fields.PhoneNumbers],});
if (data.length > 0) {
console.log(data);//do some action here
}
}
})();
},[]);