From c5a969498fa0b2376f7c75bb31f2629cb0ebcbe9 Mon Sep 17 00:00:00 2001 From: F0079 Date: Sun, 5 Jul 2026 13:22:25 +0200 Subject: [PATCH] feat(local-notifications): add test case for recurrent notifications with start date --- src/components/LocalNotificationTest.tsx | 38 ++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/components/LocalNotificationTest.tsx b/src/components/LocalNotificationTest.tsx index de77fabd..453ea597 100644 --- a/src/components/LocalNotificationTest.tsx +++ b/src/components/LocalNotificationTest.tsx @@ -3,19 +3,20 @@ import { LocalNotifications, LocalNotificationSchema, PendingResult, + ScheduleOn, } from '@capacitor/local-notifications'; import { IonButton, IonItem, - IonItemSliding, IonItemOption, IonItemOptions, + IonItemSliding, IonLabel, IonList, IonListHeader, } from '@ionic/react'; import cx from 'classnames'; -import React, { useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; interface Props { permissions: PermissionState; @@ -265,6 +266,36 @@ export default function LocalNotificationTest({ permissions }: Props) { getPendingNotifications(); }; + const scheduleOnWithStartDate = async () => { + const startDate = new Date(); + startDate.setMinutes(startDate.getMinutes() + 5); + console.log("start date", startDate.toISOString()); + const notifications: LocalNotificationSchema[] = [ + { + ...{ + id: 222, + title: 'Get 10% off!', + body: 'Swipe now to learn more', + sound: 'beep.aiff', + attachments: [{ id: 'face', url: 'res:///assets/ionitron.png' }], + actionTypeId: 'OPEN_PRODUCT', + extra: { + productId: 'PRODUCT-1', + }, + }, + schedule: { + at: startDate, + on: { second: 60 } + }, + }, + ]; + + const result = await LocalNotifications.schedule({ notifications }); + console.log('schedule result:', result); + + getPendingNotifications(); + }; + const cancelOne = async () => { await LocalNotifications.cancel({ notifications: [{ id: 222 }] }); }; @@ -402,6 +433,9 @@ export default function LocalNotificationTest({ permissions }: Props) { Schedule just one (without seconds) + + Schedule every minute, starting in 5 minutes + Cancel just one