开始使用
复制一个带有安装步骤和完整 Markdown 指南的设置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-calendar`
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/calendar/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 技能添加到您的 AI 工具中,使用以下命令:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-calendar` plugin in my project.如果您更喜欢手动设置,请运行以下命令安装插件,并按照以下平台特定的说明进行操作:
npm install @capgo/capacitor-calendarnpx cap synciOS 设置
标题为“iOS 设置”的部分向您的应用程序添加所需的使用说明 ios/App/App/Info.plist:
<key>NSCalendarsUsageDescription</key><string>This app needs calendar access.</string><key>NSCalendarsWriteOnlyAccessUsageDescription</key><string>This app needs permission to add calendar events.</string><key>NSCalendarsFullAccessUsageDescription</key><string>This app needs permission to read and manage calendar events.</string><key>NSRemindersUsageDescription</key><string>This app needs reminders access.</string><key>NSRemindersFullAccessUsageDescription</key><string>This app needs permission to read and manage reminders.</string>从 iOS 17 开始,新版 iOS 可以区分只写和全日历访问权限。只有在您的应用程序调用提醒 API 时才包括提醒使用说明。
苹果参考: 迁移到最新的日历访问级别.
安卓设置
安卓设置添加您的应用程序需要的日历权限 android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_CALENDAR" /><uses-permission android:name="android.permission.WRITE_CALENDAR" />安卓参考: 日历提供者用户权限.
请求日历访问
复制到剪贴板import { CapacitorCalendar } from '@capgo/capacitor-calendar';
const permission = await CapacitorCalendar.requestFullCalendarAccess();
if (permission.result !== 'granted') { throw new Error('Calendar permission was not granted');}仅用于安卓的读取流程使用 requestWriteOnlyCalendarAccess()Calendar Provider user permissions requestReadOnlyCalendarAccess().
创建事件
标题:创建事件日期以毫秒的 Unix 时间戳形式表示。
import { CapacitorCalendar } from '@capgo/capacitor-calendar';
const startDate = Date.now() + 60 * 60 * 1000;const endDate = startDate + 60 * 60 * 1000;
const { id } = await CapacitorCalendar.createEvent({ title: 'Product review', location: 'Capgo', startDate, endDate, description: 'Created with @capgo/capacitor-calendar',});
console.log('Created event', id);打开本地事件编辑器
标题:打开本地事件编辑器await CapacitorCalendar.createEventWithPrompt({ title: 'Planning session', location: 'Office', startDate: Date.now() + 24 * 60 * 60 * 1000, endDate: Date.now() + 25 * 60 * 60 * 1000,});在 Android 上,基于提示的创建和修改调用返回 null. 如果需要找到创建的事件 ID,请列出之后的事件。
列出即将到来的事件
标题:列出即将到来的事件const now = Date.now();const oneWeekFromNow = now + 7 * 24 * 60 * 60 * 1000;
const { result: events } = await CapacitorCalendar.listEventsInRange({ from: now, to: oneWeekFromNow,});选择一个日历
标题:选择一个日历const { result: calendars } = await CapacitorCalendar.listCalendars();const { result: defaultCalendar } = await CapacitorCalendar.getDefaultCalendar();
const calendarId = defaultCalendar?.id ?? calendars[0]?.id;selectCalendarsWithPrompt() 在 iOS 上可用,当您想要显示系统日历选择器时。
创建一个 iOS 提醒
标题:创建一个 iOS 提醒const permission = await CapacitorCalendar.requestFullRemindersAccess();
if (permission.result === 'granted') { await CapacitorCalendar.createReminder({ title: 'Send launch notes', dueDate: Date.now() + 2 * 24 * 60 * 60 * 1000, notes: 'Created with @capgo/capacitor-calendar', });}提醒 API 仅限 iOS。
示例应用
标题:示例应用仓库包含一个 Capacitor 示例应用,包括权限检查、事件创建、原生事件提示、日历列表和事件范围列表。
| iOS | Android |
|---|---|
![]() | ![]() |
API参考
API参考完整的API参考文档保存在包README和TypeScript定义中:

