Skip to content

Commit 2e02b05

Browse files
feat(notifications): add push notification functionality
By @sebastianjnuwu
2 parents 67b7dba + e6f9b02 commit 2e02b05

File tree

7 files changed

+43
-3
lines changed

7 files changed

+43
-3
lines changed

.idea/misc.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/app/capacitor.build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ android {
1010
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
1111
dependencies {
1212
implementation project(':capacitor-community-admob')
13+
implementation project(':capacitor-push-notifications')
1314

1415
}
1516

android/capacitor.settings.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/
44

55
include ':capacitor-community-admob'
66
project(':capacitor-community-admob').projectDir = new File('../node_modules/@capacitor-community/admob/android')
7+
8+
include ':capacitor-push-notifications'
9+
project(':capacitor-push-notifications').projectDir = new File('../node_modules/@capacitor/push-notifications/android')

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"dependencies": {
2525
"@capacitor-community/admob": "^6.1.0",
2626
"@capacitor/android": "^6.2.0",
27-
"@capacitor/core": "^6.2.0"
27+
"@capacitor/core": "^6.2.0",
28+
"@capacitor/push-notifications": "^6.0.3"
2829
},
2930
"devDependencies": {
3031
"@babel/core": "^7.26.0",

www/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
1313
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
1414
<script src="https://cdnjs.cloudflare.com/ajax/libs/eruda/3.4.1/eruda.min.js" integrity="sha512-3RVqOZtMevFOLeXCp0/Wl7np/l3J3MMysaFDUhNh+hdKx+Wb0lMXuHwA6CZ/+4DfYZM01Om1as8g+mnTaQH9vA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
15-
<script type="module" src="./res/plugins/AdMob.ts"></script>
15+
<script type="module" src="./res/plugins/admob.ts"></script>
16+
<script type="module" src="./res/plugins/push-notifications.ts"></script>
1617
</head>
1718
<body class="ui-cookie">
1819

File renamed without changes.

www/res/plugins/push-notifications.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { PushNotifications } from "@capacitor/push-notifications";
2+
3+
const register = async () => {
4+
let STATUS = await PushNotifications.checkPermissions();
5+
console.log(STATUS);
6+
7+
if (STATUS.receive === "prompt") {
8+
STATUS = await PushNotifications.requestPermissions();
9+
console.log(STATUS);
10+
}
11+
12+
if (STATUS.receive !== "granted") {
13+
console.log("not permission");
14+
}
15+
16+
await PushNotifications.register();
17+
18+
PushNotifications.addListener("registration", (token) => {
19+
console.log(token);
20+
});
21+
22+
PushNotifications.addListener("registrationError", (error) => {
23+
console.log(error);
24+
});
25+
26+
PushNotifications.addListener("pushNotificationReceived", (notification) => {
27+
console.log(notification);
28+
});
29+
30+
PushNotifications.addListener("pushNotificationActionPerformed", (action) => {
31+
console.log(action);
32+
});
33+
};
34+
35+
register();

0 commit comments

Comments
 (0)