@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
notefield is not supported on iOS: reading or writing it requires Apple's restrictedcom.apple.developer.contacts.notesentitlement. The field is omitted on read and ignored on save. - Contact
ids are opaqueCNContactidentifiers; 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 は権限を必要としません。連絡先アプリを開き、
電話番号、メールアドレス、住所のいずれかを選べるようにします。アプリには、
ユーザーが選んだ項目に限り、一時的な読み取り権限が与えられます。
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>