Chapter 13
Contacts
WHAT YOU WILL LEARN IN THIS CHAPTER:
- Learning about creating contacts
- Learning about finding contacts
- Handling errors
No matter what kind of device a person owns (iOS, Android, BlackBerry, Palm webOS, and so on), it is bound to have a Contacts database built in to it. The Contacts database contains all the contacts that a person stores on the phone — friends, family, business colleagues, and others — but that isn’t a guarantee that every phone manufacturer will follow a standard when it comes to the contact fields it stores and retrieves.
That being said, the PhoneGap Contacts API does a remarkably good job of letting users create, update, and find contacts, all of which you learn about in this chapter.
LEARNING ABOUT CREATING CONTACTS
The easiest way to learn how to use the Contacts API is to create a contact. You create a contact with the contacts.create() method, like this:
var myContact = navigator.contacts.create(properties);
When you use this method, it creates a new Contact object that you can then manipulate.
Following is an example:
var properties = {"displayName": "Joe Smith", "gender":"male"; } var myContact = navigator.contacts.create(properties);
You could also do this:
var myContact = navigator.contacts.create(); myContact.displayName = "Joe Smith"; myContact.gender = "male";
Here is a full list of properties you can work with:
- id — This is a globally unique identifier (GUID).
- displayName — This is the name of this contact, suitable for ...