@capawesome/capacitor-alarm 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -13
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -20,9 +20,14 @@ Capacitor plugin to create system alarms and timers.
|
|
|
20
20
|
|
|
21
21
|
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Use Cases
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
The Alarm plugin is typically used when the user must be reliably interrupted at a specific time, for example:
|
|
26
|
+
|
|
27
|
+
- **Wake-up alarms**: Create alarms that break through Silent Mode and Focus, for example for morning routines in sleep or fitness apps.
|
|
28
|
+
- **Recurring reminders**: Repeat alarms on specific weekdays, such as a medication reminder every Monday and Friday.
|
|
29
|
+
- **Countdown timers**: Start timers in the system clock app on Android, for example for cooking or workout apps.
|
|
30
|
+
- **Alarm management**: List and cancel the alarms created by your app on iOS to build your own alarm overview.
|
|
26
31
|
|
|
27
32
|
## Compatibility
|
|
28
33
|
|
|
@@ -73,18 +78,46 @@ No configuration required for this plugin.
|
|
|
73
78
|
|
|
74
79
|
## Usage
|
|
75
80
|
|
|
81
|
+
The following examples show how to check availability, check and request permissions, create alarms and timers, list and cancel alarms, and open the system clock app.
|
|
82
|
+
|
|
83
|
+
### Check if alarms are available
|
|
84
|
+
|
|
85
|
+
Before creating an alarm, check if alarms are available on the device. On Android, this checks whether an app that can handle alarms is installed. On iOS, this returns `true` if the device runs iOS 26 or later:
|
|
86
|
+
|
|
76
87
|
```typescript
|
|
77
|
-
import { Alarm
|
|
88
|
+
import { Alarm } from '@capawesome/capacitor-alarm';
|
|
78
89
|
|
|
79
|
-
const
|
|
80
|
-
await Alarm.
|
|
90
|
+
const isAvailable = async () => {
|
|
91
|
+
const { available } = await Alarm.isAvailable();
|
|
92
|
+
return available;
|
|
81
93
|
};
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Check and request permissions
|
|
97
|
+
|
|
98
|
+
Check and request the permission to schedule alarms. On Android, both methods always return `granted` since alarms are created via the system clock app:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { Alarm } from '@capawesome/capacitor-alarm';
|
|
82
102
|
|
|
83
103
|
const checkPermissions = async () => {
|
|
84
104
|
const { alarms } = await Alarm.checkPermissions();
|
|
85
105
|
return alarms;
|
|
86
106
|
};
|
|
87
107
|
|
|
108
|
+
const requestPermissions = async () => {
|
|
109
|
+
const { alarms } = await Alarm.requestPermissions();
|
|
110
|
+
return alarms;
|
|
111
|
+
};
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Create an alarm
|
|
115
|
+
|
|
116
|
+
Create a one-time or repeating alarm by providing the hour, the minute, and optionally a label and the weekdays on which the alarm repeats. On Android, the alarm is created in the system clock app and the returned `id` is `null`. On iOS, the alarm is owned by your app and can be listed and canceled later:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { Alarm, Weekday } from '@capawesome/capacitor-alarm';
|
|
120
|
+
|
|
88
121
|
const createAlarm = async () => {
|
|
89
122
|
const { id } = await Alarm.createAlarm({
|
|
90
123
|
hour: 6,
|
|
@@ -94,6 +127,14 @@ const createAlarm = async () => {
|
|
|
94
127
|
});
|
|
95
128
|
return id;
|
|
96
129
|
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Create a timer
|
|
133
|
+
|
|
134
|
+
Create a countdown timer in the system clock app by providing the duration in seconds. Only available on Android:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { Alarm } from '@capawesome/capacitor-alarm';
|
|
97
138
|
|
|
98
139
|
const createTimer = async () => {
|
|
99
140
|
await Alarm.createTimer({
|
|
@@ -101,25 +142,35 @@ const createTimer = async () => {
|
|
|
101
142
|
label: 'Tea',
|
|
102
143
|
});
|
|
103
144
|
};
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### List and cancel alarms
|
|
148
|
+
|
|
149
|
+
Get all alarms that were created by your app and cancel them by their identifier. Only available on iOS:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { Alarm } from '@capawesome/capacitor-alarm';
|
|
104
153
|
|
|
105
154
|
const getAlarms = async () => {
|
|
106
155
|
const { alarms } = await Alarm.getAlarms();
|
|
107
156
|
return alarms;
|
|
108
157
|
};
|
|
109
158
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
return available;
|
|
159
|
+
const cancelAlarm = async (id: string) => {
|
|
160
|
+
await Alarm.cancelAlarm({ id });
|
|
113
161
|
};
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Open the alarms in the system clock app
|
|
165
|
+
|
|
166
|
+
Open the list of alarms in the system clock app, for example so the user can review or edit an alarm. Only available on Android:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { Alarm } from '@capawesome/capacitor-alarm';
|
|
114
170
|
|
|
115
171
|
const openAlarms = async () => {
|
|
116
172
|
await Alarm.openAlarms();
|
|
117
173
|
};
|
|
118
|
-
|
|
119
|
-
const requestPermissions = async () => {
|
|
120
|
-
const { alarms } = await Alarm.requestPermissions();
|
|
121
|
-
return alarms;
|
|
122
|
-
};
|
|
123
174
|
```
|
|
124
175
|
|
|
125
176
|
## API
|
|
@@ -440,6 +491,46 @@ The two platforms have fundamentally different alarm models, which this plugin e
|
|
|
440
491
|
| `openAlarms()` | ✅ | ❌ |
|
|
441
492
|
| `requestPermissions()` | ✅ | ✅ |
|
|
442
493
|
|
|
494
|
+
## FAQ
|
|
495
|
+
|
|
496
|
+
### How is this plugin different from other similar plugins?
|
|
497
|
+
|
|
498
|
+
It creates real system alarms that break through Silent Mode and Focus and keep sounding until dismissed — one of the first plugins to adopt Apple's new AlarmKit on iOS 26 — with repeating weekday alarms, permission handling in a single call, timers via the system clock app on Android, and alarm listing and cancellation on iOS. It exposes each platform's fundamentally different alarm model honestly through a fully typed API and stays actively maintained against the latest Capacitor and OS versions. If a normal reminder is enough, a local notification is the simpler choice; if the user must be reliably interrupted at a set time, this plugin is built for that.
|
|
499
|
+
|
|
500
|
+
### Why does the plugin require iOS 26 or later?
|
|
501
|
+
|
|
502
|
+
The plugin uses Apple's [AlarmKit](https://developer.apple.com/documentation/alarmkit) framework, which was introduced with iOS 26. On older iOS versions, all methods except `isAvailable()` reject as unavailable, so you can use `isAvailable()` to check for support at runtime.
|
|
503
|
+
|
|
504
|
+
### Why can't I list or cancel alarms on Android?
|
|
505
|
+
|
|
506
|
+
On Android, alarms are created in the system clock app via the `AlarmClock` intent API, which is fire-and-forget: once created, the alarm belongs to the clock app and the OS offers no API to list or cancel it. That is why `createAlarm(...)` returns `null` as the alarm identifier on Android and `getAlarms()` and `cancelAlarm(...)` reject as unimplemented. See the [Platform Support](#platform-support) section for details.
|
|
507
|
+
|
|
508
|
+
### What is the difference between an alarm and a local notification?
|
|
509
|
+
|
|
510
|
+
An alarm breaks through Silent Mode and Focus modes and plays a sound until it is dismissed, while a local notification does not. On the other hand, local notifications support custom content and actions. Use an alarm when the user must be interrupted at a specific time, and a local notification for everything else (see [Alarms vs. Local Notifications](#alarms-vs-local-notifications)).
|
|
511
|
+
|
|
512
|
+
### Why is creating timers not supported on iOS?
|
|
513
|
+
|
|
514
|
+
Timers created with AlarmKit require a Live Activity widget extension in the app, which is why `createTimer(...)` is currently not supported on iOS. On Android, timers are created in the system clock app.
|
|
515
|
+
|
|
516
|
+
### Do I need any permissions to create alarms?
|
|
517
|
+
|
|
518
|
+
On Android, the plugin already declares the `com.android.alarm.permission.SET_ALARM` permission in its manifest, which is granted automatically. On iOS, you must add the `NSAlarmKitUsageDescription` key to your `Info.plist` file (see [Installation](#installation)) and request the alarm authorization using `requestPermissions()`.
|
|
519
|
+
|
|
520
|
+
### Can I use this plugin with Ionic, React, Vue or Angular?
|
|
521
|
+
|
|
522
|
+
Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
|
|
523
|
+
|
|
524
|
+
## Related Plugins
|
|
525
|
+
|
|
526
|
+
- [Datetime Picker](https://capawesome.io/docs/sdks/capacitor/datetime-picker/): Let the user pick the alarm time with a native date and time picker.
|
|
527
|
+
- [Silent Mode](https://capawesome.io/docs/sdks/capacitor/silent-mode/): Detect whether the device is in silent mode.
|
|
528
|
+
- [Background Task](https://capawesome.io/docs/sdks/capacitor/background-task/): Run background tasks in your app.
|
|
529
|
+
|
|
530
|
+
## Newsletter
|
|
531
|
+
|
|
532
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
533
|
+
|
|
443
534
|
## Changelog
|
|
444
535
|
|
|
445
536
|
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/alarm/CHANGELOG.md).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-alarm",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Capacitor plugin to create system alarms and timers.",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Capacitor plugin to create system alarms and timers on Android and iOS.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -41,7 +41,13 @@
|
|
|
41
41
|
"alarm",
|
|
42
42
|
"alarmkit",
|
|
43
43
|
"timer",
|
|
44
|
-
"clock"
|
|
44
|
+
"clock",
|
|
45
|
+
"capacitor-plugin",
|
|
46
|
+
"alarm clock",
|
|
47
|
+
"system alarm",
|
|
48
|
+
"countdown timer",
|
|
49
|
+
"wake up alarm",
|
|
50
|
+
"schedule alarm"
|
|
45
51
|
],
|
|
46
52
|
"scripts": {
|
|
47
53
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|