开始
复制安装提示并获取该插件的完整 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.
您可以使用我们的 AI 助手设置来安装插件。使用以下命令将 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-alarm` plugin in my project.如果您更喜欢手动设置,请按照以下命令安装插件,并遵循以下平台特定的说明:
bun add @capgo/capacitor-alarmbunx cap syncimport { CapgoAlarm } from '@capgo/capacitor-alarm';API概述
标题为“API概述”的部分createAlarm
标题为“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
标题: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检查本地警报访问权限的当前状态 在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
NativeAlarmCreateOptions创建本地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;}NativeActionResult
NativeActionResult本地操作的结果。
export interface NativeActionResult { /** Whether the action was successful */ success: boolean; /** Optional message with additional information */ message?: string;}OSInfo
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
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
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”如果您正在使用 Getting Started 来规划仪表板和API操作,请将其连接到 使用@capgo/capacitor-alarm 为native能力在使用@capgo/capacitor-alarm 中API概述 为API概述 在__CAPGO_KEEP_0__概述中实现详细信息 为《介绍》中实现细节 API Keys 为《API Keys》中实现细节,以及 设备 为《设备》中实现细节。