Contacts

Improve this doc

$ ionic plugin add cordova-plugin-contacts

Repo: https://github.com/apache/cordova-plugin-contacts

Access and manage Contacts on the device.

Usage

import { Contacts, Contact, ContactField, ContactName } from 'ionic-native';


let contact: Contact = Contacts.create();

contact.name = new ContactName(null, 'Smith', 'John');
contact.phoneNumbers = [new ContactField('mobile', '6471234567')];
contact.save().then(
  () => console.log('Contact saved!', contact),
  (error: any) => console.error('Error saving contact.', error)
);

Static Members

create()

Create a single contact.

Returns: Contact Returns a Contact object

find(fields, options)

Search for contacts in the Contacts list.

Param Type Details
fields ContactFieldType[]

Contact fields to be used as a search qualifier

options IContactFindOptions

Optional options for the query

Returns: Promise<Contact[]> Returns a Promise that resolves with the search results (an array of Contact objects)

pickContact()

Select a single Contact.

Returns: Promise<Contact> Returns a Promise that resolves with the selected Contact

IContactProperties

Param Type Details
id
(optional)
string

A globally unique identifier.

displayName
(optional)
string

The name of this Contact, suitable for display to end users.

name
(optional)
IContactName

An object containing all components of a persons name.

nickname
(optional)
string

A casual name by which to address the contact.

phoneNumbers
(optional)
IContactField[]

An array of all the contact's phone numbers.

emails
(optional)
IContactField[]

An array of all the contact's email addresses.

addresses
(optional)
IContactAddress[]

An array of all the contact's addresses.

ims
(optional)
IContactField[]

An array of all the contact's IM addresses.

organizations
(optional)
IContactOrganization[]

An array of all the contact's organizations.

birthday
(optional)
Date

The birthday of the contact.

note
(optional)
string

A note about the contact.

photos
(optional)
IContactField[]

An array of the contact's photos.

categories
(optional)
IContactField[]

An array of all the user-defined categories associated with the contact.

urls
(optional)
IContactField[]

An array of web pages associated with the contact.

IContactError

Param Type Details
code number

Error code

message string

Error message

IContactName

Param Type Details
formatted
(optional)
string

The complete name of the contact.

familyName
(optional)
string

The contact's family name.

givenName
(optional)
string

The contact's given name.

middleName
(optional)
string

The contact's middle name.

honorificPrefix
(optional)
string

The contact's prefix (example Mr. or Dr.)

honorificSuffix
(optional)
string

The contact's suffix (example Esq.).

IContactField

Param Type Details
type
(optional)
string

A string that indicates what type of field this is, home for example.

value
(optional)
string

The value of the field, such as a phone number or email address.

pref
(optional)
boolean

Set to true if this ContactField contains the user's preferred value.

IContactAddress

Param Type Details
pref
(optional)
boolean

Set to true if this ContactAddress contains the user's preferred value.

type
(optional)
string

A string indicating what type of field this is, home for example.

formatted
(optional)
string

The full address formatted for display.

streetAddress
(optional)
string

The full street address.

locality
(optional)
string

The city or locality.

region
(optional)
string

The state or region.

postalCode
(optional)
string

The zip code or postal code.

country
(optional)
string

The country name.

IContactOrganization

Param Type Details
pref
(optional)
boolean

Set to true if this ContactOrganization contains the user's preferred value.

type
(optional)
string

A string that indicates what type of field this is, home for example.

name
(optional)
string

The name of the organization.

department
(optional)
string

The department the contract works for.

title
(optional)
string

The contact's title at the organization.

IContactFindOptions

Param Type Details
filter
(optional)
string

The search string used to find navigator.contacts.

multiple
(optional)
boolean

Determines if the find operation returns multiple navigator.contacts. Defaults to false.

desiredFields
(optional)
string[]

Contact fields to be returned back. If specified, the resulting Contact object only features values for these fields.

hasPhoneNumber
(optional)
boolean

(Android only): Filters the search to only return contacts with a phone number informed.

API

Native

General