开始使用
复制一个包含安装步骤和本插件完整 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 及更高版本区分只写和全日历访问。仅在您的应用程序调用提醒 API 时包括提醒使用说明。
苹果参考: 迁移到最新的日历访问级别.
Android 设置
Android 设置添加日历权限您的应用程序需要 android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_CALENDAR" /><uses-permission android:name="android.permission.WRITE_CALENDAR" />Android参考: 日历提供者用户权限.
请求日历访问
标题:请求日历访问import { CapacitorCalendar } from '@capgo/capacitor-calendar';
const permission = await CapacitorCalendar.requestFullCalendarAccess();
if (permission.result !== 'granted') { throw new Error('Calendar permission was not granted');}仅添加事件的应用程序使用 requestWriteOnlyCalendarAccess()仅在 Android 上读取流程时使用 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定义中维护。

