メインコンテンツにジャンプ
プラグインに戻る
@capgo/capacitor-カレンダー
チュートリアル
@capgo/capacitor-カレンダー

カレンダー

iOSとAndroidでネイティブのカレンダーイベントを管理し、iOSのリマインダー機能をサポート

デモ

WebPアニメーション

iOSとAndroidでカレンダーイベントを作成

ソースアセット
iOSのカレンダーイベント作成
iOSイベント作成
Androidのカレンダーイベント作成
Androidイベント作成

ガイド

カレンダーのチュートリアル

デバイスでテスト

Download the Capgo app, then scan the QR code.

Calendar plugin preview QR code

Using @capgo/capacitor-calendar

Capacitorのcalendarプラグインを使用 @capgo/capacitor-calendar パッケージは、Capacitor アプリがiOSとAndroidでネイティブのカレンダーイベントを管理できるようにします。カレンダーペリミッションを要求し、イベントを作成・編集し、ネイティブのカレンダーUIを開き、カレンダーとイベントをリストし、iOSでRemindersを管理できます。

インストール

npm install @capgo/capacitor-calendar
npx cap sync

ネイティブパーミッションを設定

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>NSRemindersFullAccessUsageDescription</key>
<string>This app needs permission to read and manage reminders.</string>

Androidでは、必要なカレンダーペリミッションを追加してください。 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');
}

イベントを作成

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

ネイティブのイベントUIを開く

await CapacitorCalendar.createEventWithPrompt({
  title: 'Planning session',
  location: 'Office',
  startDate: Date.now() + 24 * 60 * 60 * 1000,
  endDate: Date.now() + 25 * 60 * 60 * 1000,
});

イベントをリスト

const now = Date.now();

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

iOSのReminders

const permission = await CapacitorCalendar.requestFullRemindersAccess();

if (permission.result === 'granted') {
  await CapacitorCalendar.createReminder({
    title: 'Send launch notes',
    dueDate: Date.now() + 2 * 24 * 60 * 60 * 1000,
  });
}

RemindersはiOSのみで利用可能です。

フルリファレンス