コンテンツにジャンプ

始め方

GitHub

インストール

インストール

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-calendar
npx cap sync

iOS設定

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

Apple の参考資料: 最新のカレンダー アクセス レベルへの移行.

アプリに必要なカレンダー許可を追加します。 android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

Android の参考資料: Calendar Provider ユーザー許可.

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__CAPGO_KEEP_0__のイベントをリストアップするには、作成されたイベントIDが必要です。

イベントの予定

__CAPGO_KEEP_1__
const now = Date.now();
const oneWeekFromNow = now + 7 * 24 * 60 * 60 * 1000;
const { result: events } = await CapacitorCalendar.listEventsInRange({
from: now,
to: oneWeekFromNow,
});

カレンダーを選択

__CAPGO_KEEP_3__
const { result: calendars } = await CapacitorCalendar.listCalendars();
const { result: defaultCalendar } = await CapacitorCalendar.getDefaultCalendar();
const calendarId = defaultCalendar?.id ?? calendars[0]?.id;

selectCalendarsWithPrompt() iOSでシステムカレンダー ピッカーを表示したい場合は利用可能です。

iOS用のリマインダーを作成

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

__CAPGO_KEEP_1__

Capacitor 例のアプリは、許可のチェック、イベントの作成、ネイティブのイベントの提示、カレンダーのリスト、イベントの範囲のリストを含みます。

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

API の完全なリファレンスは、パッケージのREADMEとTypeScriptの定義で管理されています。