跳过内容

开始

GitHub

您可以使用我们的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-alarm
bunx cap sync
import { CapgoAlarm } from '@capgo/capacitor-alarm';

使用平台时钟应用程序创建本机操作系统闹钟。 在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);

打开平台的本地闹钟列表 UI,如果可用。

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

为闹钟使用在平台上请求相关权限。 在 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');
}

检查当前权限状态以获取本地闹钟访问权限的 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}`);
});

NativeAlarmCreateOptions

标题: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

标题:NativeActionResult

本机操作的结果。

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

返回当前操作系统和功能的信息。

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. 当公共 API 在上游发生变化时,请重新同步。

继续从 Getting Started

标题:继续从 Getting Started

如果您正在使用 Getting Started 来规划仪表板和 API 操作,连接它到 使用 @capgo/capacitor-alarm 为 native 能力在使用 @capgo/capacitor-alarm 中 API Overview 为 API Overview 的实现细节 __CAPGO_KEEP_0__ 为实现细节的 Introduction API 键 用于API 键的实现细节, 设备 用于设备的实现细节,