@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,72 @@
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
+ #import "NotifeeCore+NSNotificationCenter.h"
20
+ #import "NotifeeCore+UNUserNotificationCenter.h"
21
+
22
+ @implementation NotifeeCoreNSNotificationCenter
23
+
24
+ + (instancetype)instance {
25
+ static dispatch_once_t once;
26
+ __strong static NotifeeCoreNSNotificationCenter *sharedInstance;
27
+ dispatch_once(&once, ^{
28
+ sharedInstance = [[NotifeeCoreNSNotificationCenter alloc] init];
29
+ });
30
+ return sharedInstance;
31
+ }
32
+
33
+ - (void)observe {
34
+ static dispatch_once_t once;
35
+ __weak NotifeeCoreNSNotificationCenter *weakSelf = self;
36
+ dispatch_once(&once, ^{
37
+ NotifeeCoreNSNotificationCenter *strongSelf = weakSelf;
38
+ // Application
39
+ // ObjC -> Initialize other delegates & observers
40
+ [[NSNotificationCenter defaultCenter]
41
+ addObserver:strongSelf
42
+ selector:@selector(application_onDidFinishLaunchingNotification:)
43
+ name:UIApplicationDidFinishLaunchingNotification
44
+ object:nil];
45
+ [[NSNotificationCenter defaultCenter]
46
+ addObserver:strongSelf
47
+ selector:@selector(messaging_didReceiveRemoteNotification:)
48
+ name:@"RNFBMessagingDidReceiveRemoteNotification"
49
+ object:nil];
50
+ });
51
+ }
52
+
53
+ // start observing immediately on class load - specifically for
54
+ // UIApplicationDidFinishLaunchingNotification
55
+ + (void)load {
56
+ [[self instance] observe];
57
+ }
58
+
59
+ #pragma mark -
60
+ #pragma mark Application Notifications
61
+
62
+ - (void)application_onDidFinishLaunchingNotification:(nonnull NSNotification *)notification {
63
+ // setup our delegates after app finishes launching
64
+ // these methods are idempotent so can safely be called multiple times
65
+ [[NotifeeCoreUNUserNotificationCenter instance] observe];
66
+ }
67
+
68
+ - (void)messaging_didReceiveRemoteNotification:(nonnull NSNotification *)notification {
69
+ // update me with logic
70
+ }
71
+
72
+ @end
@@ -0,0 +1,25 @@
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 <Foundation/Foundation.h>
19
+
20
+ NS_ASSUME_NONNULL_BEGIN
21
+ @interface NotifeeCoreNSURLSession : NSObject
22
+ + (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError **)error;
23
+ @end
24
+
25
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,55 @@
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 "NotifeeCore+NSURLSession.h"
19
+ #import "NotifeeCoreDownloadDelegate.h"
20
+
21
+ @implementation NotifeeCoreNSURLSession
22
+
23
+ + (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError **)error {
24
+ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
25
+
26
+ NotifeeCoreDownloadDelegate *delegate =
27
+ [[NotifeeCoreDownloadDelegate alloc] initWithFilePath:localPath];
28
+
29
+ // The session is created with the defaultSessionConfiguration
30
+ // default timeoutIntervalForRequest is 60 seconds.
31
+ NSURLSession *session =
32
+ [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
33
+ delegate:delegate
34
+ delegateQueue:nil];
35
+
36
+ NSURLSessionDataTask *task = [session dataTaskWithRequest:request];
37
+
38
+ [task resume];
39
+
40
+ [session finishTasksAndInvalidate];
41
+
42
+ while (![delegate isDone]) {
43
+ [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
44
+ }
45
+
46
+ NSError *delegateError = [delegate error];
47
+ if (delegateError != nil) {
48
+ if (error) *error = delegateError;
49
+ return nil;
50
+ }
51
+
52
+ return delegate.response.suggestedFilename;
53
+ }
54
+
55
+ @end
@@ -0,0 +1,37 @@
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 <Foundation/Foundation.h>
19
+ #import <UserNotifications/UserNotifications.h>
20
+
21
+ NS_ASSUME_NONNULL_BEGIN
22
+
23
+ @interface NotifeeCoreUNUserNotificationCenter : NSObject <UNUserNotificationCenterDelegate>
24
+
25
+ @property(nonatomic, nullable, weak) id<UNUserNotificationCenterDelegate> originalDelegate;
26
+
27
+ @property(strong, nullable) NSDictionary *initialNotification;
28
+
29
+ + (_Nonnull instancetype)instance;
30
+
31
+ - (void)observe;
32
+
33
+ - (nullable NSDictionary *)getInitialNotification;
34
+
35
+ @end
36
+
37
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,242 @@
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 "NotifeeCore+UNUserNotificationCenter.h"
19
+
20
+ #import "NotifeeCoreDelegateHolder.h"
21
+ #import "NotifeeCoreUtil.h"
22
+
23
+ @implementation NotifeeCoreUNUserNotificationCenter
24
+ struct {
25
+ unsigned int willPresentNotification : 1;
26
+ unsigned int didReceiveNotificationResponse : 1;
27
+ unsigned int openSettingsForNotification : 1;
28
+ } originalUNCDelegateRespondsTo;
29
+
30
+ + (instancetype)instance {
31
+ static dispatch_once_t once;
32
+ __strong static NotifeeCoreUNUserNotificationCenter *sharedInstance;
33
+ dispatch_once(&once, ^{
34
+ sharedInstance = [[NotifeeCoreUNUserNotificationCenter alloc] init];
35
+ sharedInstance.initialNotification = nil;
36
+ });
37
+ return sharedInstance;
38
+ }
39
+
40
+ - (void)observe {
41
+ static dispatch_once_t once;
42
+ __weak NotifeeCoreUNUserNotificationCenter *weakSelf = self;
43
+ dispatch_once(&once, ^{
44
+ NotifeeCoreUNUserNotificationCenter *strongSelf = weakSelf;
45
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
46
+ if (center.delegate != nil) {
47
+ _originalDelegate = center.delegate;
48
+ originalUNCDelegateRespondsTo.openSettingsForNotification = (unsigned int)[_originalDelegate
49
+ respondsToSelector:@selector(userNotificationCenter:openSettingsForNotification:)];
50
+ originalUNCDelegateRespondsTo.willPresentNotification = (unsigned int)[_originalDelegate
51
+ respondsToSelector:@selector(userNotificationCenter:
52
+ willPresentNotification:withCompletionHandler:)];
53
+ originalUNCDelegateRespondsTo.didReceiveNotificationResponse =
54
+ (unsigned int)[_originalDelegate
55
+ respondsToSelector:@selector(userNotificationCenter:
56
+ didReceiveNotificationResponse:withCompletionHandler:)];
57
+ }
58
+ center.delegate = strongSelf;
59
+ });
60
+ }
61
+
62
+ - (nullable NSDictionary *)getInitialNotification {
63
+ if (_initialNotification != nil) {
64
+ NSDictionary *initialNotificationCopy = [_initialNotification copy];
65
+ _initialNotification = nil;
66
+ return initialNotificationCopy;
67
+ }
68
+
69
+ return nil;
70
+ }
71
+
72
+ #pragma mark - UNUserNotificationCenter Delegate Methods
73
+
74
+ // The method will be called on the delegate only if the application is in the
75
+ // foreground. If the the handler is not called in a timely manner then the
76
+ // notification will not be presented. The application can choose to have the
77
+ // notification presented as a sound, badge, alert and/or in the notification
78
+ // list. This decision should be based on whether the information in the
79
+ // notification is otherwise visible to the user.
80
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
81
+ willPresentNotification:(UNNotification *)notification
82
+ withCompletionHandler:
83
+ (void (^)(UNNotificationPresentationOptions options))completionHandler {
84
+ NSDictionary *notifeeNotification =
85
+ notification.request.content.userInfo[kNotifeeUserInfoNotification];
86
+
87
+ // we only care about notifications created through notifee
88
+ if (notifeeNotification != nil) {
89
+ UNNotificationPresentationOptions presentationOptions = UNNotificationPresentationOptionNone;
90
+ NSDictionary *foregroundPresentationOptions =
91
+ notifeeNotification[@"ios"][@"foregroundPresentationOptions"];
92
+
93
+ BOOL alert = [foregroundPresentationOptions[@"alert"] boolValue];
94
+ BOOL badge = [foregroundPresentationOptions[@"badge"] boolValue];
95
+ BOOL sound = [foregroundPresentationOptions[@"sound"] boolValue];
96
+ BOOL banner = [foregroundPresentationOptions[@"banner"] boolValue];
97
+ BOOL list = [foregroundPresentationOptions[@"list"] boolValue];
98
+
99
+ if (badge) {
100
+ presentationOptions |= UNNotificationPresentationOptionBadge;
101
+ }
102
+
103
+ if (sound) {
104
+ presentationOptions |= UNNotificationPresentationOptionSound;
105
+ }
106
+
107
+ // if list or banner is true, ignore alert property
108
+ if (banner || list) {
109
+ if (banner) {
110
+ if (@available(iOS 14, *)) {
111
+ presentationOptions |= UNNotificationPresentationOptionBanner;
112
+ } else {
113
+ // for iOS 13 we need to set alert
114
+ presentationOptions |= UNNotificationPresentationOptionAlert;
115
+ }
116
+ }
117
+
118
+ if (list) {
119
+ if (@available(iOS 14, *)) {
120
+ presentationOptions |= UNNotificationPresentationOptionList;
121
+ } else {
122
+ // for iOS 13 we need to set alert
123
+ presentationOptions |= UNNotificationPresentationOptionAlert;
124
+ }
125
+ }
126
+ } else if (alert) {
127
+ // TODO: remove alert once it has been fully removed from the notifee API
128
+ presentationOptions |= UNNotificationPresentationOptionAlert;
129
+ }
130
+
131
+ NSDictionary *notifeeTrigger = notification.request.content.userInfo[kNotifeeUserInfoTrigger];
132
+ if (notifeeTrigger != nil) {
133
+ // post DELIVERED event
134
+ [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:@{
135
+ @"type" : @(NotifeeCoreEventTypeDelivered),
136
+ @"detail" : @{
137
+ @"notification" : notifeeNotification,
138
+ }
139
+ }];
140
+ }
141
+
142
+ completionHandler(presentationOptions);
143
+
144
+ } else if (_originalDelegate != nil && originalUNCDelegateRespondsTo.willPresentNotification) {
145
+ [_originalDelegate userNotificationCenter:center
146
+ willPresentNotification:notification
147
+ withCompletionHandler:completionHandler];
148
+ }
149
+ }
150
+
151
+ // The method will be called when the user responded to the notification by
152
+ // opening the application, dismissing the notification or choosing a
153
+ // UNNotificationAction. The delegate must be set before the application returns
154
+ // from application:didFinishLaunchingWithOptions:.
155
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
156
+ didReceiveNotificationResponse:(UNNotificationResponse *)response
157
+ withCompletionHandler:(void (^)(void))completionHandler {
158
+ NSDictionary *notifeeNotification =
159
+ response.notification.request.content.userInfo[kNotifeeUserInfoNotification];
160
+
161
+ // handle notification outside of notifee
162
+ if (notifeeNotification == nil) {
163
+ notifeeNotification =
164
+ [NotifeeCoreUtil parseUNNotificationRequest:response.notification.request];
165
+ }
166
+
167
+ if (notifeeNotification != nil) {
168
+ if ([response.actionIdentifier isEqualToString:UNNotificationDismissActionIdentifier]) {
169
+ // post DISMISSED event, only triggers if notification has a categoryId
170
+ [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:@{
171
+ @"type" : @(NotifeeCoreEventTypeDismissed),
172
+ @"detail" : @{
173
+ @"notification" : notifeeNotification,
174
+ }
175
+ }];
176
+ return;
177
+ }
178
+
179
+ NSNumber *eventType;
180
+ NSMutableDictionary *event = [NSMutableDictionary dictionary];
181
+ NSMutableDictionary *eventDetail = [NSMutableDictionary dictionary];
182
+ NSMutableDictionary *eventDetailPressAction = [NSMutableDictionary dictionary];
183
+
184
+ if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
185
+ eventType = @1; // PRESS
186
+ // event.detail.pressAction.id
187
+ eventDetailPressAction[@"id"] = @"default";
188
+ } else {
189
+ eventType = @2; // ACTION_PRESS
190
+ // event.detail.pressAction.id
191
+ eventDetailPressAction[@"id"] = response.actionIdentifier;
192
+ }
193
+
194
+ if ([response isKindOfClass:UNTextInputNotificationResponse.class]) {
195
+ // event.detail.input
196
+ eventDetail[@"input"] = [(UNTextInputNotificationResponse *)response userText];
197
+ }
198
+
199
+ // event.type
200
+ event[@"type"] = eventType;
201
+
202
+ // event.detail.notification
203
+ eventDetail[@"notification"] = notifeeNotification;
204
+
205
+ // event.detail.pressAction
206
+ eventDetail[@"pressAction"] = eventDetailPressAction;
207
+
208
+ // event.detail
209
+ event[@"detail"] = eventDetail;
210
+
211
+ // store notification for getInitialNotification
212
+ _initialNotification = [eventDetail copy];
213
+
214
+ // post PRESS/ACTION_PRESS event
215
+ [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:event];
216
+
217
+ // TODO figure out if this is needed or if we can just complete immediately
218
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(15 * NSEC_PER_SEC)),
219
+ dispatch_get_main_queue(), ^{
220
+ completionHandler();
221
+ });
222
+
223
+ } else if (_originalDelegate != nil &&
224
+ originalUNCDelegateRespondsTo.didReceiveNotificationResponse) {
225
+ [_originalDelegate userNotificationCenter:center
226
+ didReceiveNotificationResponse:response
227
+ withCompletionHandler:completionHandler];
228
+ }
229
+ }
230
+
231
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
232
+ openSettingsForNotification:(nullable UNNotification *)notification {
233
+ if (_originalDelegate != nil && originalUNCDelegateRespondsTo.openSettingsForNotification) {
234
+ if (@available(iOS 12.0, macOS 10.14, macCatalyst 13.0, *)) {
235
+ [_originalDelegate userNotificationCenter:center openSettingsForNotification:notification];
236
+ } else {
237
+ // Fallback on earlier versions
238
+ }
239
+ }
240
+ }
241
+
242
+ @end
@@ -0,0 +1,118 @@
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 <Foundation/Foundation.h>
19
+ //! Project version number for NotifeeCore.
20
+ FOUNDATION_EXPORT double NotifeeCoreVersionNumber;
21
+ #import <UserNotifications/UserNotifications.h>
22
+
23
+ //! Project version string for NotifeeCore.
24
+ FOUNDATION_EXPORT const unsigned char NotifeeCoreVersionString[];
25
+
26
+ // Import all the public headers of your framework using statements like #import
27
+ // <NotifeeCore/PublicHeader.h> #import <NotifeeCore/Example.h> END public
28
+ // headers import
29
+
30
+ NS_ASSUME_NONNULL_BEGIN
31
+
32
+ typedef void (^notifeeMethodVoidBlock)(NSError *_Nullable);
33
+
34
+ typedef void (^notifeeMethodNSDictionaryBlock)(NSError *_Nullable, NSDictionary *_Nullable);
35
+
36
+ typedef void (^notifeeMethodNSArrayBlock)(NSError *_Nullable, NSArray *_Nullable);
37
+
38
+ typedef void (^notifeeMethodBooleanBlock)(NSError *_Nullable, BOOL);
39
+
40
+ typedef void (^notifeeMethodNSIntegerBlock)(NSError *_Nullable, NSInteger);
41
+
42
+ typedef NS_ENUM(NSInteger, NotifeeCoreNotificationType) {
43
+ NotifeeCoreNotificationTypeAll = 0,
44
+ NotifeeCoreNotificationTypeDisplayed = 1,
45
+ NotifeeCoreNotificationTypeTrigger = 2
46
+ };
47
+
48
+ typedef NS_ENUM(NSInteger, NotifeeCoreEventType) {
49
+ NotifeeCoreEventTypeDismissed = 0,
50
+ NotifeeCoreEventTypeDelivered = 3,
51
+ NotifeeCoreEventTypeTriggerNotificationCreated = 7,
52
+ };
53
+
54
+ @class NotifeeCore;
55
+
56
+ @protocol NotifeeCoreDelegate <NSObject>
57
+ @optional
58
+ - (void)didReceiveNotifeeCoreEvent:(NSDictionary *_Nonnull)event;
59
+ @end
60
+
61
+ @interface NotifeeCore : NSObject
62
+
63
+ + (void)setCoreDelegate:(id<NotifeeCoreDelegate>)coreDelegate;
64
+
65
+ + (void)cancelNotification:(NSString *)notificationId
66
+ withNotificationType:(NSInteger)notificationType
67
+ withBlock:(notifeeMethodVoidBlock)block;
68
+
69
+ + (void)cancelAllNotifications:(NSInteger)notificationType withBlock:(notifeeMethodVoidBlock)block;
70
+
71
+ + (void)cancelAllNotificationsWithIds:(NSInteger)notificationType
72
+ withIds:(NSArray<NSString *> *)ids
73
+ withBlock:(notifeeMethodVoidBlock)block;
74
+
75
+ + (void)displayNotification:(NSDictionary *)notification withBlock:(notifeeMethodVoidBlock)block;
76
+
77
+ + (void)createTriggerNotification:(NSDictionary *)notification
78
+ withTrigger:(NSDictionary *)trigger
79
+ withBlock:(notifeeMethodVoidBlock)block;
80
+
81
+ + (void)getTriggerNotificationIds:(notifeeMethodNSArrayBlock)block;
82
+
83
+ + (void)getDisplayedNotifications:(notifeeMethodNSArrayBlock)block;
84
+
85
+ + (void)getTriggerNotifications:(notifeeMethodNSArrayBlock)block;
86
+
87
+ + (void)requestPermission:(NSDictionary *)permissions
88
+ withBlock:(notifeeMethodNSDictionaryBlock)block;
89
+
90
+ + (void)getNotificationCategories:(notifeeMethodNSArrayBlock)block;
91
+
92
+ + (void)setNotificationCategories:(NSArray<NSDictionary *> *)categories
93
+ withBlock:(notifeeMethodVoidBlock)block;
94
+
95
+ + (void)getNotificationSettings:(notifeeMethodNSDictionaryBlock)block;
96
+
97
+ + (void)getInitialNotification:(notifeeMethodNSDictionaryBlock)block;
98
+
99
+ + (void)setBadgeCount:(NSInteger)count withBlock:(notifeeMethodVoidBlock)block;
100
+
101
+ + (void)getBadgeCount:(notifeeMethodNSIntegerBlock)block;
102
+
103
+ + (void)incrementBadgeCount:(NSInteger)incrementBy withBlock:(notifeeMethodVoidBlock)block;
104
+
105
+ + (void)decrementBadgeCount:(NSInteger)decrementBy withBlock:(notifeeMethodVoidBlock)block;
106
+
107
+ + (nullable instancetype)notifeeUIApplication;
108
+
109
+ + (UNMutableNotificationContent *)buildNotificationContent:(NSDictionary *)notification
110
+ withTrigger:(NSDictionary *_Nullable)trigger;
111
+
112
+ + (void)populateNotificationContent:(UNNotificationRequest *_Nullable)request
113
+ withContent:(UNMutableNotificationContent *)content
114
+ withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler;
115
+
116
+ @end
117
+
118
+ NS_ASSUME_NONNULL_END