Ionic contacts fetch does not properly on iOS

Hi Folks,

I am doing one POC where i need to fetch device contacts list using ionic native plugin. Works fine on android.
iOS i am having tricky issue when there is no number added for device contact list it fails and stops there only, does not display contact details further.

I tried with removing hasPhoneNumber or making it false nothing worked.

this.contacts.find(["name", "phoneNumbers"],
    { multiple: true, hasPhoneNumber: true }).then((contacts) => {
       if (contacts.length != 0) {
         this.contactsfound = contacts;
       } else {
         this.contactsfound.push({ displayName: 'No Contacts found' });
     }
 });

Code works fine on Android.

Hi,

hasPhoneNumber is only for android.

i am facing the same issue. On android it is working fine and the contacts are loaded fast, but on iOS it is slow and when a contact does not have a number it stops there.

Have you found a solution to this issue?

Thank you in advance

I know this is not the best solution but it helped avoid the contacts which does not have number or name.

if(contacts[i].phoneNumbers == null || contacts[i].phoneNumbers == undefined || contacts[i].phoneNumbers.length ==0 ){
              //Do nothing
            }else if(contacts[i].name==undefined || contacts[i].name.formatted == undefined || contacts[i].name.formatted == null || contacts[i].name.formatted ==''){
              //Do nothing
            }else{
              var contact = {};
              contact["name"] = contacts[i].name.formatted;
              contact["number"] = contacts[i].phoneNumbers[0].value;
              this.nativeStorage.setItem('contactLength', contacts.length)
                .then(() => {
                  localStorage.setItem('contactLength', 'true');
                },
                error => console.error('Error storing item', error));
              this.contactsfound.push(contact);
            }

Hey there,

Has any of you seen this error on iPhone?

I have only 800 contacts but it’s being logged 1392 times, that’s really weird.

Fetching in bulk 250 contacts!
2020-06-23 22:12:11.239463+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.262399+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.285585+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.308285+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.331447+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.354384+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.377638+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.400469+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.423719+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.446573+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.470204+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.493055+0400 App[3350:912225] Fetching in bulk 250 contacts!
2020-06-23 22:12:11.515988+0400 App[3350:912225] Fetching in bulk 250 contacts!

I found the solution guys, the problem was that some contacts that don’t have phoneNumber, so I did this:

let options = {
    filter: "",
    multiple: true,
    hasPhoneNumber: true,
    desiredFields: ["phoneNumbers", "name"],
  };

const contacts = await new Contacts().find(["*"], options);
    const contactsWithPhone = contacts.filter(
      (contact) => contact.phoneNumbers && contact.phoneNumbers.length !== 0
    );

Hii @champion007,

Can you please help with how to fetch contacts from iOS device.
As currently I’m not able to fetch contacts. I’m getting a weird error.

Thank you

1 Like