This repository was archived by the owner on Feb 7, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathpush-plugin.android.ts
More file actions
77 lines (68 loc) · 2.83 KB
/
Copy pathpush-plugin.android.ts
File metadata and controls
77 lines (68 loc) · 2.83 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as app from 'tns-core-modules/application';
declare var com: any;
export declare interface FcmNotificaion {
getBody(): string;
getBodyLocalizationArgs(): string[];
getBodyLocalizationKey(): string;
getClickAction(): string;
getColor(): string;
getIcon(): string;
getSound(): string;
getTag(): string;
getTitle(): string;
getTitleLocalizationArgs(): string[];
getTitleLocalizationKey(): string;
}
(() => {
let registerLifecycleEvents = () => {
com.telerik.pushplugin.PushLifecycleCallbacks.registerCallbacks(app.android.nativeApp);
};
// Hook on the application events
if (app.android.nativeApp) {
registerLifecycleEvents();
} else {
app.on(app.launchEvent, registerLifecycleEvents);
}
})();
export function register(options: { senderID: string, notificationCallbackAndroid?: (stringifiedData: String, fcmNotification: any) => void }, successCallback: (fcmRegistrationToken: string) => void, errorCallback: (errorMessage: string) => void) {
com.telerik.pushplugin.PushPlugin.register(app.android.context, options.senderID,
new com.telerik.pushplugin.PushPluginListener(
{
success: (fcmRegistrationToken: string) => {
if (options && typeof options.notificationCallbackAndroid === 'function') {
onMessageReceived(options.notificationCallbackAndroid);
}
successCallback(fcmRegistrationToken);
},
error: errorCallback
})
);
}
export function unregister(onSuccessCallback: (successMessage: string) => void, onErrorCallback: (errorMessage: string) => void, options: { senderID: string }) {
com.telerik.pushplugin.PushPlugin.unregister(app.android.context, options.senderID, new com.telerik.pushplugin.PushPluginListener(
{
success: onSuccessCallback,
error: onErrorCallback
}
));
}
export function onMessageReceived(onSuccessCallback: (message: string, stringifiedData: string, fcmNotification: FcmNotificaion) => void) {
com.telerik.pushplugin.PushPlugin.setOnMessageReceivedCallback(
new com.telerik.pushplugin.PushPluginListener(
{
success: onSuccessCallback
})
);
}
export function onTokenRefresh(onSuccessCallback: () => void) {
com.telerik.pushplugin.PushPlugin.setOnTokenRefreshCallback(
new com.telerik.pushplugin.PushPluginListener(
{
success: onSuccessCallback
})
);
}
export function areNotificationsEnabled(onSuccessCallback: (areEnabled: boolean) => void) {
const bool = com.telerik.pushplugin.PushPlugin.areNotificationsEnabled();
onSuccessCallback(bool);
}