Issues with getContactsAsync v.30.0.1


#1

Hello everyone! And congratulations to the Expo Team for the improvements of version 30.0 that I just switched to. The Contacts API is more complete, good job!

However, I am experiencing some issues when querying the contacts with getContactsAsync:
I am querying for contacts with certain fields (PhoneNumbers, Name) but my query parameters are not taken into consideration: some contacts without names or phone numbers are returned.

Find my code below:

import { Contacts } from "expo"
[...]

    const ctx = this;
    Expo.Permissions.askAsync(Expo.Permissions.CONTACTS)
      .then(async permission => {
        console.log(permission.status);
        if (permission.status !== "granted") {
          console.log("permission.status : ", permission.status);
        } else {
          ctx.setState({ loading: true });

          const { data } = await Contacts.getContactsAsync({
            fields: [Contacts.Fields.PhoneNumbers, Contacts.Fields.Name],
            pageSize: 0,
						sort: Contacts.SortTypes.FirstName
          });
          if (data.length > 0) {
            const contact = data[0];
            console.log("contact : ", contact);
            console.log("data : ", data);
            ctx.setState({ loading: false });
})
            }

It used to work on v 28.0 with Expo.Contacts.PHONE_NUMBERS
Now that I’ve migrated to v 30.0, it doesn’t and I can’t see if there is an error in my code.

What do you suggest/recommend?

Many thanks!


#2

Another “issue” I have noticed regarding the Contacts concerns the sortType: I specified firstName but contacts were returned by lastName on my iPhone. I realized that this was caused by my iPhone Contacts setting, where I specified that I wanted my contacts to be ordered by lastName first. When switching my device settings to order by firstName, they are correctly returned.

I am not sure this is the intended behavior as it can be quite confusing.


closed #3

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.