Skip to content

Commit

Permalink
feat(local-notifications): Add buttons for scheduling and canceling o…
Browse files Browse the repository at this point in the history
…ne notification (#96)
  • Loading branch information
jcesarmobile authored Feb 10, 2021
1 parent 4d7482b commit 1a730b0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/components/LocalNotificationTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,33 @@ export default function LocalNotificationTest({ permissions }: Props) {
await getPendingNotifications();
};

const scheduleOne = async () => {
const tenSecondsFromNow = new Date(new Date().getTime() + 10000);
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: tenSecondsFromNow },
},
];

const result = await LocalNotifications.schedule({ notifications });
console.log('schedule result:', result);
};

const cancelOne = async () => {
await LocalNotifications.cancel({notifications: [{id: 222}]});
};

const refreshPending = async () => {
await getPendingNotifications();
};
Expand Down Expand Up @@ -179,6 +206,12 @@ export default function LocalNotificationTest({ permissions }: Props) {
<IonButton expand="block" onClick={refreshPending}>
Refresh Pending Notifications
</IonButton>
<IonButton expand="block" onClick={scheduleOne}>
Schedule just one
</IonButton>
<IonButton expand="block" onClick={cancelOne}>
Cancel just one
</IonButton>
</section>
</div>
);
Expand Down

0 comments on commit 1a730b0

Please sign in to comment.