メインコンテンツへスキップ

スタートガイド

GitHub

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-alarm` plugin in my project.

手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:

ターミナル
bun add @capgo/capacitor-alarm
npx cap sync
import { CapgoAlarm } from '@capgo/capacitor-alarm';
import { CapgoAlarm } from '@capgo/capacitor-alarm';
const result = await CapgoAlarm.createAlarm({
hour: 7,
minute: 30,
label: 'Wake up',
skipUi: false,
vibrate: true
});
console.log('Alarm created:', result.success);
import { CapgoAlarm } from '@capgo/capacitor-alarm';
const result = await CapgoAlarm.openAlarms();
if (result.success) {
console.log('Alarms UI opened');
}
import { CapgoAlarm } from '@capgo/capacitor-alarm';
const info = await CapgoAlarm.getOSInfo();
console.log('Platform:', info.platform);
console.log('Supports native alarms:', info.supportsNativeAlarms);
if (info.platform === 'android') {
console.log('Can schedule exact alarms:', info.canScheduleExactAlarms);
}
  • 権限: 呼び出し checkPermissions() その後 requestPermissions() 必要に応じて。
  • ネイティブ同期: 実行 npx cap sync プラグインのアップグレード後。
  • 信頼できる情報源: 信頼 src/definitions.ts GitHub リポジトリ内。

プラットフォームの時計アプリを使用して、ネイティブOSのアラームを作成します。 AndroidではAlarm Clock intentを使用し、iOSでは利用可能な場合(iOS 16以降)AlarmKitを使用します。

import { CapgoAlarm } from '@capgo/capacitor-alarm';
const result = await CapgoAlarm.createAlarm({
hour: 7,
minute: 30,
label: 'Wake up',
skipUi: false,
vibrate: true
});
console.log('Alarm created:', result.success);

利用可能な場合、プラットフォーム標準のアラーム一覧UIを開きます。

import { CapgoAlarm } from '@capgo/capacitor-alarm';
const result = await CapgoAlarm.openAlarms();
if (result.success) {
console.log('Alarms UI opened');
}

OSの情報と利用可能な機能を取得します。

import { CapgoAlarm } from '@capgo/capacitor-alarm';
const info = await CapgoAlarm.getOSInfo();
console.log('Platform:', info.platform);
console.log('Supports native alarms:', info.supportsNativeAlarms);
if (info.platform === 'android') {
console.log('Can schedule exact alarms:', info.canScheduleExactAlarms);
}

プラットフォーム上でアラームを使用するために、必要な権限をリクエストします。 Androidでは、正確なアラーム(exact alarms)の設定画面に遷移する場合があります。

import { CapgoAlarm } from '@capgo/capacitor-alarm';
const result = await CapgoAlarm.requestPermissions({ exactAlarm: true });
if (result.granted) {
console.log('Permissions granted');
} else {
console.log('Permissions denied');
}

UIを表示せずに、ネイティブのアラームアクセスに関する現在の権限状態を確認します。 iOSではAlarmKitの準備状況を、Androidでは機能の詳細を返します。

import { CapgoAlarm } from '@capgo/capacitor-alarm';
const status = await CapgoAlarm.checkPermissions();
console.log('AlarmKit allowed?', status.details?.alarmKit);

このアプリによってスケジュールされたアラームの一覧を取得します。 iOS 26以降ではAlarmKitからアラームを返します。Androidでは、システムがアラームを照会するための API を提供していないため、この機能はサポートされていません。

import { CapgoAlarm } from '@capgo/capacitor-alarm';
const { alarms } = await CapgoAlarm.getAlarms();
console.log('Scheduled alarms:', alarms);
alarms.forEach(alarm => {
console.log(`Alarm ${alarm.id}: ${alarm.hour}:${alarm.minute} - ${alarm.label}`);
});

プラットフォームの時計アプリを介して、ネイティブOSのアラームを作成するためのオプションです。

export interface NativeAlarmCreateOptions {
/** Hour of day in 24h format (0-23) */
hour: number;
/** Minute of hour (0-59) */
minute: number;
/** Optional label for the alarm */
label?: string;
/** Android only: attempt to skip UI if possible */
skipUi?: boolean;
/** Android only: set alarm to vibrate */
vibrate?: boolean;
}

ネイティブアクションの実行結果。

export interface NativeActionResult {
/** Whether the action was successful */
success: boolean;
/** Optional message with additional information */
message?: string;
}

現在のOSおよび機能に関する情報。

export interface OSInfo {
/** Platform identifier: 'ios' | 'android' | 'web' */
platform: string;
/** OS version string */
version: string;
/** Whether the platform exposes a native alarm app integration */
supportsNativeAlarms: boolean;
/** Whether scheduling local notifications is supported */
supportsScheduledNotifications: boolean;
/** Android only: whether exact alarms are allowed */
canScheduleExactAlarms?: boolean;
}

権限リクエストの結果。

export interface PermissionResult {
/** Overall grant for requested scope */
granted: boolean;
/** Optional details by permission key */
details?: Record<string, boolean>;
/** Optional human readable diagnostic */
message?: string;
}

スケジュールされたアラームの情報。

export interface AlarmInfo {
/** Unique identifier for the alarm */
id: string;
/** Hour of day in 24h format (0-23) */
hour: number;
/** Minute of hour (0-59) */
minute: number;
/** Optional label for the alarm */
label?: string;
/** Whether the alarm is enabled */
enabled?: boolean;
}

このページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。

Getting Startedの続きを進める

「Getting Started からの続き」セクション

使用している場合 スタートガイド ダッシュボードと API の運用を計画するには、これを次と連携させます @capgo/capacitor-alarm の使用方法 @capgo/capacitor-alarm でネイティブ機能を使用する場合、 API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー および「API Keys」の実装の詳細については、 デバイス 実装の詳細については Devices を参照してください。