@ammarahmed/notifee-react-native 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +3 -0
- package/LICENSE +44 -0
- package/README.md +131 -0
- package/RNNotifee.podspec +39 -0
- package/RNNotifeeCore.podspec +33 -0
- package/android/build.gradle +116 -0
- package/android/gradle.properties +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar +0 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.md5 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha1 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha256 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha512 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom +9 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.md5 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha1 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha256 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha512 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml +13 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.md5 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +1 -0
- package/android/lint.xml +5 -0
- package/android/proguard-rules.pro +74 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +349 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java +118 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeInitProvider.java +55 -0
- package/android/src/main/java/io/invertase/notifee/NotifeePackage.java +30 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java +244 -0
- package/app.plugin.js +1 -0
- package/dist/NotifeeApiModule.d.ts +53 -0
- package/dist/NotifeeApiModule.js +607 -0
- package/dist/NotifeeApiModule.js.map +1 -0
- package/dist/NotifeeJSEventEmitter.d.ts +3 -0
- package/dist/NotifeeJSEventEmitter.js +14 -0
- package/dist/NotifeeJSEventEmitter.js.map +1 -0
- package/dist/NotifeeNativeError.d.ts +15 -0
- package/dist/NotifeeNativeError.js +61 -0
- package/dist/NotifeeNativeError.js.map +1 -0
- package/dist/NotifeeNativeModule.d.ts +14 -0
- package/dist/NotifeeNativeModule.js +43 -0
- package/dist/NotifeeNativeModule.js.map +1 -0
- package/dist/NotifeeNativeModule.web.d.ts +12 -0
- package/dist/NotifeeNativeModule.web.js +19 -0
- package/dist/NotifeeNativeModule.web.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/types/Library.d.ts +21 -0
- package/dist/types/Library.js +6 -0
- package/dist/types/Library.js.map +1 -0
- package/dist/types/Module.d.ts +572 -0
- package/dist/types/Module.js +6 -0
- package/dist/types/Module.js.map +1 -0
- package/dist/types/Notification.d.ts +450 -0
- package/dist/types/Notification.js +105 -0
- package/dist/types/Notification.js.map +1 -0
- package/dist/types/NotificationAndroid.d.ts +1276 -0
- package/dist/types/NotificationAndroid.js +380 -0
- package/dist/types/NotificationAndroid.js.map +1 -0
- package/dist/types/NotificationIOS.d.ts +537 -0
- package/dist/types/NotificationIOS.js +92 -0
- package/dist/types/NotificationIOS.js.map +1 -0
- package/dist/types/NotificationWeb.d.ts +5 -0
- package/dist/types/NotificationWeb.js +3 -0
- package/dist/types/NotificationWeb.js.map +1 -0
- package/dist/types/PowerManagerInfo.d.ts +36 -0
- package/dist/types/PowerManagerInfo.js +6 -0
- package/dist/types/PowerManagerInfo.js.map +1 -0
- package/dist/types/Trigger.d.ts +108 -0
- package/dist/types/Trigger.js +39 -0
- package/dist/types/Trigger.js.map +1 -0
- package/dist/utils/id.d.ts +1 -0
- package/dist/utils/id.js +16 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +16 -0
- package/dist/utils/index.js +52 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/validate.d.ts +15 -0
- package/dist/utils/validate.js +93 -0
- package/dist/utils/validate.js.map +1 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.d.ts +2 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js +39 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js.map +1 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.d.ts +2 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js +27 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js.map +1 -0
- package/dist/validators/validate.d.ts +25 -0
- package/dist/validators/validate.js +75 -0
- package/dist/validators/validate.js.map +1 -0
- package/dist/validators/validateAndroidAction.d.ts +2 -0
- package/dist/validators/validateAndroidAction.js +52 -0
- package/dist/validators/validateAndroidAction.js.map +1 -0
- package/dist/validators/validateAndroidChannel.d.ts +2 -0
- package/dist/validators/validateAndroidChannel.js +155 -0
- package/dist/validators/validateAndroidChannel.js.map +1 -0
- package/dist/validators/validateAndroidChannelGroup.d.ts +2 -0
- package/dist/validators/validateAndroidChannelGroup.js +42 -0
- package/dist/validators/validateAndroidChannelGroup.js.map +1 -0
- package/dist/validators/validateAndroidFullScreenAction.d.ts +2 -0
- package/dist/validators/validateAndroidFullScreenAction.js +50 -0
- package/dist/validators/validateAndroidFullScreenAction.js.map +1 -0
- package/dist/validators/validateAndroidInput.d.ts +2 -0
- package/dist/validators/validateAndroidInput.js +54 -0
- package/dist/validators/validateAndroidInput.js.map +1 -0
- package/dist/validators/validateAndroidNotification.d.ts +2 -0
- package/dist/validators/validateAndroidNotification.js +529 -0
- package/dist/validators/validateAndroidNotification.js.map +1 -0
- package/dist/validators/validateAndroidPressAction.d.ts +2 -0
- package/dist/validators/validateAndroidPressAction.js +50 -0
- package/dist/validators/validateAndroidPressAction.js.map +1 -0
- package/dist/validators/validateAndroidStyle.d.ts +22 -0
- package/dist/validators/validateAndroidStyle.js +231 -0
- package/dist/validators/validateAndroidStyle.js.map +1 -0
- package/dist/validators/validateIOSAttachment.d.ts +6 -0
- package/dist/validators/validateIOSAttachment.js +102 -0
- package/dist/validators/validateIOSAttachment.js.map +1 -0
- package/dist/validators/validateIOSCategory.d.ts +2 -0
- package/dist/validators/validateIOSCategory.js +124 -0
- package/dist/validators/validateIOSCategory.js.map +1 -0
- package/dist/validators/validateIOSCategoryAction.d.ts +2 -0
- package/dist/validators/validateIOSCategoryAction.js +59 -0
- package/dist/validators/validateIOSCategoryAction.js.map +1 -0
- package/dist/validators/validateIOSInput.d.ts +2 -0
- package/dist/validators/validateIOSInput.js +32 -0
- package/dist/validators/validateIOSInput.js.map +1 -0
- package/dist/validators/validateIOSNotification.d.ts +2 -0
- package/dist/validators/validateIOSNotification.js +211 -0
- package/dist/validators/validateIOSNotification.js.map +1 -0
- package/dist/validators/validateIOSPermissions.d.ts +2 -0
- package/dist/validators/validateIOSPermissions.js +62 -0
- package/dist/validators/validateIOSPermissions.js.map +1 -0
- package/dist/validators/validateNotification.d.ts +11 -0
- package/dist/validators/validateNotification.js +129 -0
- package/dist/validators/validateNotification.js.map +1 -0
- package/dist/validators/validateTrigger.d.ts +2 -0
- package/dist/validators/validateTrigger.js +104 -0
- package/dist/validators/validateTrigger.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js.map +1 -0
- package/ios/NotifeeCore/Info.plist +22 -0
- package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.h +28 -0
- package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +72 -0
- package/ios/NotifeeCore/NotifeeCore+NSURLSession.h +25 -0
- package/ios/NotifeeCore/NotifeeCore+NSURLSession.m +55 -0
- package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.h +37 -0
- package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +242 -0
- package/ios/NotifeeCore/NotifeeCore.h +118 -0
- package/ios/NotifeeCore/NotifeeCore.m +784 -0
- package/ios/NotifeeCore/NotifeeCoreDelegateHolder.h +34 -0
- package/ios/NotifeeCore/NotifeeCoreDelegateHolder.m +70 -0
- package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.h +39 -0
- package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.m +68 -0
- package/ios/NotifeeCore/NotifeeCoreExtensionHelper.h +38 -0
- package/ios/NotifeeCore/NotifeeCoreExtensionHelper.m +224 -0
- package/ios/NotifeeCore/NotifeeCoreUtil.h +82 -0
- package/ios/NotifeeCore/NotifeeCoreUtil.m +793 -0
- package/ios/RNNotifee/NotifeeApiModule.h +25 -0
- package/ios/RNNotifee/NotifeeApiModule.m +371 -0
- package/ios/RNNotifee/NotifeeExtensionHelper.h +37 -0
- package/ios/RNNotifee/NotifeeExtensionHelper.m +37 -0
- package/ios/RNNotifee.xcodeproj/project.pbxproj +318 -0
- package/jest-mock.js +158 -0
- package/package.json +59 -0
- package/plugin/build/index.d.ts +3 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/withNotifeeProjectGradlePlugin.d.ts +5 -0
- package/plugin/build/withNotifeeProjectGradlePlugin.js +24 -0
- package/plugin/build/withNotifeeProjectGradlePlugin.js.map +1 -0
- package/plugin/src/index.ts +9 -0
- package/plugin/src/withNotifeeProjectGradlePlugin.ts +27 -0
- package/plugin/tsconfig.json +9 -0
- package/react-native.config.js +11 -0
- package/refresh-example.sh +71 -0
- package/src/NotifeeApiModule.ts +825 -0
- package/src/NotifeeJSEventEmitter.ts +11 -0
- package/src/NotifeeNativeError.ts +70 -0
- package/src/NotifeeNativeModule.ts +55 -0
- package/src/NotifeeNativeModule.web.ts +25 -0
- package/src/index.ts +33 -0
- package/src/types/Library.ts +28 -0
- package/src/types/Module.ts +625 -0
- package/src/types/Notification.ts +505 -0
- package/src/types/NotificationAndroid.ts +1443 -0
- package/src/types/NotificationIOS.ts +681 -0
- package/src/types/NotificationWeb.ts +5 -0
- package/src/types/PowerManagerInfo.ts +43 -0
- package/src/types/Trigger.ts +118 -0
- package/src/utils/id.ts +13 -0
- package/src/utils/index.ts +47 -0
- package/src/utils/validate.ts +92 -0
- package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfo.ts +45 -0
- package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.ts +33 -0
- package/src/validators/validate.ts +85 -0
- package/src/validators/validateAndroidAction.ts +54 -0
- package/src/validators/validateAndroidChannel.ts +188 -0
- package/src/validators/validateAndroidChannelGroup.ts +49 -0
- package/src/validators/validateAndroidFullScreenAction.ts +65 -0
- package/src/validators/validateAndroidInput.ts +67 -0
- package/src/validators/validateAndroidNotification.ts +704 -0
- package/src/validators/validateAndroidPressAction.ts +65 -0
- package/src/validators/validateAndroidStyle.ts +315 -0
- package/src/validators/validateIOSAttachment.ts +136 -0
- package/src/validators/validateIOSCategory.ts +150 -0
- package/src/validators/validateIOSCategoryAction.ts +65 -0
- package/src/validators/validateIOSInput.ts +38 -0
- package/src/validators/validateIOSNotification.ts +296 -0
- package/src/validators/validateIOSPermissions.ts +78 -0
- package/src/validators/validateNotification.ts +156 -0
- package/src/validators/validateTrigger.ts +134 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,825 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AppRegistry, Platform } from 'react-native';
|
|
6
|
+
import { Module } from './types/Module';
|
|
7
|
+
import {
|
|
8
|
+
AndroidChannel,
|
|
9
|
+
AndroidChannelGroup,
|
|
10
|
+
AndroidNotificationSetting,
|
|
11
|
+
NativeAndroidChannel,
|
|
12
|
+
NativeAndroidChannelGroup,
|
|
13
|
+
} from './types/NotificationAndroid';
|
|
14
|
+
import {
|
|
15
|
+
AuthorizationStatus,
|
|
16
|
+
InitialNotification,
|
|
17
|
+
Notification,
|
|
18
|
+
Event,
|
|
19
|
+
TriggerNotification,
|
|
20
|
+
DisplayedNotification,
|
|
21
|
+
NotificationSettings,
|
|
22
|
+
} from './types/Notification';
|
|
23
|
+
import { PowerManagerInfo } from './types/PowerManagerInfo';
|
|
24
|
+
import { Trigger } from './types/Trigger';
|
|
25
|
+
import NotifeeNativeModule, { NativeModuleConfig } from './NotifeeNativeModule';
|
|
26
|
+
import {
|
|
27
|
+
isAndroid,
|
|
28
|
+
isArray,
|
|
29
|
+
isFunction,
|
|
30
|
+
isIOS,
|
|
31
|
+
isNumber,
|
|
32
|
+
isString,
|
|
33
|
+
isUndefined,
|
|
34
|
+
isWeb,
|
|
35
|
+
kReactNativeNotifeeForegroundServiceHeadlessTask,
|
|
36
|
+
kReactNativeNotifeeNotificationBackgroundEvent,
|
|
37
|
+
kReactNativeNotifeeNotificationEvent,
|
|
38
|
+
NotificationType,
|
|
39
|
+
} from './utils';
|
|
40
|
+
import validateNotification from './validators/validateNotification';
|
|
41
|
+
import validateTrigger from './validators/validateTrigger';
|
|
42
|
+
import validateAndroidChannel from './validators/validateAndroidChannel';
|
|
43
|
+
import validateAndroidChannelGroup from './validators/validateAndroidChannelGroup';
|
|
44
|
+
import { IOSNotificationCategory, IOSNotificationPermissions } from './types/NotificationIOS';
|
|
45
|
+
import validateIOSCategory from './validators/validateIOSCategory';
|
|
46
|
+
import validateIOSPermissions from './validators/validateIOSPermissions';
|
|
47
|
+
|
|
48
|
+
let backgroundEventHandler: (event: Event) => Promise<void>;
|
|
49
|
+
|
|
50
|
+
let registeredForegroundServiceTask: (notification: Notification) => Promise<void>;
|
|
51
|
+
|
|
52
|
+
if (isAndroid) {
|
|
53
|
+
// Register foreground service
|
|
54
|
+
AppRegistry.registerHeadlessTask(kReactNativeNotifeeForegroundServiceHeadlessTask, () => {
|
|
55
|
+
if (!registeredForegroundServiceTask) {
|
|
56
|
+
console.warn(
|
|
57
|
+
'[notifee] no registered foreground service has been set for displaying a foreground notification.',
|
|
58
|
+
);
|
|
59
|
+
return (): Promise<void> => Promise.resolve();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return ({ notification }): Promise<void> => registeredForegroundServiceTask(notification);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default class NotifeeApiModule extends NotifeeNativeModule implements Module {
|
|
67
|
+
constructor(config: NativeModuleConfig) {
|
|
68
|
+
super(config);
|
|
69
|
+
if (isAndroid) {
|
|
70
|
+
// Register background handler
|
|
71
|
+
AppRegistry.registerHeadlessTask(kReactNativeNotifeeNotificationEvent, () => {
|
|
72
|
+
return (event: Event): Promise<void> => {
|
|
73
|
+
if (!backgroundEventHandler) {
|
|
74
|
+
console.warn(
|
|
75
|
+
'[notifee] no background event handler has been set. Set a handler via the "onBackgroundEvent" method.',
|
|
76
|
+
);
|
|
77
|
+
return Promise.resolve();
|
|
78
|
+
}
|
|
79
|
+
return backgroundEventHandler(event);
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
} else if (isIOS) {
|
|
83
|
+
this.emitter.addListener(
|
|
84
|
+
kReactNativeNotifeeNotificationBackgroundEvent,
|
|
85
|
+
(event: Event): Promise<void> => {
|
|
86
|
+
if (!backgroundEventHandler) {
|
|
87
|
+
console.warn(
|
|
88
|
+
'[notifee] no background event handler has been set. Set a handler via the "onBackgroundEvent" method.',
|
|
89
|
+
);
|
|
90
|
+
return Promise.resolve();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return backgroundEventHandler(event);
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public getTriggerNotificationIds = (): Promise<string[]> => {
|
|
100
|
+
if (isAndroid || isIOS) {
|
|
101
|
+
return this.native.getTriggerNotificationIds();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return Promise.resolve([]);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
public getTriggerNotifications = (): Promise<TriggerNotification[]> => {
|
|
108
|
+
if (isAndroid || isIOS) {
|
|
109
|
+
return this.native.getTriggerNotifications();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return Promise.resolve([]);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
public getDisplayedNotifications = (): Promise<DisplayedNotification[]> => {
|
|
116
|
+
if (isAndroid || isIOS) {
|
|
117
|
+
return this.native.getDisplayedNotifications();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return Promise.resolve([]);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
public isChannelBlocked = (channelId: string): Promise<boolean> => {
|
|
124
|
+
if (!isString(channelId)) {
|
|
125
|
+
throw new Error("notifee.isChannelBlocked(*) 'channelId' expected a string value.");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (isWeb || isIOS || this.native.ANDROID_API_LEVEL < 26) {
|
|
129
|
+
return Promise.resolve(false);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return this.native.isChannelBlocked(channelId);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
public isChannelCreated = (channelId: string): Promise<boolean> => {
|
|
136
|
+
if (!isString(channelId)) {
|
|
137
|
+
channelId;
|
|
138
|
+
throw new Error("notifee.isChannelCreated(*) 'channelId' expected a string value.");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (isWeb || isIOS || this.native.ANDROID_API_LEVEL < 26) {
|
|
142
|
+
return Promise.resolve(true);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return this.native.isChannelCreated(channelId);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
public cancelAllNotifications = (notificationIds?: string[], tag?: string): Promise<void> => {
|
|
149
|
+
if (isAndroid || isIOS) {
|
|
150
|
+
if (notificationIds) {
|
|
151
|
+
if (isAndroid) {
|
|
152
|
+
return this.native.cancelAllNotificationsWithIds(
|
|
153
|
+
notificationIds,
|
|
154
|
+
NotificationType.ALL,
|
|
155
|
+
tag,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
return this.native.cancelAllNotificationsWithIds(notificationIds);
|
|
159
|
+
}
|
|
160
|
+
return this.native.cancelAllNotifications();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return Promise.resolve();
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
public cancelDisplayedNotifications = (
|
|
167
|
+
notificationIds?: string[],
|
|
168
|
+
tag?: string,
|
|
169
|
+
): Promise<void> => {
|
|
170
|
+
if (isAndroid || isIOS) {
|
|
171
|
+
if (notificationIds) {
|
|
172
|
+
if (isAndroid) {
|
|
173
|
+
return this.native.cancelAllNotificationsWithIds(
|
|
174
|
+
notificationIds,
|
|
175
|
+
NotificationType.DISPLAYED,
|
|
176
|
+
tag,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return this.native.cancelDisplayedNotificationsWithIds(notificationIds);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return this.native.cancelDisplayedNotifications();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return Promise.resolve();
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
public cancelTriggerNotifications = (notificationIds?: string[]): Promise<void> => {
|
|
190
|
+
if (isAndroid || isIOS) {
|
|
191
|
+
if (notificationIds) {
|
|
192
|
+
if (isAndroid) {
|
|
193
|
+
return this.native.cancelAllNotificationsWithIds(
|
|
194
|
+
notificationIds,
|
|
195
|
+
NotificationType.TRIGGER,
|
|
196
|
+
null,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
return this.native.cancelTriggerNotificationsWithIds(notificationIds);
|
|
200
|
+
}
|
|
201
|
+
return this.native.cancelTriggerNotifications();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return Promise.resolve();
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
public cancelNotification = (notificationId: string, tag?: string): Promise<void> => {
|
|
208
|
+
if (!isString(notificationId)) {
|
|
209
|
+
throw new Error("notifee.cancelNotification(*) 'notificationId' expected a string value.");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (isAndroid) {
|
|
213
|
+
return this.native.cancelAllNotificationsWithIds([notificationId], NotificationType.ALL, tag);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (isIOS) {
|
|
217
|
+
return this.native.cancelNotification(notificationId);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return Promise.resolve();
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
public cancelDisplayedNotification = (notificationId: string, tag?: string): Promise<void> => {
|
|
224
|
+
if (!isString(notificationId)) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
"notifee.cancelDisplayedNotification(*) 'notificationId' expected a string value.",
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (isAndroid) {
|
|
231
|
+
return this.native.cancelAllNotificationsWithIds(
|
|
232
|
+
[notificationId],
|
|
233
|
+
NotificationType.DISPLAYED,
|
|
234
|
+
tag,
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (isIOS) {
|
|
239
|
+
return this.native.cancelDisplayedNotification(notificationId);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return Promise.resolve();
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
public cancelTriggerNotification = (notificationId: string): Promise<void> => {
|
|
246
|
+
if (!isString(notificationId)) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
"notifee.cancelTriggerNotification(*) 'notificationId' expected a string value.",
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (isAndroid) {
|
|
253
|
+
return this.native.cancelAllNotificationsWithIds(
|
|
254
|
+
[notificationId],
|
|
255
|
+
NotificationType.TRIGGER,
|
|
256
|
+
null,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (isIOS) {
|
|
261
|
+
return this.native.cancelTriggerNotification(notificationId);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return Promise.resolve();
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
public createChannel = (channel: AndroidChannel): Promise<string> => {
|
|
268
|
+
let options: AndroidChannel;
|
|
269
|
+
try {
|
|
270
|
+
options = validateAndroidChannel(channel);
|
|
271
|
+
} catch (e: any) {
|
|
272
|
+
throw new Error(`notifee.createChannel(*) ${e.message}`);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (isAndroid) {
|
|
276
|
+
if (this.native.ANDROID_API_LEVEL < 26) {
|
|
277
|
+
return Promise.resolve(options.id);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return this.native.createChannel(options).then(() => {
|
|
281
|
+
return options.id;
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return Promise.resolve('');
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
public createChannels = (channels: AndroidChannel[]): Promise<void> => {
|
|
289
|
+
if (!isArray(channels)) {
|
|
290
|
+
throw new Error("notifee.createChannels(*) 'channels' expected an array of AndroidChannel.");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const options: AndroidChannel[] = [];
|
|
294
|
+
try {
|
|
295
|
+
for (let i = 0; i < channels.length; i++) {
|
|
296
|
+
options[i] = validateAndroidChannel(channels[i]);
|
|
297
|
+
}
|
|
298
|
+
} catch (e: any) {
|
|
299
|
+
throw new Error(`notifee.createChannels(*) 'channels' a channel is invalid: ${e.message}`);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
|
|
303
|
+
return this.native.createChannels(options);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return Promise.resolve();
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
public createChannelGroup = (channelGroup: AndroidChannelGroup): Promise<string> => {
|
|
310
|
+
let options: AndroidChannelGroup;
|
|
311
|
+
try {
|
|
312
|
+
options = validateAndroidChannelGroup(channelGroup);
|
|
313
|
+
} catch (e: any) {
|
|
314
|
+
throw new Error(`notifee.createChannelGroup(*) ${e.message}`);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (isAndroid) {
|
|
318
|
+
if (this.native.ANDROID_API_LEVEL < 26) {
|
|
319
|
+
return Promise.resolve(options.id);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return this.native.createChannelGroup(options).then(() => {
|
|
323
|
+
return options.id;
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return Promise.resolve('');
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
public createChannelGroups = (channelGroups: AndroidChannelGroup[]): Promise<void> => {
|
|
331
|
+
if (!isArray(channelGroups)) {
|
|
332
|
+
throw new Error(
|
|
333
|
+
"notifee.createChannelGroups(*) 'channelGroups' expected an array of AndroidChannelGroup.",
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const options = [];
|
|
338
|
+
try {
|
|
339
|
+
for (let i = 0; i < channelGroups.length; i++) {
|
|
340
|
+
options[i] = validateAndroidChannelGroup(channelGroups[i]);
|
|
341
|
+
}
|
|
342
|
+
} catch (e: any) {
|
|
343
|
+
throw new Error(
|
|
344
|
+
`notifee.createChannelGroups(*) 'channelGroups' a channel group is invalid: ${e.message}`,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
|
|
349
|
+
return this.native.createChannelGroups(options);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return Promise.resolve();
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
public deleteChannel = (channelId: string): Promise<void> => {
|
|
356
|
+
if (!isString(channelId)) {
|
|
357
|
+
throw new Error("notifee.deleteChannel(*) 'channelId' expected a string value.");
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
|
|
361
|
+
return this.native.deleteChannel(channelId);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return Promise.resolve();
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
public deleteChannelGroup = (channelGroupId: string): Promise<void> => {
|
|
368
|
+
if (!isString(channelGroupId)) {
|
|
369
|
+
throw new Error("notifee.deleteChannelGroup(*) 'channelGroupId' expected a string value.");
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
|
|
373
|
+
return this.native.deleteChannelGroup(channelGroupId);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return Promise.resolve();
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
public displayNotification = (notification: Notification): Promise<string> => {
|
|
380
|
+
let options: Notification;
|
|
381
|
+
try {
|
|
382
|
+
options = validateNotification(notification);
|
|
383
|
+
} catch (e: any) {
|
|
384
|
+
throw new Error(`notifee.displayNotification(*) ${e.message}`);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (isIOS || isAndroid) {
|
|
388
|
+
return this.native.displayNotification(options).then((): string => {
|
|
389
|
+
return options.id as string;
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return Promise.resolve('');
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
public openAlarmPermissionSettings = (): Promise<void> => {
|
|
397
|
+
if (isAndroid) {
|
|
398
|
+
return this.native.openAlarmPermissionSettings();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return Promise.resolve();
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
public createTriggerNotification = (
|
|
405
|
+
notification: Notification,
|
|
406
|
+
trigger: Trigger,
|
|
407
|
+
): Promise<string> => {
|
|
408
|
+
let options: Notification;
|
|
409
|
+
let triggerOptions: Trigger;
|
|
410
|
+
|
|
411
|
+
try {
|
|
412
|
+
options = validateNotification(notification);
|
|
413
|
+
} catch (e: any) {
|
|
414
|
+
throw new Error(`notifee.createTriggerNotification(*) ${e.message}`);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
try {
|
|
418
|
+
triggerOptions = validateTrigger(trigger);
|
|
419
|
+
} catch (e: any) {
|
|
420
|
+
throw new Error(`notifee.createTriggerNotification(*) ${e.message}`);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (isIOS || isAndroid) {
|
|
424
|
+
return this.native.createTriggerNotification(options, triggerOptions).then((): string => {
|
|
425
|
+
return options.id as string;
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return Promise.resolve('');
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
public getChannel = (channelId: string): Promise<NativeAndroidChannel | null> => {
|
|
433
|
+
if (!isString(channelId)) {
|
|
434
|
+
throw new Error("notifee.getChannel(*) 'channelId' expected a string value.");
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
|
|
438
|
+
return this.native.getChannel(channelId);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return Promise.resolve(null);
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
public getChannels = (): Promise<NativeAndroidChannel[]> => {
|
|
445
|
+
if (isAndroid && this.native.ANDROID_API_LEVEL >= 26) {
|
|
446
|
+
return this.native.getChannels();
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return Promise.resolve([]);
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
public getChannelGroup = (channelGroupId: string): Promise<NativeAndroidChannelGroup | null> => {
|
|
453
|
+
if (!isString(channelGroupId)) {
|
|
454
|
+
throw new Error("notifee.getChannelGroup(*) 'channelGroupId' expected a string value.");
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (isAndroid || this.native.ANDROID_API_LEVEL >= 26) {
|
|
458
|
+
return this.native.getChannelGroup(channelGroupId);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return Promise.resolve(null);
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
public getChannelGroups = (): Promise<NativeAndroidChannelGroup[]> => {
|
|
465
|
+
if (isAndroid || this.native.ANDROID_API_LEVEL >= 26) {
|
|
466
|
+
return this.native.getChannelGroups();
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return Promise.resolve([]);
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
public getInitialNotification = (): Promise<InitialNotification | null> => {
|
|
473
|
+
if (isIOS || isAndroid) {
|
|
474
|
+
return this.native.getInitialNotification();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return Promise.resolve(null);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
public onBackgroundEvent = (observer: (event: Event) => Promise<void>): void => {
|
|
481
|
+
if (!isFunction(observer)) {
|
|
482
|
+
throw new Error("notifee.onBackgroundEvent(*) 'observer' expected a function.");
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
backgroundEventHandler = observer;
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
public onForegroundEvent = (observer: (event: Event) => void): (() => void) => {
|
|
489
|
+
if (!isFunction(observer)) {
|
|
490
|
+
throw new Error("notifee.onForegroundEvent(*) 'observer' expected a function.");
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const subscriber = this.emitter.addListener(
|
|
494
|
+
kReactNativeNotifeeNotificationEvent,
|
|
495
|
+
({ type, detail }) => {
|
|
496
|
+
observer({ type, detail });
|
|
497
|
+
},
|
|
498
|
+
);
|
|
499
|
+
|
|
500
|
+
return (): void => {
|
|
501
|
+
subscriber.remove();
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
public openNotificationSettings = (channelId?: string): Promise<void> => {
|
|
506
|
+
if (!isUndefined(channelId) && !isString(channelId)) {
|
|
507
|
+
throw new Error("notifee.openNotificationSettings(*) 'channelId' expected a string value.");
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (isAndroid) {
|
|
511
|
+
return this.native.openNotificationSettings(channelId || null);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
return Promise.resolve();
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
public requestPermission = (
|
|
518
|
+
permissions: IOSNotificationPermissions = {},
|
|
519
|
+
): Promise<NotificationSettings> => {
|
|
520
|
+
if (isAndroid) {
|
|
521
|
+
return this.native
|
|
522
|
+
.requestPermission()
|
|
523
|
+
.then(
|
|
524
|
+
({
|
|
525
|
+
authorizationStatus,
|
|
526
|
+
android,
|
|
527
|
+
}: Pick<NotificationSettings, 'authorizationStatus' | 'android'>) => {
|
|
528
|
+
return {
|
|
529
|
+
authorizationStatus,
|
|
530
|
+
android,
|
|
531
|
+
ios: {
|
|
532
|
+
alert: 1,
|
|
533
|
+
badge: 1,
|
|
534
|
+
criticalAlert: 1,
|
|
535
|
+
showPreviews: 1,
|
|
536
|
+
sound: 1,
|
|
537
|
+
carPlay: 1,
|
|
538
|
+
lockScreen: 1,
|
|
539
|
+
announcement: 1,
|
|
540
|
+
notificationCenter: 1,
|
|
541
|
+
inAppNotificationSettings: 1,
|
|
542
|
+
authorizationStatus,
|
|
543
|
+
},
|
|
544
|
+
web: {},
|
|
545
|
+
};
|
|
546
|
+
},
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (isIOS) {
|
|
551
|
+
let options: IOSNotificationPermissions;
|
|
552
|
+
try {
|
|
553
|
+
options = validateIOSPermissions(permissions);
|
|
554
|
+
} catch (e: any) {
|
|
555
|
+
throw new Error(`notifee.requestPermission(*) ${e.message}`);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return this.native
|
|
559
|
+
.requestPermission(options)
|
|
560
|
+
.then(
|
|
561
|
+
({
|
|
562
|
+
authorizationStatus,
|
|
563
|
+
ios,
|
|
564
|
+
}: Pick<NotificationSettings, 'authorizationStatus' | 'ios'>) => {
|
|
565
|
+
return {
|
|
566
|
+
authorizationStatus,
|
|
567
|
+
ios,
|
|
568
|
+
android: {
|
|
569
|
+
alarm: AndroidNotificationSetting.ENABLED,
|
|
570
|
+
},
|
|
571
|
+
web: {},
|
|
572
|
+
};
|
|
573
|
+
},
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// assume web
|
|
578
|
+
return Promise.resolve({
|
|
579
|
+
authorizationStatus: AuthorizationStatus.NOT_DETERMINED,
|
|
580
|
+
android: {
|
|
581
|
+
alarm: AndroidNotificationSetting.ENABLED,
|
|
582
|
+
},
|
|
583
|
+
ios: {
|
|
584
|
+
alert: 1,
|
|
585
|
+
badge: 1,
|
|
586
|
+
criticalAlert: 1,
|
|
587
|
+
showPreviews: 1,
|
|
588
|
+
sound: 1,
|
|
589
|
+
carPlay: 1,
|
|
590
|
+
lockScreen: 1,
|
|
591
|
+
announcement: 1,
|
|
592
|
+
notificationCenter: 1,
|
|
593
|
+
inAppNotificationSettings: 1,
|
|
594
|
+
authorizationStatus: AuthorizationStatus.NOT_DETERMINED,
|
|
595
|
+
},
|
|
596
|
+
web: {},
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
public registerForegroundService(runner: (notification: Notification) => Promise<void>): void {
|
|
601
|
+
if (!isFunction(runner)) {
|
|
602
|
+
throw new Error("notifee.registerForegroundService(_) 'runner' expected a function.");
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (isAndroid) {
|
|
606
|
+
registeredForegroundServiceTask = runner;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
public setNotificationCategories = (categories: IOSNotificationCategory[]): Promise<void> => {
|
|
613
|
+
if (!isIOS) {
|
|
614
|
+
return Promise.resolve();
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
if (!isArray(categories)) {
|
|
618
|
+
throw new Error(
|
|
619
|
+
"notifee.setNotificationCategories(*) 'categories' expected an array of IOSCategory.",
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const options = [];
|
|
624
|
+
try {
|
|
625
|
+
for (let i = 0; i < categories.length; i++) {
|
|
626
|
+
options[i] = validateIOSCategory(categories[i]);
|
|
627
|
+
}
|
|
628
|
+
} catch (e: any) {
|
|
629
|
+
throw new Error(
|
|
630
|
+
`notifee.setNotificationCategories(*) 'categories' a category is invalid: ${e.message}`,
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
return this.native.setNotificationCategories(categories);
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
public getNotificationCategories = (): Promise<IOSNotificationCategory[]> => {
|
|
638
|
+
if (!isIOS) {
|
|
639
|
+
return Promise.resolve([]);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
return this.native.getNotificationCategories();
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
public getNotificationSettings = (): Promise<NotificationSettings> => {
|
|
646
|
+
if (isAndroid) {
|
|
647
|
+
return this.native
|
|
648
|
+
.getNotificationSettings()
|
|
649
|
+
.then(
|
|
650
|
+
({
|
|
651
|
+
authorizationStatus,
|
|
652
|
+
android,
|
|
653
|
+
}: Pick<NotificationSettings, 'authorizationStatus' | 'android'>) => {
|
|
654
|
+
return {
|
|
655
|
+
authorizationStatus,
|
|
656
|
+
android,
|
|
657
|
+
ios: {
|
|
658
|
+
alert: 1,
|
|
659
|
+
badge: 1,
|
|
660
|
+
criticalAlert: 1,
|
|
661
|
+
showPreviews: 1,
|
|
662
|
+
sound: 1,
|
|
663
|
+
carPlay: 1,
|
|
664
|
+
lockScreen: 1,
|
|
665
|
+
announcement: 1,
|
|
666
|
+
notificationCenter: 1,
|
|
667
|
+
inAppNotificationSettings: 1,
|
|
668
|
+
authorizationStatus,
|
|
669
|
+
},
|
|
670
|
+
web: {},
|
|
671
|
+
};
|
|
672
|
+
},
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
if (isIOS) {
|
|
677
|
+
return this.native
|
|
678
|
+
.getNotificationSettings()
|
|
679
|
+
.then(
|
|
680
|
+
({
|
|
681
|
+
authorizationStatus,
|
|
682
|
+
ios,
|
|
683
|
+
}: Pick<NotificationSettings, 'authorizationStatus' | 'ios'>) => {
|
|
684
|
+
return {
|
|
685
|
+
authorizationStatus,
|
|
686
|
+
ios,
|
|
687
|
+
android: {
|
|
688
|
+
alarm: AndroidNotificationSetting.ENABLED,
|
|
689
|
+
},
|
|
690
|
+
};
|
|
691
|
+
},
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// assume web
|
|
696
|
+
return Promise.resolve({
|
|
697
|
+
authorizationStatus: AuthorizationStatus.NOT_DETERMINED,
|
|
698
|
+
android: {
|
|
699
|
+
alarm: AndroidNotificationSetting.ENABLED,
|
|
700
|
+
},
|
|
701
|
+
ios: {
|
|
702
|
+
alert: 1,
|
|
703
|
+
badge: 1,
|
|
704
|
+
criticalAlert: 1,
|
|
705
|
+
showPreviews: 1,
|
|
706
|
+
sound: 1,
|
|
707
|
+
carPlay: 1,
|
|
708
|
+
lockScreen: 1,
|
|
709
|
+
announcement: 1,
|
|
710
|
+
notificationCenter: 1,
|
|
711
|
+
inAppNotificationSettings: 1,
|
|
712
|
+
authorizationStatus: AuthorizationStatus.NOT_DETERMINED,
|
|
713
|
+
},
|
|
714
|
+
web: {},
|
|
715
|
+
});
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
public getBadgeCount = (): Promise<number> => {
|
|
719
|
+
if (!isIOS) {
|
|
720
|
+
return Promise.resolve(0);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return this.native.getBadgeCount();
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
public setBadgeCount = (count: number): Promise<void> => {
|
|
727
|
+
if (!isIOS) {
|
|
728
|
+
return Promise.resolve();
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
if (!isNumber(count) || count < 0) {
|
|
732
|
+
throw new Error("notifee.setBadgeCount(*) 'count' expected a number value greater than 0.");
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
return this.native.setBadgeCount(Math.round(count));
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
public incrementBadgeCount = (incrementBy?: number): Promise<void> => {
|
|
739
|
+
if (!isIOS) {
|
|
740
|
+
return Promise.resolve();
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
let value = 1;
|
|
744
|
+
if (!isUndefined(incrementBy)) {
|
|
745
|
+
if (!isNumber(incrementBy) || incrementBy < 1) {
|
|
746
|
+
throw new Error(
|
|
747
|
+
"notifee.decrementBadgeCount(*) 'incrementBy' expected a number value greater than 1.",
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
value = incrementBy;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
return this.native.incrementBadgeCount(Math.round(value));
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
public decrementBadgeCount = (decrementBy?: number): Promise<void> => {
|
|
758
|
+
if (!isIOS) {
|
|
759
|
+
return Promise.resolve();
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
let value = 1;
|
|
763
|
+
if (!isUndefined(decrementBy)) {
|
|
764
|
+
if (!isNumber(decrementBy) || decrementBy < 1) {
|
|
765
|
+
throw new Error(
|
|
766
|
+
"notifee.decrementBadgeCount(*) 'decrementBy' expected a number value greater than 1.",
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
value = decrementBy;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
return this.native.decrementBadgeCount(Math.round(value));
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
public isBatteryOptimizationEnabled = (): Promise<boolean> => {
|
|
777
|
+
if (!isAndroid) {
|
|
778
|
+
return Promise.resolve(false);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return this.native.isBatteryOptimizationEnabled();
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
public openBatteryOptimizationSettings = (): Promise<void> => {
|
|
785
|
+
if (!isAndroid) {
|
|
786
|
+
return Promise.resolve();
|
|
787
|
+
}
|
|
788
|
+
return this.native.openBatteryOptimizationSettings();
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
public getPowerManagerInfo = (): Promise<PowerManagerInfo> => {
|
|
792
|
+
if (!isAndroid) {
|
|
793
|
+
// only Android supports this, so instead we
|
|
794
|
+
// return a dummy response to allow the power manager
|
|
795
|
+
// flow work the same on all platforms
|
|
796
|
+
return Promise.resolve({
|
|
797
|
+
manufacturer: Platform.OS,
|
|
798
|
+
activity: null,
|
|
799
|
+
} as PowerManagerInfo);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
return this.native.getPowerManagerInfo();
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
public openPowerManagerSettings = (): Promise<void> => {
|
|
806
|
+
if (!isAndroid) {
|
|
807
|
+
return Promise.resolve();
|
|
808
|
+
}
|
|
809
|
+
return this.native.openPowerManagerSettings();
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
public stopForegroundService = (): Promise<void> => {
|
|
813
|
+
if (!isAndroid) {
|
|
814
|
+
return Promise.resolve();
|
|
815
|
+
}
|
|
816
|
+
return this.native.stopForegroundService();
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
public hideNotificationDrawer = (): void => {
|
|
820
|
+
if (!isAndroid) {
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
return this.native.hideNotificationDrawer();
|
|
824
|
+
};
|
|
825
|
+
}
|