-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.page.ts
61 lines (40 loc) · 1.43 KB
/
home.page.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Component } from '@angular/core';
import { Badge } from '@capawesome/capacitor-badge';
import { NotificationService } from '../notification.service';
import {
ActionPerformed,
PushNotificationSchema,
PushNotifications,
Token,
} from '@capacitor/push-notifications';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
badgeNumber: any;
constructor(private notifService: NotificationService) { }
async setBadge(count: number) {
console.log("Setting badge count to: ", count);
await Badge.set({ count: count });
const result = await Badge.get();
console.log("Get Badge Count: ", JSON.stringify(result));
}
getRandomArbitrary(min: number, max: number) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min)
}
ngOnInit(): void {
this.badgeNumber = this.getRandomArbitrary(10, 99);
this.setBadge(this.badgeNumber)
//badge number on icon will not be updated here.
//this.notifService.registerLocalNotification(); //listener for notifications click
this.setBadge(this.badgeNumber)
setInterval(() => {
this.badgeNumber = this.getRandomArbitrary(10, 99);
this.setBadge(this.badgeNumber)
this.notifService.notifyExchanges(this.badgeNumber);
//badge count on icon will be updated only after above line has been executed.
}, (60 * 1000));
}
}