快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-contacts`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/contacts/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-contacts` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
npm install @capgo/capacitor-contactsnpx cap sync导入
“导入”章节import { CapacitorContacts } from '@capgo/capacitor-contacts';快速入门
章节标题为“快速入门”请求访问权限后,使用合理的分页大小加载联系人,而不是加载整个通讯录。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.requestPermissions();const { contacts } = await CapacitorContacts.getContacts({ limit: 50, offset: 0 });// Increase offset by limit for the next page instead of loading the full address book.常见坑点
章节标题为“常见陷阱”- 理由: 在弹出对话框前,说明为什么需要访问联系人。
- 分页: 避免一次性加载整个通讯录。
- 写入: 创建联系人需要写入权限。
API 概览
章节标题:“API 概览”countContacts
“countContacts” 章节统计设备上的联系人总数。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.countContacts();console.log(result);createContact
“createContact” 部分以编程方式创建新联系人。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.createContact({ contact: {} });console.log(result);createGroup
“createGroup” 部分创建一个新的联系人分组。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.createGroup({ group: { name: 'example' } });console.log(result);deleteContactById
“deleteContactById” 部分根据 ID 删除联系人。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.deleteContactById({ id: 'id-123' });deleteGroupById
标题为 “deleteGroupById” 的章节根据 ID 删除分组。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.deleteGroupById({ id: 'id-123' });displayContactById
标题为 “displayContactById” 的章节使用原生联系人查看器显示联系人。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.displayContactById({ id: 'id-123' });displayCreateContact
标题为 “displayCreateContact” 的章节调起原生的创建联系人界面。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.displayCreateContact();console.log(result);displayUpdateContactById
标题为 “displayUpdateContactById” 的章节显示指定联系人的原生联系人更新 UI。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.displayUpdateContactById({ id: 'id-123' });getAccounts
标题为“getAccounts”的章节获取设备上所有可用的账户。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getAccounts();console.log(result);getContactById
“getContactById” 章节按 ID 获取指定联系人。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getContactById({ id: 'id-123' });// The result holds sensitive values: use it without logging it.getContacts
“getContacts” 章节获取设备上的所有联系人。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getContacts();// The result holds sensitive values: use it without logging it.getGroupById
“getGroupById” 章节按 ID 获取指定分组。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getGroupById({ id: 'id-123' });console.log(result);getGroups
“getGroups” 章节获取所有联系人分组。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getGroups();console.log(result);isAvailable
标题为 “isAvailable” 的章节检查设备上联系人功能是否可用。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.isAvailable();console.log(result);isSupported
标题为“isSupported”的部分检查当前平台是否支持该插件。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.isSupported();console.log(result);openSettings
标题为“openSettings”的章节打开设备的联系人设置。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.openSettings();pickContact
标题为“pickContact”的章节使用原生联系人选择器选择单个联系人。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.pickContact();// The result holds sensitive values: use it without logging it.pickContacts
标题为“pickContacts”的章节使用原生联系人选择器选择一个或多个联系人。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.pickContacts();// The result holds sensitive values: use it without logging it.updateContactById
标题为“updateContactById”的章节按 ID 更新现有联系人。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.updateContactById({ id: 'id-123', contact: {},});checkPermissions
“checkPermissions” 章节检查当前的联系人权限状态。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.checkPermissions();console.log(result);requestPermissions
“requestPermissions” 章节请求访问联系人的权限。
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.requestPermissions();console.log(result);类型参考
“类型参考” 章节CountContactsResult
标题为“CountContactsResult”的章节统计联系人数量的结果。
export interface CountContactsResult { /** * Total number of contacts. * * @since 1.0.0 */ count: number;}CreateContactOptions
标题为“CreateContactOptions”的章节创建联系人的选项。
export interface CreateContactOptions { /** * Contact information to create. The 'id' field will be generated automatically. * * @since 1.0.0 */ contact: Omit<Contact, 'id'>;}CreateContactResult
标题为“CreateContactResult”的章节创建联系人的结果。
export interface CreateContactResult { /** * The ID of the newly created contact. * * @since 1.0.0 */ id: string;}CreateGroupOptions
标题为“CreateGroupOptions”的章节创建群组的选项。
export interface CreateGroupOptions { /** * Group information to create. The 'id' field will be generated automatically. * * @since 1.0.0 */ group: Omit<Group, 'id'>;}CreateGroupResult
标题为“CreateGroupResult”的章节创建群组的结果。
export interface CreateGroupResult { /** * The ID of the newly created group. * * @since 1.0.0 */ id: string;}DeleteContactByIdOptions
标题为“DeleteContactByIdOptions”的章节按 ID 删除联系人的选项。
export interface DeleteContactByIdOptions { /** * The ID of the contact to delete. * * @since 1.0.0 */ id: string;}DeleteGroupByIdOptions
标题为“DeleteGroupByIdOptions”的章节通过 ID 删除组的选项。
export interface DeleteGroupByIdOptions { /** * The ID of the group to delete. * * @since 1.0.0 */ id: string;}DisplayContactByIdOptions
标题为 “DisplayContactByIdOptions” 的章节通过 ID 显示联系人的选项。
export interface DisplayContactByIdOptions { /** * The ID of the contact to display. * * @since 1.0.0 */ id: string;}DisplayCreateContactOptions
标题为 “DisplayCreateContactOptions” 的章节显示原生创建联系人 UI 的选项。
export interface DisplayCreateContactOptions { /** * Optional pre-filled contact information for the create UI. * * @since 1.0.0 */ contact?: Omit<Contact, 'id'>;}DisplayCreateContactResult
标题为 “DisplayCreateContactResult” 的章节显示原生创建联系人 UI 的结果。
export interface DisplayCreateContactResult { /** * The ID of the created contact, if one was created. Undefined if the user cancelled. * * @since 1.0.0 */ id?: string;}DisplayUpdateContactByIdOptions
标题为 “DisplayUpdateContactByIdOptions” 的章节显示原生更新联系人 UI 的选项。
export interface DisplayUpdateContactByIdOptions { /** * The ID of the contact to update. * * @since 1.0.0 */ id: string;}GetAccountsResult
标题为“GetAccountsResult”的部分获取账户的结果。
export interface GetAccountsResult { /** * List of accounts available on the device. * * @since 1.0.0 */ accounts: Account[];}单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-contacts 针对使用 @capgo/capacitor-contacts 时的原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。