コンテンツに進む

はじめよう

GitHub

CapgoのAIアシストセットアップを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを使用してください。

ターミナル画面
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.

Manual Setupを使用する場合は、以下のコマンドを実行し、下記のプラットフォーム固有の手順に従ってください。

ターミナルウィンドウ
npm install @capgo/capacitor-calendar
npx cap sync

アプリに必要な使用方法の説明を追加します。 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を呼び出す場合のみ、リマインダーの使用方法の説明を含めます。

Appleの公式リファレンス: 最新のカレンダーへのアクセスレベルへの移行.

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');
}

Androidのみの読み取りフローでは、を使用します。 requestWriteOnlyCalendarAccess()イベントを作成する 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ではシステムカレンダーピッカーを表示したいときに利用可能です。

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のサンプルアプリが含まれます。

iOSAndroid
ネイティブのカレンダーイベントのiOSデモAndroid のネイティブ カレンダー イベントの作成

API リファレンス

API リファレンス

The complete API reference is maintained in the package README and TypeScript definitions: