メインコンテンツまでスキップ
バージョン: v8

@capacitor/contacts

端末の連絡先にアクセスして検索、選択、作成、更新、削除できます。Web では使用できません。

Install​

To use npm

npm install @capacitor/contacts

To use yarn

yarn add @capacitor/contacts

Sync native files

npx cap sync

iOS​

Add the NSContactsUsageDescription key to your app's Info.plist and describe why the app accesses the user's contacts; iOS crashes on first contacts access without it:

<key>NSContactsUsageDescription</key>
<string>We need access to contacts to search, save and remove them.</string>

Notes:

  • プラグインは非推奨の AddressBook API に代わり、現在の Contacts フレームワーク(CNContactStore)を 使用しており、iOS 18 以降のLimited Accessに対応しています。 このモードでは、find、save、remove の操作は、 ユーザーがアプリと共有した連絡先だけが対象です。一方、pickContact と pickContactField は システムの選択画面を開きます。この画面は権限を必要とせず、常にすべての 連絡先を表示します。
  • The note field is not supported on iOS: reading or writing it requires Apple's restricted com.apple.developer.contacts.notes entitlement. The field is omitted on read and ignored on save.
  • Contact ids are opaque CNContact identifiers; ids persisted by the legacy AddressBook-based Cordova plugin do not resolve after migration.

Android​

プラグインは自身のマニフェストで READ_CONTACTS と WRITE_CONTACTS を宣言し、 Gradle がアプリのマニフェストに自動でマージします。 各メソッドは初回実行時に必要な権限を要求します。 find / pickContact には読み取り、save / remove には読み書きの権限が必要です。 pickContactField は権限を必要としません。連絡先アプリを開き、 電話番号、メールアドレス、住所のいずれかを選べるようにします。アプリには、 ユーザーが選んだ項目に限り、一時的な読み取り権限が与えられます。

Google Play の要件

pickContactField は、主に Google Play の連絡先権限の制限に対応するためのメソッドです。この制限は Capacitor 9 以降を使用するアプリが対象です。アプリの用途を pickContactField だけで満たせるか確認してください。ほかのアクセスも必要な場合は、Play Console で申告が必要になることがあります。詳しくは Google Play の説明を参照してください。

アプリが pickContactField だけを使用する場合は、連絡先権限を除外できます。 アプリの AndroidManifest.xml に次のように記述し、 マージ後のマニフェストから権限を削除してください。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_CONTACTS" tools:node="remove" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" tools:node="remove" />
</manifest>

この場合、ほかのメソッドは必要な権限が宣言されていないため、 OS-PLUG-CONT-0021 で失敗します。

Permission model​

このプラグインには checkPermissions() や requestPermissions() はありません。 旧 cordova-plugin-contacts と同様に、それぞれのメソッドが 必要な権限を暗黙的に要求します。 ユーザーがアクセスを拒否すると、呼び出しは OS-PLUG-CONT-0020 で失敗します。pickContactField は 権限を必要としません。Android では、ほかのメソッドに必要な権限が アプリのマニフェストに宣言されていない場合、 OS-PLUG-CONT-0021 が返ります。

Errors​

Every rejection carries a structured code + message:

CodeMeaning
OS-PLUG-CONT-0000Unknown error
OS-PLUG-CONT-0001Invalid argument (e.g. unknown id)
OS-PLUG-CONT-0002Timeout (reserved, currently unused)
OS-PLUG-CONT-0003Pending operation (e.g. picker already open)
OS-PLUG-CONT-0004I/O error
OS-PLUG-CONT-0005Not supported
OS-PLUG-CONT-0006Operation cancelled (picker closed)
OS-PLUG-CONT-0020Permission denied
OS-PLUG-CONT-0021Android マニフェストに必要な権限が宣言されていません。

Usage​

import { Contacts } from '@capacitor/contacts';

// Search every field for "ada" and return all matches with a phone number
const { contacts } = await Contacts.find({
fields: ['*'],
filter: 'ada',
multiple: true,
hasPhoneNumber: true,
});

// Create a contact
const saved = await Contacts.save({
contact: {
name: { givenName: 'Ada', familyName: 'Lovelace' },
phoneNumbers: [{ type: 'mobile', value: '+351910000000' }],
emails: [{ type: 'home', value: 'ada@example.com' }],
},
});

// Update it (id present -> update)
await Contacts.save({ contact: { ...saved, nickname: 'Countess' } });

// ネイティブの選択画面で連絡先を選びます。Android では連絡先権限が必要です。
const picked = await Contacts.pickContact();

// 電話番号、メールアドレス、住所のいずれかを1件選びます。どちらのプラットフォームでも連絡先権限は不要です。
const { value, type, displayName } = await Contacts.pickContactField({ field: 'phone' });

// Remove it by id
await Contacts.remove({ id: saved.id! });

API​

find(...)​

find(options: ContactFindOptions) => Promise<ContactFindResult>

Queries the device contacts database and returns the matching contacts.

Requests the READ_CONTACTS (Android) / Contacts (iOS) permission internally the first time it runs; there is no separate permission method.

iOS 18+: under Limited Access the search runs against (and returns only) the subset of contacts the user shared with the app.

ParamType
options
ContactFindOptions

Returns:

Promise<ContactFindResult>

Since: 1.0.0


save(...)​

save(options: ContactSaveOptions) => Promise<Contact>

Persists a new contact or updates an existing one (matched by contact.id). Resolves with the full saved contact.

Requests the READ/WRITE_CONTACTS (Android) / Contacts (iOS) permission internally.

iOS 18+: works under Limited Access: new contacts are added to the app's accessible set; updating requires the target contact to be in that set (otherwise the call rejects with OS-PLUG-CONT-0001).

ParamType
options
ContactSaveOptions

Returns:

Promise<Contact>

Since: 1.0.0


remove(...)​

remove(options: ContactRemoveOptions) => Promise<void>

Removes the contact with the given id from the device contacts database. Rejects with OS-PLUG-CONT-0001 when no contact has that id (on iOS 18+ Limited Access, also when the contact is outside the accessible set).

Requests the READ/WRITE_CONTACTS (Android) / Contacts (iOS) permission internally.

ParamType
options
ContactRemoveOptions

Since: 1.0.0


pickContact()​

pickContact() => Promise<Contact>

Launches the native contact picker UI and resolves with the contact the user selects. Rejects with OS-PLUG-CONT-0006 if the user cancels.

On iOS the system picker requires no permission and always shows the full contact list, even under iOS 18+ Limited Access (the picked contact is returned without joining the app's accessible set). On Android the READ_CONTACTS permission is requested internally to read the picked contact's details.

Returns:

Promise<Contact>

Since: 1.0.0


pickContactField(...)​

pickContactField(options: PickContactFieldOptions) => Promise<PickedContactField>

ネイティブの連絡先選択画面に、指定した種類の情報だけを表示します。 戻り値は、ユーザーが選んだ単一の値です。連絡先全体は返しません。 ユーザーがキャンセルした場合は OS-PLUG-CONT-0006 で失敗します。

どちらのプラットフォームでも連絡先権限は不要です。Android アプリは マニフェストから READ_CONTACTS を省略できます。1回の呼び出しで選択できる データの種類は1つです。

ParamType
options
PickContactFieldOptions

Returns:

Promise<PickedContactField>

Since: 1.1.0


Interfaces​

ContactFindResult​

Result of a {@link ContactsPlugin.find} call.

PropTypeDescriptionSince
contactsContact[]The contacts matching the search criteria.1.0.0

Contact​

A single device contact.

PropTypeDescriptionSince
idstringGlobally unique, platform-assigned identifier. Absent for contacts not yet saved to the device.1.0.0
rawIdstringAndroid raw-contact id backing this aggregated contact. iOS leaves this unset.1.0.0
displayNamestringName suitable for display to end users.1.0.0
name
ContactName
The structured name components.1.0.0
nicknamestringA casual name by which to address the contact.1.0.0
phoneNumbersContactField[]The contact's phone numbers.1.0.0
emailsContactField[]The contact's email addresses.1.0.0
addressesContactAddress[]The contact's postal addresses.1.0.0
imsContactField[]The contact's instant-messaging handles.1.0.0
organizationsContactOrganization[]The contact's organizations.1.0.0
birthdaynumberThe contact's birthday as epoch milliseconds.1.0.0
notestringA free-form note about the contact. iOS: not supported by default: reading/writing a contact's note requires Apple's restricted com.apple.developer.contacts.notes entitlement. Without it the field is omitted on read and ignored on save. Android has no such restriction.1.0.0
photosContactField[]The contact's photos. Reads return type: 'url' with the value holding a reference to the image, never image bytes: on Android the contact's content:// photo URI, on iOS the path of a copy written to the app's temporary directory (cleared by the system). On save, the first entry is applied: pass type: 'base64' with base64 data, or type: 'url' with a local file:///content:// URI to import.1.0.0
categoriesContactField[]User-defined categories associated with the contact. Read-only: populated from the contact's group memberships on Android, never returned on iOS (the Contacts framework has no equivalent), and ignored on save.1.0.0
urlsContactField[]Web pages associated with the contact.1.0.0

ContactName​

Structured name of a {@link Contact}.

PropTypeDescriptionSince
formattedstringThe complete formatted name.1.0.0
familyNamestringFamily (last) name.1.0.0
givenNamestringGiven (first) name.1.0.0
middleNamestringMiddle name.1.0.0
honorificPrefixstringHonorific prefix (e.g. Mr., Dr.).1.0.0
honorificSuffixstringHonorific suffix (e.g. Esq.).1.0.0

ContactField​

A generic, repeatable contact field (phone number, email, IM, photo, URL, category).

PropTypeDescriptionSince
typestringThe kind of field, e.g. home, work, mobile. For photos, url or base64.1.0.0
valuestringThe field value (phone number, email address, URI, etc.).1.0.0
prefbooleantrue if this is the contact's preferred value for the field.1.0.0
idstringPlatform-assigned id of this individual field entry.1.0.0

ContactAddress​

A postal address of a {@link Contact}.

PropTypeDescriptionSince
idstringPlatform-assigned id of this address entry.1.0.0
prefbooleantrue if this is the contact's preferred address.1.0.0
typestringThe kind of address, e.g. home, work.1.0.0
formattedstringThe full address formatted for display.1.0.0
streetAddressstringThe street address.1.0.0
localitystringThe city or locality.1.0.0
regionstringThe state or region.1.0.0
postalCodestringThe ZIP or postal code.1.0.0
countrystringThe country name.1.0.0

ContactOrganization​

An organization a {@link Contact} belongs to.

PropTypeDescriptionSince
idstringPlatform-assigned id of this organization entry. Android only; iOS models the organization as flat contact properties without an id.1.0.0
prefbooleantrue if this is the contact's preferred organization.1.0.0
typestringThe kind of organization, e.g. work.1.0.0
namestringThe organization name.1.0.0
departmentstringThe department within the organization.1.0.0
titlestringThe contact's title at the organization.1.0.0

ContactFindOptions​

Search options accepted by {@link ContactsPlugin.find}.

PropTypeDescriptionSince
fieldsContactFieldType[]Fields to search against. Pass ['*'] to match every field. An empty array is invalid and rejects with OS-PLUG-CONT-0001. The id field matches by exact identifier; all other fields match case-insensitive substrings. photos and categories are not searchable.1.0.0
filterstringSearch string matched (case-insensitively) against the selected fields. An empty/omitted filter returns every contact.1.0.0
multiplebooleanWhen true, returns every match; when false (default), returns at most one contact.1.0.0
desiredFieldsContactFieldType[]If set, each returned {@link Contact} only includes these fields (plus the always-present id).1.0.0
hasPhoneNumberbooleanOutSystems extension: when true, only contacts that have at least one phone number are returned. Defaults to false.1.0.0

ContactSaveOptions​

Options accepted by {@link ContactsPlugin.save}.

PropTypeDescriptionSince
contact
Contact
The contact to create (no id) or update (existing id). Update semantics: every field present on the contact replaces the stored value entirely (e.g. name replaces the whole structured name, phoneNumbers replaces all phone numbers); omitted fields are left unchanged.1.0.0

ContactRemoveOptions​

Options accepted by {@link ContactsPlugin.remove}.

PropTypeDescriptionSince
idstringThe native id of the contact to remove.1.0.0

PickedContactField​

{@link ContactsPlugin.pickContactField} でユーザーが選んだ値です。 連絡先のうち、選んだ値とそのラベル、 および連絡先の表示名だけを含みます。

PropTypeDescriptionSince
field'phone' | 'email' | 'address'選択した値の種類。要求時の指定に対応します。1.1.0
valuestring選択した電話番号、メールアドレス、または表示用に整形された住所。field に応じて決まります。1.1.0
typestring選択した値のラベル(例: mobile、home、work)。1.1.0
displayNamestring取得できる場合は、選択した値が属する連絡先の表示名。1.1.0
address
PickedContactAddress
住所の構成要素。field が address の場合のみ含まれます。1.1.0

PickedContactAddress​

{@link ContactsPlugin.pickContactField} が返す住所の構成要素。

PropTypeDescriptionSince
streetAddressstring番地などの住所。1.1.0
localitystring市区町村。1.1.0
regionstring州または地域。1.1.0
postalCodestring郵便番号。1.1.0
countrystring国。1.1.0

PickContactFieldOptions​

{@link ContactsPlugin.pickContactField} に渡すオプション。

PropTypeDescriptionSince
field'phone' | 'email' | 'address'選択する連絡先情報の種類を1つ指定します。対応していない値では OS-PLUG-CONT-0001 が返ります。1.1.0

Type Aliases​

ContactFieldType​

The set of contact fields a {@link ContactsPlugin.find} call can search against or request back. Mirrors the legacy Cordova ContactFieldType string values exactly.

'addresses' | 'birthday' | 'categories' | 'country' | 'department' | 'displayName' | 'emails' | 'familyName' | 'formatted' | 'givenName' | 'honorificPrefix' | 'honorificSuffix' | 'id' | 'ims' | 'locality' | 'middleName' | 'name' | 'nickname' | 'note' | 'organizations' | 'phoneNumbers' | 'photos' | 'postalCode' | 'region' | 'streetAddress' | 'title' | 'urls'