forked from EddyVerbruggen/nativescript-pushy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-view-model.ts
41 lines (35 loc) · 1.22 KB
/
main-view-model.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
import { LocalNotifications } from "nativescript-local-notifications";
import { getDevicePushToken, setNotificationHandler } from "nativescript-pushy";
import { Observable } from "tns-core-modules/data/observable";
export class HelloWorldModel extends Observable {
public message: string;
constructor() {
super();
setNotificationHandler(notification => {
console.log(`Notification received: ${JSON.stringify(notification)}`);
setTimeout(() => {
alert({
title: "Notification received",
message: JSON.stringify(notification),
okButtonText: "OK"
});
}, 500);
});
}
public doScheduleLocalNotification(): void {
LocalNotifications.schedule([{
id: 1,
title: "Local FTW",
body: "I'm a local notification",
at: new Date(new Date().getTime() + (10 * 1000)) // 10 seconds from now
}]).then(() => console.log("Will show a local notification in 10 seconds"));
}
public doGetDevicePushToken(): void {
getDevicePushToken()
.then(token => {
console.log(`getDevicePushToken success, token: ${token}`);
this.set("message", "token: " + token);
})
.catch(err => this.set("message", err));
}
}