Harry
Harry

Reputation: 13329

Phonegap - Adding a Contact to iPad - Empty Contact

On the iPad 5.1 Simulator I'm trying to add a contact to the phonebook like this:

contact = navigator.contacts.create()
contact.displayName = "Plumber"
contact.save()

The contact is saved but as an empty contact. Am I doing something wrong here?

We are using cordova-2.0.0.

Upvotes: 1

Views: 333

Answers (1)

Lloyd Smith
Lloyd Smith

Reputation: 1187

What I had to do was something like this...

    var contact = navigator.contacts.create();
    var fullName = new ContactName();

            fullName.givenName = "John";
            fullName.familyName = "Doe";
            fullName.formatted = "John Doe";
            contact.name = fullName;
    contact.save();

That should allow you to save the contact with a name.

http://docs.phonegap.com/en/2.0.0/cordova_contacts_contacts.md.html#Contacts

If you head to the Contact Object section, you can find some more examples on adding contacts.

Upvotes: 1

Related Questions