@psync/notifee 9.2.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 (193) hide show
  1. package/LICENSE +44 -0
  2. package/README.md +142 -0
  3. package/RNNotifee.podspec +39 -0
  4. package/RNNotifeeCore.podspec +33 -0
  5. package/android/.editorconfig +10 -0
  6. package/android/build.gradle +116 -0
  7. package/android/gradle.properties +1 -0
  8. package/android/lint.xml +5 -0
  9. package/android/proguard-rules.pro +82 -0
  10. package/android/settings.gradle +1 -0
  11. package/android/src/main/AndroidManifest.xml +12 -0
  12. package/android/src/main/java/io/invertase/notifee/HeadlessTask.java +431 -0
  13. package/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +365 -0
  14. package/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java +118 -0
  15. package/android/src/main/java/io/invertase/notifee/NotifeeInitProvider.java +55 -0
  16. package/android/src/main/java/io/invertase/notifee/NotifeePackage.java +30 -0
  17. package/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java +135 -0
  18. package/dist/NotifeeApiModule.d.ts +53 -0
  19. package/dist/NotifeeApiModule.js +609 -0
  20. package/dist/NotifeeApiModule.js.map +1 -0
  21. package/dist/NotifeeJSEventEmitter.d.ts +3 -0
  22. package/dist/NotifeeJSEventEmitter.js +14 -0
  23. package/dist/NotifeeJSEventEmitter.js.map +1 -0
  24. package/dist/NotifeeNativeError.d.ts +15 -0
  25. package/dist/NotifeeNativeError.js +59 -0
  26. package/dist/NotifeeNativeError.js.map +1 -0
  27. package/dist/NotifeeNativeModule.d.ts +14 -0
  28. package/dist/NotifeeNativeModule.js +42 -0
  29. package/dist/NotifeeNativeModule.js.map +1 -0
  30. package/dist/NotifeeNativeModule.web.d.ts +12 -0
  31. package/dist/NotifeeNativeModule.web.js +18 -0
  32. package/dist/NotifeeNativeModule.web.js.map +1 -0
  33. package/dist/index.d.ts +8 -0
  34. package/dist/index.js +43 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/types/Library.d.ts +21 -0
  37. package/dist/types/Library.js +6 -0
  38. package/dist/types/Library.js.map +1 -0
  39. package/dist/types/Module.d.ts +576 -0
  40. package/dist/types/Module.js +6 -0
  41. package/dist/types/Module.js.map +1 -0
  42. package/dist/types/Notification.d.ts +462 -0
  43. package/dist/types/Notification.js +111 -0
  44. package/dist/types/Notification.js.map +1 -0
  45. package/dist/types/NotificationAndroid.d.ts +1311 -0
  46. package/dist/types/NotificationAndroid.js +409 -0
  47. package/dist/types/NotificationAndroid.js.map +1 -0
  48. package/dist/types/NotificationIOS.d.ts +539 -0
  49. package/dist/types/NotificationIOS.js +92 -0
  50. package/dist/types/NotificationIOS.js.map +1 -0
  51. package/dist/types/NotificationWeb.d.ts +5 -0
  52. package/dist/types/NotificationWeb.js +6 -0
  53. package/dist/types/NotificationWeb.js.map +1 -0
  54. package/dist/types/PowerManagerInfo.d.ts +36 -0
  55. package/dist/types/PowerManagerInfo.js +6 -0
  56. package/dist/types/PowerManagerInfo.js.map +1 -0
  57. package/dist/types/Trigger.d.ts +124 -0
  58. package/dist/types/Trigger.js +51 -0
  59. package/dist/types/Trigger.js.map +1 -0
  60. package/dist/utils/id.d.ts +1 -0
  61. package/dist/utils/id.js +15 -0
  62. package/dist/utils/id.js.map +1 -0
  63. package/dist/utils/index.d.ts +16 -0
  64. package/dist/utils/index.js +51 -0
  65. package/dist/utils/index.js.map +1 -0
  66. package/dist/utils/validate.d.ts +15 -0
  67. package/dist/utils/validate.js +90 -0
  68. package/dist/utils/validate.js.map +1 -0
  69. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.d.ts +2 -0
  70. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js +51 -0
  71. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js.map +1 -0
  72. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.d.ts +2 -0
  73. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js +27 -0
  74. package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js.map +1 -0
  75. package/dist/validators/validate.d.ts +25 -0
  76. package/dist/validators/validate.js +74 -0
  77. package/dist/validators/validate.js.map +1 -0
  78. package/dist/validators/validateAndroidAction.d.ts +2 -0
  79. package/dist/validators/validateAndroidAction.js +52 -0
  80. package/dist/validators/validateAndroidAction.js.map +1 -0
  81. package/dist/validators/validateAndroidChannel.d.ts +2 -0
  82. package/dist/validators/validateAndroidChannel.js +155 -0
  83. package/dist/validators/validateAndroidChannel.js.map +1 -0
  84. package/dist/validators/validateAndroidChannelGroup.d.ts +2 -0
  85. package/dist/validators/validateAndroidChannelGroup.js +42 -0
  86. package/dist/validators/validateAndroidChannelGroup.js.map +1 -0
  87. package/dist/validators/validateAndroidFullScreenAction.d.ts +2 -0
  88. package/dist/validators/validateAndroidFullScreenAction.js +50 -0
  89. package/dist/validators/validateAndroidFullScreenAction.js.map +1 -0
  90. package/dist/validators/validateAndroidInput.d.ts +2 -0
  91. package/dist/validators/validateAndroidInput.js +54 -0
  92. package/dist/validators/validateAndroidInput.js.map +1 -0
  93. package/dist/validators/validateAndroidNotification.d.ts +2 -0
  94. package/dist/validators/validateAndroidNotification.js +547 -0
  95. package/dist/validators/validateAndroidNotification.js.map +1 -0
  96. package/dist/validators/validateAndroidPressAction.d.ts +2 -0
  97. package/dist/validators/validateAndroidPressAction.js +50 -0
  98. package/dist/validators/validateAndroidPressAction.js.map +1 -0
  99. package/dist/validators/validateAndroidStyle.d.ts +22 -0
  100. package/dist/validators/validateAndroidStyle.js +230 -0
  101. package/dist/validators/validateAndroidStyle.js.map +1 -0
  102. package/dist/validators/validateIOSAttachment.d.ts +6 -0
  103. package/dist/validators/validateIOSAttachment.js +100 -0
  104. package/dist/validators/validateIOSAttachment.js.map +1 -0
  105. package/dist/validators/validateIOSCategory.d.ts +2 -0
  106. package/dist/validators/validateIOSCategory.js +124 -0
  107. package/dist/validators/validateIOSCategory.js.map +1 -0
  108. package/dist/validators/validateIOSCategoryAction.d.ts +2 -0
  109. package/dist/validators/validateIOSCategoryAction.js +59 -0
  110. package/dist/validators/validateIOSCategoryAction.js.map +1 -0
  111. package/dist/validators/validateIOSInput.d.ts +2 -0
  112. package/dist/validators/validateIOSInput.js +32 -0
  113. package/dist/validators/validateIOSInput.js.map +1 -0
  114. package/dist/validators/validateIOSNotification.d.ts +2 -0
  115. package/dist/validators/validateIOSNotification.js +211 -0
  116. package/dist/validators/validateIOSNotification.js.map +1 -0
  117. package/dist/validators/validateIOSPermissions.d.ts +2 -0
  118. package/dist/validators/validateIOSPermissions.js +62 -0
  119. package/dist/validators/validateIOSPermissions.js.map +1 -0
  120. package/dist/validators/validateNotification.d.ts +11 -0
  121. package/dist/validators/validateNotification.js +129 -0
  122. package/dist/validators/validateNotification.js.map +1 -0
  123. package/dist/validators/validateTrigger.d.ts +2 -0
  124. package/dist/validators/validateTrigger.js +110 -0
  125. package/dist/validators/validateTrigger.js.map +1 -0
  126. package/dist/version.d.ts +1 -0
  127. package/dist/version.js +6 -0
  128. package/dist/version.js.map +1 -0
  129. package/ios/NotifeeCore/Info.plist +22 -0
  130. package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.h +28 -0
  131. package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +76 -0
  132. package/ios/NotifeeCore/NotifeeCore+NSURLSession.h +25 -0
  133. package/ios/NotifeeCore/NotifeeCore+NSURLSession.m +55 -0
  134. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.h +44 -0
  135. package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +270 -0
  136. package/ios/NotifeeCore/NotifeeCore.h +118 -0
  137. package/ios/NotifeeCore/NotifeeCore.m +843 -0
  138. package/ios/NotifeeCore/NotifeeCoreDelegateHolder.h +34 -0
  139. package/ios/NotifeeCore/NotifeeCoreDelegateHolder.m +70 -0
  140. package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.h +39 -0
  141. package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.m +68 -0
  142. package/ios/NotifeeCore/NotifeeCoreExtensionHelper.h +38 -0
  143. package/ios/NotifeeCore/NotifeeCoreExtensionHelper.m +224 -0
  144. package/ios/NotifeeCore/NotifeeCoreUtil.h +81 -0
  145. package/ios/NotifeeCore/NotifeeCoreUtil.m +834 -0
  146. package/ios/RNNotifee/NotifeeApiModule.h +25 -0
  147. package/ios/RNNotifee/NotifeeApiModule.m +371 -0
  148. package/ios/RNNotifee/NotifeeExtensionHelper.h +37 -0
  149. package/ios/RNNotifee/NotifeeExtensionHelper.m +37 -0
  150. package/ios/RNNotifee.xcodeproj/project.pbxproj +318 -0
  151. package/ios/RNNotifee.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  152. package/ios/RNNotifee.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  153. package/jest-mock.js +161 -0
  154. package/package.json +74 -0
  155. package/react-native.config.js +11 -0
  156. package/src/NotifeeApiModule.ts +827 -0
  157. package/src/NotifeeJSEventEmitter.ts +10 -0
  158. package/src/NotifeeNativeError.ts +68 -0
  159. package/src/NotifeeNativeModule.ts +54 -0
  160. package/src/NotifeeNativeModule.web.ts +24 -0
  161. package/src/index.ts +33 -0
  162. package/src/types/Library.ts +28 -0
  163. package/src/types/Module.ts +629 -0
  164. package/src/types/Notification.ts +518 -0
  165. package/src/types/NotificationAndroid.ts +1478 -0
  166. package/src/types/NotificationIOS.ts +683 -0
  167. package/src/types/NotificationWeb.ts +5 -0
  168. package/src/types/PowerManagerInfo.ts +43 -0
  169. package/src/types/Trigger.ts +136 -0
  170. package/src/utils/id.ts +13 -0
  171. package/src/utils/index.ts +46 -0
  172. package/src/utils/validate.ts +90 -0
  173. package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfo.ts +61 -0
  174. package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.ts +33 -0
  175. package/src/validators/validate.ts +85 -0
  176. package/src/validators/validateAndroidAction.ts +54 -0
  177. package/src/validators/validateAndroidChannel.ts +188 -0
  178. package/src/validators/validateAndroidChannelGroup.ts +49 -0
  179. package/src/validators/validateAndroidFullScreenAction.ts +65 -0
  180. package/src/validators/validateAndroidInput.ts +67 -0
  181. package/src/validators/validateAndroidNotification.ts +734 -0
  182. package/src/validators/validateAndroidPressAction.ts +65 -0
  183. package/src/validators/validateAndroidStyle.ts +315 -0
  184. package/src/validators/validateIOSAttachment.ts +135 -0
  185. package/src/validators/validateIOSCategory.ts +150 -0
  186. package/src/validators/validateIOSCategoryAction.ts +65 -0
  187. package/src/validators/validateIOSInput.ts +38 -0
  188. package/src/validators/validateIOSNotification.ts +296 -0
  189. package/src/validators/validateIOSPermissions.ts +78 -0
  190. package/src/validators/validateNotification.ts +156 -0
  191. package/src/validators/validateTrigger.ts +142 -0
  192. package/src/version.ts +2 -0
  193. package/tsconfig.json +23 -0
@@ -0,0 +1,76 @@
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
+ + (void)load {
54
+ [[self instance] observe];
55
+ }
56
+
57
+ #pragma mark -
58
+ #pragma mark Application Notifications
59
+
60
+ - (void)application_onDidFinishLaunchingNotification:(nonnull NSNotification *)notification {
61
+ #pragma clang diagnostic push
62
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
63
+ UILocalNotification *launchNotification =
64
+ (UILocalNotification *)notification.userInfo[UIApplicationLaunchOptionsLocalNotificationKey];
65
+ [[NotifeeCoreUNUserNotificationCenter instance]
66
+ onDidFinishLaunchingNotification:launchNotification.userInfo];
67
+ [[NotifeeCoreUNUserNotificationCenter instance] getInitialNotification];
68
+
69
+ [[NotifeeCoreUNUserNotificationCenter instance] observe];
70
+ }
71
+
72
+ - (void)messaging_didReceiveRemoteNotification:(nonnull NSNotification *)notification {
73
+ // update me with logic
74
+ }
75
+
76
+ @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,44 @@
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
+ #import "NotifeeCore.h"
21
+
22
+ NS_ASSUME_NONNULL_BEGIN
23
+
24
+ @interface NotifeeCoreUNUserNotificationCenter : NSObject <UNUserNotificationCenterDelegate>
25
+
26
+ @property(nonatomic, nullable, weak) id<UNUserNotificationCenterDelegate> originalDelegate;
27
+
28
+ @property(strong, nullable) NSDictionary *initialNotification;
29
+ @property bool initialNotificationGathered;
30
+ @property(nullable) notifeeMethodNSDictionaryBlock initialNotificationBlock;
31
+ @property NSString *initialNoticationID;
32
+ @property NSString *notificationOpenedAppID;
33
+
34
+ + (_Nonnull instancetype)instance;
35
+
36
+ - (void)observe;
37
+
38
+ - (nullable NSDictionary *)getInitialNotification;
39
+
40
+ - (void)onDidFinishLaunchingNotification:(NSDictionary *)notification;
41
+
42
+ @end
43
+
44
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,270 @@
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
+
25
+ struct {
26
+ unsigned int willPresentNotification : 1;
27
+ unsigned int didReceiveNotificationResponse : 1;
28
+ unsigned int openSettingsForNotification : 1;
29
+ } originalUNCDelegateRespondsTo;
30
+
31
+ + (instancetype)instance {
32
+ static dispatch_once_t once;
33
+ __strong static NotifeeCoreUNUserNotificationCenter *sharedInstance;
34
+ dispatch_once(&once, ^{
35
+ sharedInstance = [[NotifeeCoreUNUserNotificationCenter alloc] init];
36
+ sharedInstance.initialNotification = nil;
37
+ sharedInstance.initialNotificationGathered = false;
38
+ sharedInstance.initialNotificationBlock = nil;
39
+ });
40
+ return sharedInstance;
41
+ }
42
+
43
+ - (void)observe {
44
+ static dispatch_once_t once;
45
+ __weak NotifeeCoreUNUserNotificationCenter *weakSelf = self;
46
+ dispatch_once(&once, ^{
47
+ NotifeeCoreUNUserNotificationCenter *strongSelf = weakSelf;
48
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
49
+ if (center.delegate != nil) {
50
+ _originalDelegate = center.delegate;
51
+ originalUNCDelegateRespondsTo.openSettingsForNotification = (unsigned int)[_originalDelegate
52
+ respondsToSelector:@selector(userNotificationCenter:openSettingsForNotification:)];
53
+ originalUNCDelegateRespondsTo.willPresentNotification = (unsigned int)[_originalDelegate
54
+ respondsToSelector:@selector(userNotificationCenter:
55
+ willPresentNotification:withCompletionHandler:)];
56
+ originalUNCDelegateRespondsTo.didReceiveNotificationResponse =
57
+ (unsigned int)[_originalDelegate
58
+ respondsToSelector:@selector(userNotificationCenter:
59
+ didReceiveNotificationResponse:withCompletionHandler:)];
60
+ }
61
+ center.delegate = strongSelf;
62
+ });
63
+ }
64
+
65
+ - (void)onDidFinishLaunchingNotification:(nonnull NSDictionary *)notifUserInfo {
66
+ if (notifUserInfo != nil) {
67
+ NSDictionary *notifeeNotification = notifUserInfo[kNotifeeUserInfoNotification];
68
+ _initialNoticationID = notifeeNotification[@"id"];
69
+ }
70
+
71
+ _initialNotificationGathered = YES;
72
+ }
73
+
74
+ - (nullable NSDictionary *)getInitialNotification {
75
+ if (_initialNotificationGathered && _initialNotificationBlock != nil) {
76
+ // copying initial notification
77
+ if (_initialNotification != nil &&
78
+ [_initialNoticationID isEqualToString:_notificationOpenedAppID]) {
79
+ NSDictionary *initialNotificationCopy = [_initialNotification copy];
80
+ _initialNotification = nil;
81
+ _initialNotificationBlock(nil, initialNotificationCopy);
82
+ } else {
83
+ _initialNotificationBlock(nil, nil);
84
+ }
85
+
86
+ _initialNotificationBlock = nil;
87
+ }
88
+
89
+ return nil;
90
+ }
91
+
92
+ #pragma mark - UNUserNotificationCenter Delegate Methods
93
+
94
+ // The method will be called on the delegate only if the application is in the
95
+ // foreground. If the the handler is not called in a timely manner then the
96
+ // notification will not be presented. The application can choose to have the
97
+ // notification presented as a sound, badge, alert and/or in the notification
98
+ // list. This decision should be based on whether the information in the
99
+ // notification is otherwise visible to the user.
100
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
101
+ willPresentNotification:(UNNotification *)notification
102
+ withCompletionHandler:
103
+ (void (^)(UNNotificationPresentationOptions options))completionHandler {
104
+ NSDictionary *notifeeNotification =
105
+ notification.request.content.userInfo[kNotifeeUserInfoNotification];
106
+
107
+ // we only care about notifications created through notifee
108
+ if (notifeeNotification != nil) {
109
+ UNNotificationPresentationOptions presentationOptions = UNNotificationPresentationOptionNone;
110
+ NSDictionary *foregroundPresentationOptions =
111
+ notifeeNotification[@"ios"][@"foregroundPresentationOptions"];
112
+
113
+ BOOL alert = [foregroundPresentationOptions[@"alert"] boolValue];
114
+ BOOL badge = [foregroundPresentationOptions[@"badge"] boolValue];
115
+ BOOL sound = [foregroundPresentationOptions[@"sound"] boolValue];
116
+ BOOL banner = [foregroundPresentationOptions[@"banner"] boolValue];
117
+ BOOL list = [foregroundPresentationOptions[@"list"] boolValue];
118
+
119
+ if (badge) {
120
+ presentationOptions |= UNNotificationPresentationOptionBadge;
121
+ }
122
+
123
+ if (sound) {
124
+ presentationOptions |= UNNotificationPresentationOptionSound;
125
+ }
126
+
127
+ // if list or banner is true, ignore alert property
128
+ if (banner || list) {
129
+ if (banner) {
130
+ if (@available(iOS 14, *)) {
131
+ presentationOptions |= UNNotificationPresentationOptionBanner;
132
+ } else {
133
+ // for iOS 13 we need to set alert
134
+ presentationOptions |= UNNotificationPresentationOptionAlert;
135
+ }
136
+ }
137
+
138
+ if (list) {
139
+ if (@available(iOS 14, *)) {
140
+ presentationOptions |= UNNotificationPresentationOptionList;
141
+ } else {
142
+ // for iOS 13 we need to set alert
143
+ presentationOptions |= UNNotificationPresentationOptionAlert;
144
+ }
145
+ }
146
+ } else if (alert) {
147
+ // TODO: remove alert once it has been fully removed from the notifee API
148
+ presentationOptions |= UNNotificationPresentationOptionAlert;
149
+ }
150
+
151
+ NSDictionary *notifeeTrigger = notification.request.content.userInfo[kNotifeeUserInfoTrigger];
152
+ if (notifeeTrigger != nil) {
153
+ // post DELIVERED event
154
+ [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:@{
155
+ @"type" : @(NotifeeCoreEventTypeDelivered),
156
+ @"detail" : @{
157
+ @"notification" : notifeeNotification,
158
+ }
159
+ }];
160
+ }
161
+
162
+ completionHandler(presentationOptions);
163
+
164
+ } else if (_originalDelegate != nil && originalUNCDelegateRespondsTo.willPresentNotification) {
165
+ [_originalDelegate userNotificationCenter:center
166
+ willPresentNotification:notification
167
+ withCompletionHandler:completionHandler];
168
+ }
169
+ }
170
+
171
+ // The method will be called when the user responded to the notification by
172
+ // opening the application, dismissing the notification or choosing a
173
+ // UNNotificationAction. The delegate must be set before the application returns
174
+ // from application:didFinishLaunchingWithOptions:.
175
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
176
+ didReceiveNotificationResponse:(UNNotificationResponse *)response
177
+ withCompletionHandler:(void (^)(void))completionHandler {
178
+ NSDictionary *notifeeNotification =
179
+ response.notification.request.content.userInfo[kNotifeeUserInfoNotification];
180
+
181
+ _notificationOpenedAppID = notifeeNotification[@"id"];
182
+
183
+ // handle notification outside of notifee
184
+ if (notifeeNotification == nil) {
185
+ if (_originalDelegate != nil && originalUNCDelegateRespondsTo.didReceiveNotificationResponse) {
186
+ [_originalDelegate userNotificationCenter:center
187
+ didReceiveNotificationResponse:response
188
+ withCompletionHandler:completionHandler];
189
+ } else {
190
+ notifeeNotification =
191
+ [NotifeeCoreUtil parseUNNotificationRequest:response.notification.request];
192
+ }
193
+ }
194
+
195
+ if (notifeeNotification != nil) {
196
+ if ([response.actionIdentifier isEqualToString:UNNotificationDismissActionIdentifier]) {
197
+ // post DISMISSED event, only triggers if notification has a categoryId
198
+ [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:@{
199
+ @"type" : @(NotifeeCoreEventTypeDismissed),
200
+ @"detail" : @{
201
+ @"notification" : notifeeNotification,
202
+ }
203
+ }];
204
+ return;
205
+ }
206
+
207
+ NSNumber *eventType;
208
+ NSMutableDictionary *event = [NSMutableDictionary dictionary];
209
+ NSMutableDictionary *eventDetail = [NSMutableDictionary dictionary];
210
+ NSMutableDictionary *eventDetailPressAction = [NSMutableDictionary dictionary];
211
+
212
+ if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
213
+ eventType = @1; // PRESS
214
+ // event.detail.pressAction.id
215
+ eventDetailPressAction[@"id"] = @"default";
216
+ } else {
217
+ eventType = @2; // ACTION_PRESS
218
+ // event.detail.pressAction.id
219
+ eventDetailPressAction[@"id"] = response.actionIdentifier;
220
+ }
221
+
222
+ if ([response isKindOfClass:UNTextInputNotificationResponse.class]) {
223
+ // event.detail.input
224
+ eventDetail[@"input"] = [(UNTextInputNotificationResponse *)response userText];
225
+ }
226
+
227
+ // event.type
228
+ event[@"type"] = eventType;
229
+
230
+ // event.detail.notification
231
+ eventDetail[@"notification"] = notifeeNotification;
232
+
233
+ // event.detail.pressAction
234
+ eventDetail[@"pressAction"] = eventDetailPressAction;
235
+
236
+ // event.detail
237
+ event[@"detail"] = eventDetail;
238
+
239
+ // store notification for getInitialNotification
240
+ _initialNotification = [eventDetail copy];
241
+
242
+ // post PRESS/ACTION_PRESS event
243
+ // Set is initial notification to true
244
+ if (_notificationOpenedAppID != nil &&
245
+ [_initialNoticationID isEqualToString:_notificationOpenedAppID]) {
246
+ eventDetail[@"initialNotification"] = @1;
247
+ }
248
+
249
+ [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:event];
250
+
251
+ // TODO figure out if this is needed or if we can just complete immediately
252
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(15 * NSEC_PER_SEC)),
253
+ dispatch_get_main_queue(), ^{
254
+ completionHandler();
255
+ });
256
+ }
257
+ }
258
+
259
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
260
+ openSettingsForNotification:(nullable UNNotification *)notification {
261
+ if (_originalDelegate != nil && originalUNCDelegateRespondsTo.openSettingsForNotification) {
262
+ if (@available(iOS 12.0, macOS 10.14, macCatalyst 13.0, *)) {
263
+ [_originalDelegate userNotificationCenter:center openSettingsForNotification:notification];
264
+ } else {
265
+ // Fallback on earlier versions
266
+ }
267
+ }
268
+ }
269
+
270
+ @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