colourtheweb
colourtheweb

Reputation: 777

Cordova contacts not coming up

Problem

I'm trying to fetch contacts from any iOS device using Cordova as am developing an app using phonegap. I have included the ViewContacts.h and ViewContacts.m files in xCode 5.0. Also installed the cordova plugin for contacts and have mentioned <plugin name="Contacts" value="CDVContacts" /> in config.xml but still when I try to get contacts I don't get any error or contacts. After new ContactFindOptions(); function gets called it doesn't do anything. Any guidance or suggestions will be great. I'm struggling with this problem from last 2 days.

The below javascript code works fine in Android.

Code

function searchContact()
{
    alert("Hello........");
    // specify contact search criteria
    var options = new ContactFindOptions();
    alert("Before");// <-This ALERT

    options.filter      =   "";                 // empty search string returns all contacts
    options.multiple    =   true;               // return multiple results
    filter              =   ["displayName", "phoneNumbers", "emails"];  // return contact.displayName field

    // find contacts
    navigator.contacts.find(filter, onSuccess, onError, options);
    alert("After");
}//List all contacts

Upvotes: 1

Views: 1083

Answers (1)

huroran
huroran

Reputation: 62

Very late answer, but it may help somebody else. There's no such thing as "displayname" on iOS. You should look for the name object.

    filter              =   ["name", "phoneNumbers", "emails"];

And on the success function, you should look for the first name and last name like this :

var firstName = contacts[i].name.givenName;
var lastName = contacts[i].name.familyName;

Upvotes: 3

Related Questions