Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Contacts

Improve this doc

Access and manage Contacts on the device.

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

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-contacts
    $ npm install --save @ionic-native/contacts@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

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

constructor(private contacts: Contacts) { }

let contact: Contact = this.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)
);

Instance 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 queryOptional

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

Contact

Instance Members

id()

rawId()

displayName()

name()

nickname()

phoneNumbers()

emails()

addresses()

ims()

organizations()

birthday()

note()

photos()

categories()

urls()

clone()

remove()

save()

IContactProperties

Param Type Details
id string

A globally unique identifier.

(optional)
rawId string

A globally unique identifier on Android.

(optional)
displayName string

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

(optional)
name IContactName

An object containing all components of a persons name.

(optional)
nickname string

A casual name by which to address the contact.

(optional)
phoneNumbers IContactField[]

An array of all the contact's phone numbers.

(optional)
emails IContactField[]

An array of all the contact's email addresses.

(optional)
addresses IContactAddress[]

An array of all the contact's addresses.

(optional)
ims IContactField[]

An array of all the contact's IM addresses.

(optional)
organizations IContactOrganization[]

An array of all the contact's organizations.

(optional)
birthday Date

The birthday of the contact.

(optional)
note string

A note about the contact.

(optional)
photos IContactField[]

An array of the contact's photos.

(optional)
categories IContactField[]

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

(optional)
urls IContactField[]

An array of web pages associated with the contact.

(optional)

IContactError

Param Type Details
code number

Error code

message string

Error message

IContactName

Param Type Details
formatted string

The complete name of the contact.

(optional)
familyName string

The contact's family name.

(optional)
givenName string

The contact's given name.

(optional)
middleName string

The contact's middle name.

(optional)
honorificPrefix string

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

(optional)
honorificSuffix string

The contact's suffix (example Esq.).

(optional)

IContactField

Param Type Details
type string

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

(optional)
value string

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

(optional)
pref boolean

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

(optional)

IContactAddress

Param Type Details
pref boolean

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

(optional)
type string

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

(optional)
formatted string

The full address formatted for display.

(optional)
streetAddress string

The full street address.

(optional)
locality string

The city or locality.

(optional)
region string

The state or region.

(optional)
postalCode string

The zip code or postal code.

(optional)
country string

The country name.

(optional)

IContactOrganization

Param Type Details
pref boolean

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

(optional)
type string

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

(optional)
name string

The name of the organization.

(optional)
department string

The department the contract works for.

(optional)
title string

The contact's title at the organization.

(optional)

IContactFindOptions

Param Type Details
filter string

The search string used to find navigator.contacts.

(optional)
multiple boolean

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

(optional)
desiredFields string[]

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

(optional)
hasPhoneNumber boolean

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

(optional)

API

Native

General