开始入门
复制一个包含安装步骤和本插件的完整 Markdown 指南的设置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-alarm`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/alarm/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
bun add @capgo/capacitor-alarmbunx cap syncimport { CapgoAlarm } from '@capgo/capacitor-alarm';API 介绍
Section titled “API 介绍”createAlarm
Section titled “createAlarm”使用平台时钟应用创建本机操作系统闹钟。 在 Android 上,这使用闹钟意图;在 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);openAlarms
Section titled “openAlarms”打开本地平台的闹钟列表 UI,如果可用。
import { CapgoAlarm } from '@capgo/capacitor-alarm';
const result = await CapgoAlarm.openAlarms();if (result.success) { console.log('Alarms UI opened');}getOSInfo
标题为“getOSInfo”获取有关操作系统和功能的信息。
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
标题为“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');}checkPermissions
标题为“checkPermissions”检查本地闹钟访问权限的当前状态,无需触发 UI。 在 iOS 上,这将报告 AlarmKit 准备就绪;在 Android 上,它将报告功能详细信息。
import { CapgoAlarm } from '@capgo/capacitor-alarm';
const status = await CapgoAlarm.checkPermissions();console.log('AlarmKit allowed?', status.details?.alarmKit);getAlarms
标题为“getAlarms”获取此应用程序预订的闹钟列表。 在 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}`);});类型参考
标题:类型参考NativeAlarmCreateOptions
标题:本机闹钟创建选项创建本机操作系统闹钟的选项,通过平台时钟应用程序。
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;}NativeActionResult
标题:本机操作结果本机操作的结果。
export interface NativeActionResult { /** Whether the action was successful */ success: boolean; /** Optional message with additional information */ message?: string;}OSInfo
标题:操作系统信息返回当前操作系统和功能的信息。
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;}PermissionResult
标题:权限结果权限请求的结果
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;}AlarmInfo
标题:闹钟信息关于预定闹钟的信息
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重新同步公共API时,重新运行上游的同步。
继续从开始指南
继续从 Getting Started如果您正在使用 Getting Started 以计划仪表板和API操作为目的,连接它 使用@capgo/capacitor-alarm 使用@capgo/capacitor-alarm的本地能力 API概述 API概述的实现细节 介绍 介绍的实现细节 API密钥 API密钥的实现细节 设备 关于设备的实现细节