Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Feat/implement a local notification service #235

Merged
merged 9 commits into from
Oct 16, 2023
1 change: 1 addition & 0 deletions example/vue3/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
</manifest>
1 change: 1 addition & 0 deletions example/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@mytiki/tiki-sdk-capacitor": "^0.3.3",
"@mytiki/receipt-capacitor": "file:../../",
"@capacitor/preferences": "^5.0.6",
"@capacitor/local-notifications": "^5.0.6",
MiroBenicio marked this conversation as resolved.
Show resolved Hide resolved
"uuid": "^9.0.0",
"vue": "^3.3.4"
},
Expand Down
33 changes: 33 additions & 0 deletions src/service/notification-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { LocalNotifications } from '@capacitor/local-notifications';

Check failure on line 1 in src/service/notification-service.ts

View workflow job for this annotation

GitHub Actions / Analyze Vue 2

Cannot find module '@capacitor/local-notifications' or its corresponding type declarations.

Check failure on line 1 in src/service/notification-service.ts

View workflow job for this annotation

GitHub Actions / Analyze Vue 3

Cannot find module '@capacitor/local-notifications' or its corresponding type declarations.

export class NotificationService {
/**
* Request permission from the user to show notifications
* It's necessary to use the sendNotification method
*/
authorize = async () => {
await LocalNotifications.requestPermissions()
}

/**
* Send a local notification to the user after 5 seconds
* @param title - the title of the notification
* @param body - the body of the notification
*/
sendNotification = async (title: string, body: string) => {
await LocalNotifications.schedule({
MiroBenicio marked this conversation as resolved.
Show resolved Hide resolved
notifications: [
{
title: title,
body: body,
id: 1,
schedule: { at: new Date(Date.now() + 1000 * 5) },
sound: undefined,
attachments: undefined,
actionTypeId: '',
extra: null,
},
],
})
}
}
Loading