1

I'm facing a serious issue while fetching contacts from the contacts list using PhoneGap. I have installed the plugin and did everything but seems it doesn't work for me.

So, What is the problem ? The problem with it is my contacts having the email accounts.So email doesn't have the phonenumber. Here is the screenshot : http://prntscr.com/82meyr

What is the issue ? 

Well, the problem is that when it encounters the email the for loop stops immediately and shows the 20-30 contacts only!

     function onSuccess(contacts) 
     {
            alert("Total contacts = "+ contacts.length);
            for (var i=0; i<contacts.length; i++) 
            { 
                $('#contactList').append("<li><a href='#'><h2>"+ contacts[i].displayName +"</h2><p>" + contacts[i].phoneNumbers[0].value + "</p></a></li>");  
                 $('#contactList').listview("refresh");
            }
  }

My contacts .vcf file. You can import it on your emulator.


Link : https://dl.dropboxusercontent.com/u/43274075/00004.vcf

Here is the code I'm using.(already posted but didn't get answer)

--> https://stackoverflow.com/questions/31889859/phonegap-error-on-the-physical-device

Is there any way to bypass the email accounts ?

Thank you!

  • Why not check if contacts[i].phoneNumbers[0] == null and ignore that contact if so? – Huey Aug 10 '15 at 3:25
  • function onSuccess(contacts) { for(var i=0;i<contacts.length;i++) { if(contacts[i].phoneNumbers) { for (var j = 0; j < contacts[i].phoneNumbers.length; j++) { $('#contactList').append("<li><a href='#'><h2>"+ contacts[i].displayName +"</h2><p>" + contacts[i].phoneNumbers[0].value + "</p></a></li>"); } } } – John Mark Aug 10 '15 at 6:24
  • I have done this @Huey but it's duplicating the contact names more time. – John Mark Aug 10 '15 at 6:25
  • Because it's adding a new entry for each phone number someone with multiple numbers has – Huey Aug 10 '15 at 6:29
  • Then what should I do ? @Huey – John Mark Aug 10 '15 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.