ガイド
アラームのチュートリアル
capgo/capacitor-alarm を使用する
Capacitor アラーム プラグイン: OS のアラームを管理するためのネイティブ OS のインターフェイス
インストール
bun add @capgo/capacitor-alarm
bunx cap sync
このプラグインが公開するもの
createAlarm- Android の場合は、Alarm Clock インテントを使用して、プラットフォームの時計アプリを使用してネイティブ OS のアラームを作成します。iOS の場合は、AlarmKit を使用します (iOS 16 以降)。openAlarms- プラットフォームのネイティブ アラーム リスト UI を開きます (利用可能な場合)。getOSInfo- OS の情報と機能を取得します。requestPermissions- __CAPGO_KEEP_0__のアラーム使用に必要な権限を要求します。Androidでは、正確なアラームの設定にルーティングする場合があります。
使用例
createAlarm
__CAPGO_KEEP_0__のネイティブOSアラームを作成します。__CAPGO_KEEP_0__の時計アプリを使用します。AndroidではAlarm ClockのIntentを使用し、iOSではAlarmKitを使用します (iOS 16以上)。
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);
openAlarms
__CAPGO_KEEP_0__のネイティブアラームリストUIを開きます (利用可能な場合)。
import { CapgoAlarm } from '@capgo/capacitor-alarm';
const result = await CapgoAlarm.openAlarms();
if (result.success) {
console.log('Alarms UI opened');
}
getOSInfo
__CAPGO_KEEP_0__と機能についての情報を取得します。
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);
}
requestPermissions
アラーム使用に必要な権限を要求します。Androidでは、正確なアラームの設定にルーティングする場合があります。
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');
}
完全なリファレンス
- GitHub: https://github.com/Cap-go/capacitor-alarm/
- ドキュメント: /docs/plugins/alarm/