Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/components/LocalNotificationTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 }] });
};
Expand Down Expand Up @@ -402,6 +433,9 @@ export default function LocalNotificationTest({ permissions }: Props) {
<IonButton expand="block" onClick={scheduleOnWithoutSeconds}>
Schedule just one (without seconds)
</IonButton>
<IonButton expand="block" onClick={scheduleOnWithStartDate}>
Schedule every minute, starting in 5 minutes
</IonButton>
<IonButton expand="block" onClick={cancelOne}>
Cancel just one
</IonButton>
Expand Down
Loading