@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.
Files changed (215) hide show
  1. package/.gitattributes +3 -0
  2. package/LICENSE +44 -0
  3. package/README.md +131 -0
  4. package/RNNotifee.podspec +39 -0
  5. package/RNNotifeeCore.podspec +33 -0
  6. package/android/build.gradle +116 -0
  7. package/android/gradle.properties +1 -0
  8. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar +0 -0
  9. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.md5 +1 -0
  10. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha1 +1 -0
  11. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha256 +1 -0
  12. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha512 +1 -0
  13. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom +9 -0
  14. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.md5 +1 -0
  15. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha1 +1 -0
  16. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha256 +1 -0
  17. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha512 +1 -0
  18. package/android/libs/app/notifee/core/maven-metadata.xml +13 -0
  19. package/android/libs/app/notifee/core/maven-metadata.xml.md5 +1 -0
  20. package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +1 -0
  21. package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +1 -0
  22. package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +1 -0
  23. package/android/lint.xml +5 -0
  24. package/android/proguard-rules.pro +74 -0
  25. package/android/settings.gradle +1 -0
  26. package/android/src/main/AndroidManifest.xml +12 -0
  27. package/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +349 -0
  28. package/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java +118 -0
  29. package/android/src/main/java/io/invertase/notifee/NotifeeInitProvider.java +55 -0
  30. package/android/src/main/java/io/invertase/notifee/NotifeePackage.java +30 -0
  31. package/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java +244 -0
  32. package/app.plugin.js +1 -0
  33. package/dist/NotifeeApiModule.d.ts +53 -0
  34. package/dist/NotifeeApiModule.js +607 -0
  35. package/dist/NotifeeApiModule.js.map +1 -0
  36. package/dist/NotifeeJSEventEmitter.d.ts +3 -0
  37. package/dist/NotifeeJSEventEmitter.js +14 -0
  38. package/dist/NotifeeJSEventEmitter.js.map +1 -0
  39. package/dist/NotifeeNativeError.d.ts +15 -0
  40. package/dist/NotifeeNativeError.js +61 -0
  41. package/dist/NotifeeNativeError.js.map +1 -0
  42. package/dist/NotifeeNativeModule.d.ts +14 -0
  43. package/dist/NotifeeNativeModule.js +43 -0
  44. package/dist/NotifeeNativeModule.js.map +1 -0
  45. package/dist/NotifeeNativeModule.web.d.ts +12 -0
  46. package/dist/NotifeeNativeModule.web.js +19 -0
  47. package/dist/NotifeeNativeModule.web.js.map +1 -0
  48. package/dist/index.d.ts +8 -0
  49. package/dist/index.js +43 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/types/Library.d.ts +21 -0
  52. package/dist/types/Library.js +6 -0
  53. package/dist/types/Library.js.map +1 -0
  54. package/dist/types/Module.d.ts +572 -0
  55. package/dist/types/Module.js +6 -0
  56. package/dist/types/Module.js.map +1 -0
  57. package/dist/types/Notification.d.ts +450 -0
  58. package/dist/types/Notification.js +105 -0
  59. package/dist/types/Notification.js.map +1 -0
  60. package/dist/types/NotificationAndroid.d.ts +1276 -0
  61. package/dist/types/NotificationAndroid.js +380 -0
  62. package/dist/types/NotificationAndroid.js.map +1 -0
  63. package/dist/types/NotificationIOS.d.ts +537 -0
  64. package/dist/types/NotificationIOS.js +92 -0
  65. package/dist/types/NotificationIOS.js.map +1 -0
  66. package/dist/types/NotificationWeb.d.ts +5 -0
  67. package/dist/types/NotificationWeb.js +3 -0
  68. package/dist/types/NotificationWeb.js.map +1 -0
  69. package/dist/types/PowerManagerInfo.d.ts +36 -0
  70. package/dist/types/PowerManagerInfo.js +6 -0
  71. package/dist/types/PowerManagerInfo.js.map +1 -0
  72. package/dist/types/Trigger.d.ts +108 -0
  73. package/dist/types/Trigger.js +39 -0
  74. package/dist/types/Trigger.js.map +1 -0
  75. package/dist/utils/id.d.ts +1 -0
  76. package/dist/utils/id.js +16 -0
  77. package/dist/utils/id.js.map +1 -0
  78. package/dist/utils/index.d.ts +16 -0
  79. package/dist/utils/index.js +52 -0
  80. package/dist/utils/index.js.map +1 -0
  81. package/dist/utils/validate.d.ts +15 -0
  82. package/dist/utils/validate.js +93 -0
  83. package/dist/utils/validate.js.map +1 -0
  84. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.d.ts +2 -0
  85. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js +39 -0
  86. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js.map +1 -0
  87. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.d.ts +2 -0
  88. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js +27 -0
  89. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js.map +1 -0
  90. package/dist/validators/validate.d.ts +25 -0
  91. package/dist/validators/validate.js +75 -0
  92. package/dist/validators/validate.js.map +1 -0
  93. package/dist/validators/validateAndroidAction.d.ts +2 -0
  94. package/dist/validators/validateAndroidAction.js +52 -0
  95. package/dist/validators/validateAndroidAction.js.map +1 -0
  96. package/dist/validators/validateAndroidChannel.d.ts +2 -0
  97. package/dist/validators/validateAndroidChannel.js +155 -0
  98. package/dist/validators/validateAndroidChannel.js.map +1 -0
  99. package/dist/validators/validateAndroidChannelGroup.d.ts +2 -0
  100. package/dist/validators/validateAndroidChannelGroup.js +42 -0
  101. package/dist/validators/validateAndroidChannelGroup.js.map +1 -0
  102. package/dist/validators/validateAndroidFullScreenAction.d.ts +2 -0
  103. package/dist/validators/validateAndroidFullScreenAction.js +50 -0
  104. package/dist/validators/validateAndroidFullScreenAction.js.map +1 -0
  105. package/dist/validators/validateAndroidInput.d.ts +2 -0
  106. package/dist/validators/validateAndroidInput.js +54 -0
  107. package/dist/validators/validateAndroidInput.js.map +1 -0
  108. package/dist/validators/validateAndroidNotification.d.ts +2 -0
  109. package/dist/validators/validateAndroidNotification.js +529 -0
  110. package/dist/validators/validateAndroidNotification.js.map +1 -0
  111. package/dist/validators/validateAndroidPressAction.d.ts +2 -0
  112. package/dist/validators/validateAndroidPressAction.js +50 -0
  113. package/dist/validators/validateAndroidPressAction.js.map +1 -0
  114. package/dist/validators/validateAndroidStyle.d.ts +22 -0
  115. package/dist/validators/validateAndroidStyle.js +231 -0
  116. package/dist/validators/validateAndroidStyle.js.map +1 -0
  117. package/dist/validators/validateIOSAttachment.d.ts +6 -0
  118. package/dist/validators/validateIOSAttachment.js +102 -0
  119. package/dist/validators/validateIOSAttachment.js.map +1 -0
  120. package/dist/validators/validateIOSCategory.d.ts +2 -0
  121. package/dist/validators/validateIOSCategory.js +124 -0
  122. package/dist/validators/validateIOSCategory.js.map +1 -0
  123. package/dist/validators/validateIOSCategoryAction.d.ts +2 -0
  124. package/dist/validators/validateIOSCategoryAction.js +59 -0
  125. package/dist/validators/validateIOSCategoryAction.js.map +1 -0
  126. package/dist/validators/validateIOSInput.d.ts +2 -0
  127. package/dist/validators/validateIOSInput.js +32 -0
  128. package/dist/validators/validateIOSInput.js.map +1 -0
  129. package/dist/validators/validateIOSNotification.d.ts +2 -0
  130. package/dist/validators/validateIOSNotification.js +211 -0
  131. package/dist/validators/validateIOSNotification.js.map +1 -0
  132. package/dist/validators/validateIOSPermissions.d.ts +2 -0
  133. package/dist/validators/validateIOSPermissions.js +62 -0
  134. package/dist/validators/validateIOSPermissions.js.map +1 -0
  135. package/dist/validators/validateNotification.d.ts +11 -0
  136. package/dist/validators/validateNotification.js +129 -0
  137. package/dist/validators/validateNotification.js.map +1 -0
  138. package/dist/validators/validateTrigger.d.ts +2 -0
  139. package/dist/validators/validateTrigger.js +104 -0
  140. package/dist/validators/validateTrigger.js.map +1 -0
  141. package/dist/version.d.ts +1 -0
  142. package/dist/version.js.map +1 -0
  143. package/ios/NotifeeCore/Info.plist +22 -0
  144. package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.h +28 -0
  145. package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +72 -0
  146. package/ios/NotifeeCore/NotifeeCore+NSURLSession.h +25 -0
  147. package/ios/NotifeeCore/NotifeeCore+NSURLSession.m +55 -0
  148. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.h +37 -0
  149. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +242 -0
  150. package/ios/NotifeeCore/NotifeeCore.h +118 -0
  151. package/ios/NotifeeCore/NotifeeCore.m +784 -0
  152. package/ios/NotifeeCore/NotifeeCoreDelegateHolder.h +34 -0
  153. package/ios/NotifeeCore/NotifeeCoreDelegateHolder.m +70 -0
  154. package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.h +39 -0
  155. package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.m +68 -0
  156. package/ios/NotifeeCore/NotifeeCoreExtensionHelper.h +38 -0
  157. package/ios/NotifeeCore/NotifeeCoreExtensionHelper.m +224 -0
  158. package/ios/NotifeeCore/NotifeeCoreUtil.h +82 -0
  159. package/ios/NotifeeCore/NotifeeCoreUtil.m +793 -0
  160. package/ios/RNNotifee/NotifeeApiModule.h +25 -0
  161. package/ios/RNNotifee/NotifeeApiModule.m +371 -0
  162. package/ios/RNNotifee/NotifeeExtensionHelper.h +37 -0
  163. package/ios/RNNotifee/NotifeeExtensionHelper.m +37 -0
  164. package/ios/RNNotifee.xcodeproj/project.pbxproj +318 -0
  165. package/jest-mock.js +158 -0
  166. package/package.json +59 -0
  167. package/plugin/build/index.d.ts +3 -0
  168. package/plugin/build/index.js +12 -0
  169. package/plugin/build/index.js.map +1 -0
  170. package/plugin/build/withNotifeeProjectGradlePlugin.d.ts +5 -0
  171. package/plugin/build/withNotifeeProjectGradlePlugin.js +24 -0
  172. package/plugin/build/withNotifeeProjectGradlePlugin.js.map +1 -0
  173. package/plugin/src/index.ts +9 -0
  174. package/plugin/src/withNotifeeProjectGradlePlugin.ts +27 -0
  175. package/plugin/tsconfig.json +9 -0
  176. package/react-native.config.js +11 -0
  177. package/refresh-example.sh +71 -0
  178. package/src/NotifeeApiModule.ts +825 -0
  179. package/src/NotifeeJSEventEmitter.ts +11 -0
  180. package/src/NotifeeNativeError.ts +70 -0
  181. package/src/NotifeeNativeModule.ts +55 -0
  182. package/src/NotifeeNativeModule.web.ts +25 -0
  183. package/src/index.ts +33 -0
  184. package/src/types/Library.ts +28 -0
  185. package/src/types/Module.ts +625 -0
  186. package/src/types/Notification.ts +505 -0
  187. package/src/types/NotificationAndroid.ts +1443 -0
  188. package/src/types/NotificationIOS.ts +681 -0
  189. package/src/types/NotificationWeb.ts +5 -0
  190. package/src/types/PowerManagerInfo.ts +43 -0
  191. package/src/types/Trigger.ts +118 -0
  192. package/src/utils/id.ts +13 -0
  193. package/src/utils/index.ts +47 -0
  194. package/src/utils/validate.ts +92 -0
  195. package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfo.ts +45 -0
  196. package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.ts +33 -0
  197. package/src/validators/validate.ts +85 -0
  198. package/src/validators/validateAndroidAction.ts +54 -0
  199. package/src/validators/validateAndroidChannel.ts +188 -0
  200. package/src/validators/validateAndroidChannelGroup.ts +49 -0
  201. package/src/validators/validateAndroidFullScreenAction.ts +65 -0
  202. package/src/validators/validateAndroidInput.ts +67 -0
  203. package/src/validators/validateAndroidNotification.ts +704 -0
  204. package/src/validators/validateAndroidPressAction.ts +65 -0
  205. package/src/validators/validateAndroidStyle.ts +315 -0
  206. package/src/validators/validateIOSAttachment.ts +136 -0
  207. package/src/validators/validateIOSCategory.ts +150 -0
  208. package/src/validators/validateIOSCategoryAction.ts +65 -0
  209. package/src/validators/validateIOSInput.ts +38 -0
  210. package/src/validators/validateIOSNotification.ts +296 -0
  211. package/src/validators/validateIOSPermissions.ts +78 -0
  212. package/src/validators/validateNotification.ts +156 -0
  213. package/src/validators/validateTrigger.ts +134 -0
  214. package/src/version.ts +2 -0
  215. package/tsconfig.json +23 -0
@@ -0,0 +1,784 @@
1
+ /**
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ #import <UIKit/UIKit.h>
19
+
20
+ #import "Intents/Intents.h"
21
+ #import "NotifeeCore+UNUserNotificationCenter.h"
22
+ #import "NotifeeCore.h"
23
+ #import "NotifeeCoreDelegateHolder.h"
24
+ #import "NotifeeCoreExtensionHelper.h"
25
+ #import "NotifeeCoreUtil.h"
26
+
27
+ @implementation NotifeeCore
28
+
29
+ #pragma mark - Library Methods
30
+
31
+ + (void)setCoreDelegate:(id<NotifeeCoreDelegate>)coreDelegate {
32
+ [NotifeeCoreDelegateHolder instance].delegate = coreDelegate;
33
+ }
34
+
35
+ /**
36
+ * Cancel a currently displayed or pending trigger notification.
37
+ *
38
+ * @param notificationId NSString id of the notification to cancel
39
+ * @param block notifeeMethodVoidBlock
40
+ */
41
+ + (void)cancelNotification:(NSString *)notificationId
42
+ withNotificationType:(NSInteger)notificationType
43
+ withBlock:(notifeeMethodVoidBlock)block {
44
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
45
+ // cancel displayed notification
46
+ if (notificationType == NotifeeCoreNotificationTypeDisplayed ||
47
+ notificationType == NotifeeCoreNotificationTypeAll)
48
+ [center removeDeliveredNotificationsWithIdentifiers:@[ notificationId ]];
49
+
50
+ // cancel trigger notification
51
+ if (notificationType == NotifeeCoreNotificationTypeTrigger ||
52
+ notificationType == NotifeeCoreNotificationTypeAll)
53
+ [center removePendingNotificationRequestsWithIdentifiers:@[ notificationId ]];
54
+ block(nil);
55
+ }
56
+
57
+ /**
58
+ * Cancel all currently displayed or pending trigger notifications.
59
+ *
60
+ * @param notificationType NSInteger
61
+ * @param block notifeeMethodVoidBlock
62
+ */
63
+ + (void)cancelAllNotifications:(NSInteger)notificationType withBlock:(notifeeMethodVoidBlock)block {
64
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
65
+
66
+ // cancel displayed notifications
67
+ if (notificationType == NotifeeCoreNotificationTypeDisplayed ||
68
+ notificationType == NotifeeCoreNotificationTypeAll)
69
+ [center removeAllDeliveredNotifications];
70
+
71
+ // cancel trigger notifications
72
+ if (notificationType == NotifeeCoreNotificationTypeTrigger ||
73
+ notificationType == NotifeeCoreNotificationTypeAll)
74
+ [center removeAllPendingNotificationRequests];
75
+ block(nil);
76
+ }
77
+
78
+ /**
79
+ * Cancel currently displayed or pending trigger notifications by ids.
80
+ *
81
+ * @param notificationType NSInteger
82
+ * @param ids NSInteger
83
+ * @param block notifeeMethodVoidBlock
84
+ */
85
+ + (void)cancelAllNotificationsWithIds:(NSInteger)notificationType
86
+ withIds:(NSArray<NSString *> *)ids
87
+ withBlock:(notifeeMethodVoidBlock)block {
88
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
89
+
90
+ // cancel displayed notifications
91
+ if (notificationType == NotifeeCoreNotificationTypeDisplayed ||
92
+ notificationType == NotifeeCoreNotificationTypeAll)
93
+ [center removeDeliveredNotificationsWithIdentifiers:ids];
94
+
95
+ // cancel trigger notifications
96
+ if (notificationType == NotifeeCoreNotificationTypeTrigger ||
97
+ notificationType == NotifeeCoreNotificationTypeAll)
98
+ [center removePendingNotificationRequestsWithIdentifiers:ids];
99
+ block(nil);
100
+ }
101
+
102
+ + (void)getDisplayedNotifications:(notifeeMethodNSArrayBlock)block {
103
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
104
+ NSMutableArray *triggerNotifications = [[NSMutableArray alloc] init];
105
+ [center getDeliveredNotificationsWithCompletionHandler:^(
106
+ NSArray<UNNotification *> *_Nonnull deliveredNotifications) {
107
+ for (UNNotification *deliveredNotification in deliveredNotifications) {
108
+ NSMutableDictionary *triggerNotification = [NSMutableDictionary dictionary];
109
+ triggerNotification[@"id"] = deliveredNotification.request.identifier;
110
+
111
+ triggerNotification[@"date"] =
112
+ [NotifeeCoreUtil convertToTimestamp:deliveredNotification.date];
113
+ triggerNotification[@"notification"] =
114
+ deliveredNotification.request.content.userInfo[kNotifeeUserInfoNotification];
115
+ triggerNotification[@"trigger"] =
116
+ deliveredNotification.request.content.userInfo[kNotifeeUserInfoTrigger];
117
+
118
+ if (triggerNotification[@"notification"] == nil) {
119
+ // parse remote notification
120
+ triggerNotification[@"notification"] =
121
+ [NotifeeCoreUtil parseUNNotificationRequest:deliveredNotification.request];
122
+ }
123
+
124
+ [triggerNotifications addObject:triggerNotification];
125
+ }
126
+ block(nil, triggerNotifications);
127
+ }];
128
+ }
129
+
130
+ + (void)getTriggerNotifications:(notifeeMethodNSArrayBlock)block {
131
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
132
+
133
+ [center getPendingNotificationRequestsWithCompletionHandler:^(
134
+ NSArray<UNNotificationRequest *> *_Nonnull requests) {
135
+ NSMutableArray *triggerNotifications = [[NSMutableArray alloc] init];
136
+
137
+ for (UNNotificationRequest *request in requests) {
138
+ NSMutableDictionary *triggerNotification = [NSMutableDictionary dictionary];
139
+
140
+ triggerNotification[@"notification"] = request.content.userInfo[kNotifeeUserInfoNotification];
141
+ triggerNotification[@"trigger"] = request.content.userInfo[kNotifeeUserInfoTrigger];
142
+
143
+ [triggerNotifications addObject:triggerNotification];
144
+ }
145
+
146
+ block(nil, triggerNotifications);
147
+ }];
148
+ }
149
+
150
+ /**
151
+ * Retrieve a NSArray of pending UNNotificationRequest for the application.
152
+ * Resolves a NSArray of UNNotificationRequest identifiers.
153
+ *
154
+ * @param block notifeeMethodNSArrayBlock
155
+ */
156
+ + (void)getTriggerNotificationIds:(notifeeMethodNSArrayBlock)block {
157
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
158
+ [center getPendingNotificationRequestsWithCompletionHandler:^(
159
+ NSArray<UNNotificationRequest *> *_Nonnull requests) {
160
+ NSMutableArray<NSString *> *idsArray = [[NSMutableArray alloc] init];
161
+
162
+ for (UNNotificationRequest *request in requests) {
163
+ NSString *notificationId = request.identifier;
164
+ [idsArray addObject:notificationId];
165
+ }
166
+
167
+ block(nil, idsArray);
168
+ }];
169
+ }
170
+
171
+ /**
172
+ * Display a local notification immediately.
173
+ *
174
+ * @param notification NSDictionary representation of
175
+ * UNMutableNotificationContent
176
+ * @param block notifeeMethodVoidBlock
177
+ */
178
+ + (void)displayNotification:(NSDictionary *)notification withBlock:(notifeeMethodVoidBlock)block {
179
+ UNMutableNotificationContent *content = [self buildNotificationContent:notification
180
+ withTrigger:nil];
181
+
182
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
183
+
184
+ NSMutableDictionary *notificationDetail = [notification mutableCopy];
185
+ notificationDetail[@"remote"] = @NO;
186
+
187
+ if (@available(iOS 15.0, *)) {
188
+ if (notification[@"ios"][@"communicationInfo"] != nil) {
189
+ INSendMessageIntent *intent = [NotifeeCoreUtil
190
+ generateSenderIntentForCommunicationNotifciation:notification[@"ios"]
191
+ [@"communicationInfo"]];
192
+
193
+ // Use the intent to initialize the interaction.
194
+ INInteraction *interaction = [[INInteraction alloc] initWithIntent:intent response:nil];
195
+ interaction.direction = INInteractionDirectionIncoming;
196
+ [interaction donateInteractionWithCompletion:^(NSError *error) {
197
+ if (error)
198
+ NSLog(@"NotifeeCore: Could not donate interaction for communication notification: %@",
199
+ error);
200
+ }];
201
+
202
+ content = [[content contentByUpdatingWithProvider:intent error:nil] mutableCopy];
203
+ }
204
+ }
205
+
206
+ UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:notification[@"id"]
207
+ content:content
208
+ trigger:nil];
209
+
210
+ [center addNotificationRequest:request
211
+ withCompletionHandler:^(NSError *error) {
212
+ if (error == nil) {
213
+ [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:@{
214
+ @"type" : @(NotifeeCoreEventTypeDelivered),
215
+ @"detail" : @{
216
+ @"notification" : notificationDetail,
217
+ }
218
+ }];
219
+ }
220
+ block(error);
221
+ }];
222
+ }
223
+
224
+ /* Create a trigger notification .
225
+ *
226
+ * @param notification NSDictionary representation of
227
+ * UNMutableNotificationContent
228
+ * @param block notifeeMethodVoidBlock
229
+ */
230
+ + (void)createTriggerNotification:(NSDictionary *)notification
231
+ withTrigger:(NSDictionary *)trigger
232
+ withBlock:(notifeeMethodVoidBlock)block {
233
+ UNMutableNotificationContent *content = [self buildNotificationContent:notification
234
+ withTrigger:trigger];
235
+ UNNotificationTrigger *unTrigger = [NotifeeCoreUtil triggerFromDictionary:trigger];
236
+
237
+ if (unTrigger == nil) {
238
+ // do nothing if trigger is null
239
+ return block(nil);
240
+ }
241
+
242
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
243
+
244
+ NSMutableDictionary *notificationDetail = [notification mutableCopy];
245
+ notificationDetail[@"remote"] = @NO;
246
+
247
+ if (@available(iOS 15.0, *)) {
248
+ if (notification[@"ios"][@"communicationInfo"] != nil) {
249
+ INSendMessageIntent *intent = [NotifeeCoreUtil
250
+ generateSenderIntentForCommunicationNotifciation:notification[@"ios"]
251
+ [@"communicationInfo"]];
252
+
253
+ // Use the intent to initialize the interaction.
254
+ INInteraction *interaction = [[INInteraction alloc] initWithIntent:intent response:nil];
255
+ interaction.direction = INInteractionDirectionIncoming;
256
+ [interaction donateInteractionWithCompletion:^(NSError *error) {
257
+ if (error)
258
+ NSLog(@"NotifeeCore: Could not donate interaction for communication notification: %@",
259
+ error);
260
+ }];
261
+
262
+ content = [[content contentByUpdatingWithProvider:intent error:nil] mutableCopy];
263
+ }
264
+ }
265
+
266
+ UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:notification[@"id"]
267
+ content:content
268
+ trigger:unTrigger];
269
+
270
+ [center addNotificationRequest:request
271
+ withCompletionHandler:^(NSError *error) {
272
+ if (error == nil) {
273
+ [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:@{
274
+ @"type" : @(NotifeeCoreEventTypeTriggerNotificationCreated),
275
+ @"detail" : @{
276
+ @"notification" : notificationDetail,
277
+ }
278
+ }];
279
+ }
280
+ block(error);
281
+ }];
282
+ }
283
+
284
+ /**
285
+ * Builds a UNMutableNotificationContent from a NSDictionary.
286
+ *
287
+ * @param notification NSDictionary representation of UNNotificationContent
288
+ */
289
+
290
+ + (UNMutableNotificationContent *)buildNotificationContent:(NSDictionary *)notification
291
+ withTrigger:(NSDictionary *)trigger {
292
+ NSDictionary *iosDict = notification[@"ios"];
293
+ UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
294
+
295
+ // title
296
+ if (notification[@"title"] != nil) {
297
+ content.title = notification[@"title"];
298
+ }
299
+
300
+ // subtitle
301
+ if (notification[@"subtitle"] != nil) {
302
+ content.subtitle = notification[@"subtitle"];
303
+ }
304
+
305
+ // body
306
+ if (notification[@"body"] != nil) {
307
+ content.body = notification[@"body"];
308
+ }
309
+
310
+ NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
311
+
312
+ // data
313
+ if (notification[@"data"] != nil) {
314
+ userInfo = [notification[@"data"] mutableCopy];
315
+ }
316
+
317
+ // attach a copy of the original notification payload into the data object,
318
+ // for internal use
319
+ userInfo[kNotifeeUserInfoNotification] = [notification mutableCopy];
320
+ if (trigger != nil) {
321
+ userInfo[kNotifeeUserInfoTrigger] = [trigger mutableCopy];
322
+ }
323
+
324
+ content.userInfo = userInfo;
325
+
326
+ // badgeCount - nil is an acceptable value so no need to check key existence
327
+ content.badge = iosDict[@"badgeCount"];
328
+
329
+ // categoryId
330
+ if (iosDict[@"categoryId"] != nil && iosDict[@"categoryId"] != [NSNull null]) {
331
+ content.categoryIdentifier = iosDict[@"categoryId"];
332
+ }
333
+
334
+ // launchImageName
335
+ if (iosDict[@"launchImageName"] != nil && iosDict[@"launchImageName"] != [NSNull null]) {
336
+ content.launchImageName = iosDict[@"launchImageName"];
337
+ }
338
+
339
+ // interruptionLevel
340
+ if (@available(iOS 15.0, *)) {
341
+ if (iosDict[@"interruptionLevel"] != nil) {
342
+ if ([iosDict[@"interruptionLevel"] isEqualToString:@"passive"]) {
343
+ content.interruptionLevel = UNNotificationInterruptionLevelPassive;
344
+ } else if ([iosDict[@"interruptionLevel"] isEqualToString:@"active"]) {
345
+ content.interruptionLevel = UNNotificationInterruptionLevelActive;
346
+ } else if ([iosDict[@"interruptionLevel"] isEqualToString:@"timeSensitive"]) {
347
+ content.interruptionLevel = UNNotificationInterruptionLevelTimeSensitive;
348
+ } else if ([iosDict[@"interruptionLevel"] isEqualToString:@"critical"]) {
349
+ content.interruptionLevel = UNNotificationInterruptionLevelCritical;
350
+ }
351
+ }
352
+ }
353
+
354
+ // critical, criticalVolume, sound
355
+ if (iosDict[@"critical"] != nil && iosDict[@"critical"] != [NSNull null]) {
356
+ UNNotificationSound *notificationSound;
357
+ BOOL criticalSound = [iosDict[@"critical"] boolValue];
358
+ NSNumber *criticalSoundVolume = iosDict[@"criticalVolume"];
359
+ NSString *soundName = iosDict[@"sound"] != nil ? iosDict[@"sound"] : @"default";
360
+
361
+ if ([soundName isEqualToString:@"default"]) {
362
+ if (criticalSound) {
363
+ if (@available(iOS 12.0, *)) {
364
+ if (criticalSoundVolume != nil) {
365
+ notificationSound = [UNNotificationSound
366
+ defaultCriticalSoundWithAudioVolume:[criticalSoundVolume floatValue]];
367
+ } else {
368
+ notificationSound = [UNNotificationSound defaultCriticalSound];
369
+ }
370
+ } else {
371
+ notificationSound = [UNNotificationSound defaultSound];
372
+ }
373
+ } else {
374
+ notificationSound = [UNNotificationSound defaultSound];
375
+ }
376
+ } else {
377
+ if (criticalSound) {
378
+ if (@available(iOS 12.0, *)) {
379
+ if (criticalSoundVolume != nil) {
380
+ notificationSound =
381
+ [UNNotificationSound criticalSoundNamed:soundName
382
+ withAudioVolume:[criticalSoundVolume floatValue]];
383
+ } else {
384
+ notificationSound = [UNNotificationSound criticalSoundNamed:soundName];
385
+ }
386
+ } else {
387
+ notificationSound = [UNNotificationSound soundNamed:soundName];
388
+ }
389
+ } else {
390
+ notificationSound = [UNNotificationSound soundNamed:soundName];
391
+ }
392
+ }
393
+ content.sound = notificationSound;
394
+ } else if (iosDict[@"sound"] != nil) {
395
+ UNNotificationSound *notificationSound;
396
+ NSString *soundName = iosDict[@"sound"];
397
+
398
+ if ([soundName isEqualToString:@"default"]) {
399
+ notificationSound = [UNNotificationSound defaultSound];
400
+ } else {
401
+ notificationSound = [UNNotificationSound soundNamed:soundName];
402
+ }
403
+
404
+ content.sound = notificationSound;
405
+
406
+ } // critical, criticalVolume, sound
407
+
408
+ // threadId
409
+ if (iosDict[@"threadId"] != nil) {
410
+ content.threadIdentifier = iosDict[@"threadId"];
411
+ }
412
+
413
+ if (@available(iOS 12.0, *)) {
414
+ // summaryArgument
415
+ if (iosDict[@"summaryArgument"] != nil) {
416
+ content.summaryArgument = iosDict[@"summaryArgument"];
417
+ }
418
+
419
+ // summaryArgumentCount
420
+ if (iosDict[@"summaryArgumentCount"] != nil) {
421
+ content.summaryArgumentCount = [iosDict[@"summaryArgumentCount"] unsignedIntValue];
422
+ }
423
+ }
424
+
425
+ if (@available(iOS 13.0, *)) {
426
+ // targetContentId
427
+ if (iosDict[@"targetContentId"] != nil) {
428
+ content.targetContentIdentifier = iosDict[@"targetContentId"];
429
+ }
430
+ }
431
+
432
+ // Ignore downloading attachments here if remote notifications via NSE
433
+ BOOL remote = [notification[@"remote"] boolValue];
434
+
435
+ if (iosDict[@"attachments"] != nil && !remote) {
436
+ content.attachments =
437
+ [NotifeeCoreUtil notificationAttachmentsFromDictionaryArray:iosDict[@"attachments"]];
438
+ }
439
+
440
+ return content;
441
+ }
442
+
443
+ + (void)getNotificationCategories:(notifeeMethodNSArrayBlock)block {
444
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
445
+ [center getNotificationCategoriesWithCompletionHandler:^(
446
+ NSSet<UNNotificationCategory *> *categories) {
447
+ NSMutableArray<NSDictionary *> *categoriesArray = [[NSMutableArray alloc] init];
448
+
449
+ for (UNNotificationCategory *notificationCategory in categories) {
450
+ NSMutableDictionary *categoryDictionary = [NSMutableDictionary dictionary];
451
+
452
+ categoryDictionary[@"id"] = notificationCategory.identifier;
453
+ categoryDictionary[@"allowInCarPlay"] =
454
+ @(((notificationCategory.options & UNNotificationCategoryOptionAllowInCarPlay) != 0));
455
+
456
+ if (@available(iOS 11.0, *)) {
457
+ categoryDictionary[@"hiddenPreviewsShowTitle"] =
458
+ @(((notificationCategory.options &
459
+ UNNotificationCategoryOptionHiddenPreviewsShowTitle) != 0));
460
+ categoryDictionary[@"hiddenPreviewsShowSubtitle"] =
461
+ @(((notificationCategory.options &
462
+ UNNotificationCategoryOptionHiddenPreviewsShowSubtitle) != 0));
463
+ if (notificationCategory.hiddenPreviewsBodyPlaceholder != nil) {
464
+ categoryDictionary[@"hiddenPreviewsBodyPlaceholder"] =
465
+ notificationCategory.hiddenPreviewsBodyPlaceholder;
466
+ }
467
+ } else {
468
+ categoryDictionary[@"hiddenPreviewsShowTitle"] = @(NO);
469
+ categoryDictionary[@"hiddenPreviewsShowSubtitle"] = @(NO);
470
+ }
471
+
472
+ if (@available(iOS 12.0, *)) {
473
+ if (notificationCategory.categorySummaryFormat != nil) {
474
+ categoryDictionary[@"summaryFormat"] = notificationCategory.categorySummaryFormat;
475
+ }
476
+ }
477
+
478
+ if (@available(iOS 13.0, *)) {
479
+ categoryDictionary[@"allowAnnouncement"] = @(
480
+ ((notificationCategory.options & UNNotificationCategoryOptionAllowAnnouncement) != 0));
481
+ } else {
482
+ categoryDictionary[@"allowAnnouncement"] = @(NO);
483
+ }
484
+
485
+ categoryDictionary[@"actions"] =
486
+ [NotifeeCoreUtil notificationActionsToDictionaryArray:notificationCategory.actions];
487
+ categoryDictionary[@"intentIdentifiers"] =
488
+ [NotifeeCoreUtil intentIdentifiersFromStringArray:notificationCategory.intentIdentifiers];
489
+
490
+ [categoriesArray addObject:categoryDictionary];
491
+ }
492
+
493
+ block(nil, categoriesArray);
494
+ }];
495
+ }
496
+
497
+ /**
498
+ * Builds and replaces the existing notification categories on
499
+ * UNUserNotificationCenter
500
+ *
501
+ * @param categories NSArray<NSDictionary *> *
502
+ * @param block notifeeMethodVoidBlock
503
+ */
504
+ + (void)setNotificationCategories:(NSArray<NSDictionary *> *)categories
505
+ withBlock:(notifeeMethodVoidBlock)block {
506
+ NSMutableSet *UNNotificationCategories = [[NSMutableSet alloc] init];
507
+
508
+ for (NSDictionary *categoryDictionary in categories) {
509
+ UNNotificationCategory *category;
510
+
511
+ NSString *id = categoryDictionary[@"id"];
512
+ NSString *summaryFormat = categoryDictionary[@"summaryFormat"];
513
+ NSString *bodyPlaceHolder = categoryDictionary[@"hiddenPreviewsBodyPlaceholder"];
514
+
515
+ NSArray<UNNotificationAction *> *actions =
516
+ [NotifeeCoreUtil notificationActionsFromDictionaryArray:categoryDictionary[@"actions"]];
517
+ NSArray<NSString *> *intentIdentifiers =
518
+ [NotifeeCoreUtil intentIdentifiersFromNumberArray:categoryDictionary[@"intentIdentifiers"]];
519
+
520
+ UNNotificationCategoryOptions options = UNNotificationCategoryOptionCustomDismissAction;
521
+
522
+ if ([categoryDictionary[@"allowInCarPlay"] isEqual:@(YES)]) {
523
+ options |= UNNotificationCategoryOptionAllowInCarPlay;
524
+ }
525
+
526
+ if (@available(iOS 11.0, *)) {
527
+ if ([categoryDictionary[@"hiddenPreviewsShowTitle"] isEqual:@(YES)]) {
528
+ options |= UNNotificationCategoryOptionHiddenPreviewsShowTitle;
529
+ }
530
+
531
+ if ([categoryDictionary[@"hiddenPreviewsShowSubtitle"] isEqual:@(YES)]) {
532
+ options |= UNNotificationCategoryOptionHiddenPreviewsShowSubtitle;
533
+ }
534
+ }
535
+
536
+ if (@available(iOS 13.0, *)) {
537
+ if ([categoryDictionary[@"allowAnnouncement"] isEqual:@(YES)]) {
538
+ options |= UNNotificationCategoryOptionAllowAnnouncement;
539
+ }
540
+ }
541
+
542
+ if (@available(iOS 12.0, *)) {
543
+ category = [UNNotificationCategory categoryWithIdentifier:id
544
+ actions:actions
545
+ intentIdentifiers:intentIdentifiers
546
+ hiddenPreviewsBodyPlaceholder:bodyPlaceHolder
547
+ categorySummaryFormat:summaryFormat
548
+ options:options];
549
+ } else if (@available(iOS 11.0, *)) {
550
+ category = [UNNotificationCategory categoryWithIdentifier:id
551
+ actions:actions
552
+ intentIdentifiers:intentIdentifiers
553
+ hiddenPreviewsBodyPlaceholder:bodyPlaceHolder
554
+ options:options];
555
+ } else {
556
+ category = [UNNotificationCategory categoryWithIdentifier:id
557
+ actions:actions
558
+ intentIdentifiers:intentIdentifiers
559
+ options:options];
560
+ }
561
+
562
+ [UNNotificationCategories addObject:category];
563
+ }
564
+
565
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
566
+ [center setNotificationCategories:UNNotificationCategories];
567
+ block(nil);
568
+ }
569
+
570
+ /**
571
+ * Request UNAuthorizationOptions for user notifications.
572
+ * Resolves a NSDictionary representation of UNNotificationSettings.
573
+ *
574
+ * @param permissions NSDictionary
575
+ * @param block NSDictionary block
576
+ */
577
+ + (void)requestPermission:(NSDictionary *)permissions
578
+ withBlock:(notifeeMethodNSDictionaryBlock)block {
579
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
580
+
581
+ UNAuthorizationOptions options = UNAuthorizationOptionNone;
582
+
583
+ if ([permissions[@"alert"] isEqual:@(YES)]) {
584
+ options |= UNAuthorizationOptionAlert;
585
+ }
586
+
587
+ if ([permissions[@"badge"] isEqual:@(YES)]) {
588
+ options |= UNAuthorizationOptionBadge;
589
+ }
590
+
591
+ if ([permissions[@"sound"] isEqual:@(YES)]) {
592
+ options |= UNAuthorizationOptionSound;
593
+ }
594
+
595
+ if ([permissions[@"inAppNotificationSettings"] isEqual:@(YES)]) {
596
+ if (@available(iOS 12.0, *)) {
597
+ options |= UNAuthorizationOptionProvidesAppNotificationSettings;
598
+ }
599
+ }
600
+
601
+ if ([permissions[@"provisional"] isEqual:@(YES)]) {
602
+ if (@available(iOS 12.0, *)) {
603
+ options |= UNAuthorizationOptionProvisional;
604
+ }
605
+ }
606
+
607
+ if ([permissions[@"announcement"] isEqual:@(YES)]) {
608
+ if (@available(iOS 13.0, *)) {
609
+ options |= UNAuthorizationOptionAnnouncement;
610
+ }
611
+ }
612
+
613
+ if ([permissions[@"carPlay"] isEqual:@(YES)]) {
614
+ options |= UNAuthorizationOptionCarPlay;
615
+ }
616
+
617
+ if ([permissions[@"criticalAlert"] isEqual:@(YES)]) {
618
+ if (@available(iOS 12.0, *)) {
619
+ options |= UNAuthorizationOptionCriticalAlert;
620
+ }
621
+ }
622
+
623
+ id handler = ^(BOOL granted, NSError *_Nullable error) {
624
+ if (error != nil) {
625
+ // TODO send error to notifeeMethodNSDictionaryBlock
626
+ }
627
+
628
+ [self getNotificationSettings:block];
629
+ };
630
+
631
+ [center requestAuthorizationWithOptions:options completionHandler:handler];
632
+ }
633
+
634
+ /**
635
+ * Retrieve UNNotificationSettings for the application.
636
+ * Resolves a NSDictionary representation of UNNotificationSettings.
637
+ *
638
+ * @param block NSDictionary block
639
+ */
640
+ + (void)getNotificationSettings:(notifeeMethodNSDictionaryBlock)block {
641
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
642
+
643
+ [center
644
+ getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *_Nonnull settings) {
645
+ NSMutableDictionary *settingsDictionary = [NSMutableDictionary dictionary];
646
+ NSMutableDictionary *iosDictionary = [NSMutableDictionary dictionary];
647
+
648
+ // authorizationStatus
649
+ NSNumber *authorizationStatus = @-1;
650
+ if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) {
651
+ authorizationStatus = @-1;
652
+ } else if (settings.authorizationStatus == UNAuthorizationStatusDenied) {
653
+ authorizationStatus = @0;
654
+ } else if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
655
+ authorizationStatus = @1;
656
+ }
657
+
658
+ if (@available(iOS 12.0, *)) {
659
+ if (settings.authorizationStatus == UNAuthorizationStatusProvisional) {
660
+ authorizationStatus = @2;
661
+ }
662
+ }
663
+
664
+ NSNumber *showPreviews = @-1;
665
+ if (@available(iOS 11.0, *)) {
666
+ if (settings.showPreviewsSetting == UNShowPreviewsSettingNever) {
667
+ showPreviews = @0;
668
+ } else if (settings.showPreviewsSetting == UNShowPreviewsSettingAlways) {
669
+ showPreviews = @1;
670
+ } else if (settings.showPreviewsSetting == UNShowPreviewsSettingWhenAuthenticated) {
671
+ showPreviews = @2;
672
+ }
673
+ }
674
+
675
+ if (@available(iOS 13.0, *)) {
676
+ iosDictionary[@"announcement"] =
677
+ [NotifeeCoreUtil numberForUNNotificationSetting:settings.announcementSetting];
678
+ } else {
679
+ iosDictionary[@"announcement"] = @-1;
680
+ }
681
+
682
+ if (@available(iOS 12.0, *)) {
683
+ iosDictionary[@"criticalAlert"] =
684
+ [NotifeeCoreUtil numberForUNNotificationSetting:settings.criticalAlertSetting];
685
+ } else {
686
+ iosDictionary[@"criticalAlert"] = @-1;
687
+ }
688
+
689
+ if (@available(iOS 12.0, *)) {
690
+ iosDictionary[@"inAppNotificationSettings"] =
691
+ settings.providesAppNotificationSettings ? @1 : @0;
692
+ } else {
693
+ iosDictionary[@"inAppNotificationSettings"] = @-1;
694
+ }
695
+
696
+ iosDictionary[@"showPreviews"] = showPreviews;
697
+ iosDictionary[@"authorizationStatus"] = authorizationStatus;
698
+ iosDictionary[@"alert"] =
699
+ [NotifeeCoreUtil numberForUNNotificationSetting:settings.alertSetting];
700
+ iosDictionary[@"badge"] =
701
+ [NotifeeCoreUtil numberForUNNotificationSetting:settings.badgeSetting];
702
+ iosDictionary[@"sound"] =
703
+ [NotifeeCoreUtil numberForUNNotificationSetting:settings.soundSetting];
704
+ iosDictionary[@"carPlay"] =
705
+ [NotifeeCoreUtil numberForUNNotificationSetting:settings.carPlaySetting];
706
+ iosDictionary[@"lockScreen"] =
707
+ [NotifeeCoreUtil numberForUNNotificationSetting:settings.lockScreenSetting];
708
+ iosDictionary[@"notificationCenter"] =
709
+ [NotifeeCoreUtil numberForUNNotificationSetting:settings.notificationCenterSetting];
710
+
711
+ settingsDictionary[@"authorizationStatus"] = authorizationStatus;
712
+ settingsDictionary[@"ios"] = iosDictionary;
713
+
714
+ block(nil, settingsDictionary);
715
+ }];
716
+ }
717
+
718
+ + (void)getInitialNotification:(notifeeMethodNSDictionaryBlock)block {
719
+ block(nil, [[NotifeeCoreUNUserNotificationCenter instance] getInitialNotification]);
720
+ }
721
+
722
+ + (void)setBadgeCount:(NSInteger)count withBlock:(notifeeMethodVoidBlock)block {
723
+ if (![NotifeeCoreUtil isAppExtension]) {
724
+ // If count is 0, set to -1 instead to avoid notifications in tray being cleared
725
+ NSInteger newCount = count == 0 ? -1 : count;
726
+ UIApplication *application = (UIApplication *)[NotifeeCoreUtil notifeeUIApplication];
727
+ [application setApplicationIconBadgeNumber:newCount];
728
+ }
729
+ block(nil);
730
+ }
731
+
732
+ + (void)getBadgeCount:(notifeeMethodNSIntegerBlock)block {
733
+ if (![NotifeeCoreUtil isAppExtension]) {
734
+ UIApplication *application = (UIApplication *)[NotifeeCoreUtil notifeeUIApplication];
735
+ NSInteger badgeCount = application.applicationIconBadgeNumber;
736
+
737
+ block(nil, badgeCount == -1 ? 0 : badgeCount);
738
+ }
739
+ }
740
+
741
+ + (void)incrementBadgeCount:(NSInteger)incrementBy withBlock:(notifeeMethodVoidBlock)block {
742
+ if (![NotifeeCoreUtil isAppExtension]) {
743
+ UIApplication *application = (UIApplication *)[NotifeeCoreUtil notifeeUIApplication];
744
+ NSInteger currentCount = application.applicationIconBadgeNumber;
745
+ // If count is -1, set currentCount to 0 before incrementing
746
+ if (currentCount == -1) {
747
+ currentCount = 0;
748
+ }
749
+
750
+ NSInteger newCount = currentCount + incrementBy;
751
+
752
+ [application setApplicationIconBadgeNumber:newCount];
753
+ block(nil);
754
+ }
755
+ }
756
+
757
+ + (void)decrementBadgeCount:(NSInteger)decrementBy withBlock:(notifeeMethodVoidBlock)block {
758
+ if (![NotifeeCoreUtil isAppExtension]) {
759
+ UIApplication *application = (UIApplication *)[NotifeeCoreUtil notifeeUIApplication];
760
+ NSInteger currentCount = application.applicationIconBadgeNumber;
761
+ NSInteger newCount = currentCount - decrementBy;
762
+ // If count is 0 or less, set to -1 instead to avoid notifications in tray being cleared
763
+ if (newCount < 1) {
764
+ newCount = -1;
765
+ }
766
+ [application setApplicationIconBadgeNumber:newCount];
767
+ }
768
+
769
+ block(nil);
770
+ }
771
+
772
+ + (nullable instancetype)notifeeUIApplication {
773
+ return (NotifeeCore *)[NotifeeCoreUtil notifeeUIApplication];
774
+ };
775
+
776
+ + (void)populateNotificationContent:(UNNotificationRequest *)request
777
+ withContent:(UNMutableNotificationContent *)content
778
+ withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler {
779
+ return [[NotifeeCoreExtensionHelper instance] populateNotificationContent:request
780
+ withContent:content
781
+ withContentHandler:contentHandler];
782
+ };
783
+
784
+ @end