@ammarahmed/notifee-react-native 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +3 -0
- package/LICENSE +44 -0
- package/README.md +131 -0
- package/RNNotifee.podspec +39 -0
- package/RNNotifeeCore.podspec +33 -0
- package/android/build.gradle +116 -0
- package/android/gradle.properties +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar +0 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.md5 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha1 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha256 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha512 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom +9 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.md5 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha1 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha256 +1 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha512 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml +13 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.md5 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +1 -0
- package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +1 -0
- package/android/lint.xml +5 -0
- package/android/proguard-rules.pro +74 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +349 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java +118 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeInitProvider.java +55 -0
- package/android/src/main/java/io/invertase/notifee/NotifeePackage.java +30 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java +244 -0
- package/app.plugin.js +1 -0
- package/dist/NotifeeApiModule.d.ts +53 -0
- package/dist/NotifeeApiModule.js +607 -0
- package/dist/NotifeeApiModule.js.map +1 -0
- package/dist/NotifeeJSEventEmitter.d.ts +3 -0
- package/dist/NotifeeJSEventEmitter.js +14 -0
- package/dist/NotifeeJSEventEmitter.js.map +1 -0
- package/dist/NotifeeNativeError.d.ts +15 -0
- package/dist/NotifeeNativeError.js +61 -0
- package/dist/NotifeeNativeError.js.map +1 -0
- package/dist/NotifeeNativeModule.d.ts +14 -0
- package/dist/NotifeeNativeModule.js +43 -0
- package/dist/NotifeeNativeModule.js.map +1 -0
- package/dist/NotifeeNativeModule.web.d.ts +12 -0
- package/dist/NotifeeNativeModule.web.js +19 -0
- package/dist/NotifeeNativeModule.web.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/types/Library.d.ts +21 -0
- package/dist/types/Library.js +6 -0
- package/dist/types/Library.js.map +1 -0
- package/dist/types/Module.d.ts +572 -0
- package/dist/types/Module.js +6 -0
- package/dist/types/Module.js.map +1 -0
- package/dist/types/Notification.d.ts +450 -0
- package/dist/types/Notification.js +105 -0
- package/dist/types/Notification.js.map +1 -0
- package/dist/types/NotificationAndroid.d.ts +1276 -0
- package/dist/types/NotificationAndroid.js +380 -0
- package/dist/types/NotificationAndroid.js.map +1 -0
- package/dist/types/NotificationIOS.d.ts +537 -0
- package/dist/types/NotificationIOS.js +92 -0
- package/dist/types/NotificationIOS.js.map +1 -0
- package/dist/types/NotificationWeb.d.ts +5 -0
- package/dist/types/NotificationWeb.js +3 -0
- package/dist/types/NotificationWeb.js.map +1 -0
- package/dist/types/PowerManagerInfo.d.ts +36 -0
- package/dist/types/PowerManagerInfo.js +6 -0
- package/dist/types/PowerManagerInfo.js.map +1 -0
- package/dist/types/Trigger.d.ts +108 -0
- package/dist/types/Trigger.js +39 -0
- package/dist/types/Trigger.js.map +1 -0
- package/dist/utils/id.d.ts +1 -0
- package/dist/utils/id.js +16 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +16 -0
- package/dist/utils/index.js +52 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/validate.d.ts +15 -0
- package/dist/utils/validate.js +93 -0
- package/dist/utils/validate.js.map +1 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.d.ts +2 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js +39 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js.map +1 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.d.ts +2 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js +27 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js.map +1 -0
- package/dist/validators/validate.d.ts +25 -0
- package/dist/validators/validate.js +75 -0
- package/dist/validators/validate.js.map +1 -0
- package/dist/validators/validateAndroidAction.d.ts +2 -0
- package/dist/validators/validateAndroidAction.js +52 -0
- package/dist/validators/validateAndroidAction.js.map +1 -0
- package/dist/validators/validateAndroidChannel.d.ts +2 -0
- package/dist/validators/validateAndroidChannel.js +155 -0
- package/dist/validators/validateAndroidChannel.js.map +1 -0
- package/dist/validators/validateAndroidChannelGroup.d.ts +2 -0
- package/dist/validators/validateAndroidChannelGroup.js +42 -0
- package/dist/validators/validateAndroidChannelGroup.js.map +1 -0
- package/dist/validators/validateAndroidFullScreenAction.d.ts +2 -0
- package/dist/validators/validateAndroidFullScreenAction.js +50 -0
- package/dist/validators/validateAndroidFullScreenAction.js.map +1 -0
- package/dist/validators/validateAndroidInput.d.ts +2 -0
- package/dist/validators/validateAndroidInput.js +54 -0
- package/dist/validators/validateAndroidInput.js.map +1 -0
- package/dist/validators/validateAndroidNotification.d.ts +2 -0
- package/dist/validators/validateAndroidNotification.js +529 -0
- package/dist/validators/validateAndroidNotification.js.map +1 -0
- package/dist/validators/validateAndroidPressAction.d.ts +2 -0
- package/dist/validators/validateAndroidPressAction.js +50 -0
- package/dist/validators/validateAndroidPressAction.js.map +1 -0
- package/dist/validators/validateAndroidStyle.d.ts +22 -0
- package/dist/validators/validateAndroidStyle.js +231 -0
- package/dist/validators/validateAndroidStyle.js.map +1 -0
- package/dist/validators/validateIOSAttachment.d.ts +6 -0
- package/dist/validators/validateIOSAttachment.js +102 -0
- package/dist/validators/validateIOSAttachment.js.map +1 -0
- package/dist/validators/validateIOSCategory.d.ts +2 -0
- package/dist/validators/validateIOSCategory.js +124 -0
- package/dist/validators/validateIOSCategory.js.map +1 -0
- package/dist/validators/validateIOSCategoryAction.d.ts +2 -0
- package/dist/validators/validateIOSCategoryAction.js +59 -0
- package/dist/validators/validateIOSCategoryAction.js.map +1 -0
- package/dist/validators/validateIOSInput.d.ts +2 -0
- package/dist/validators/validateIOSInput.js +32 -0
- package/dist/validators/validateIOSInput.js.map +1 -0
- package/dist/validators/validateIOSNotification.d.ts +2 -0
- package/dist/validators/validateIOSNotification.js +211 -0
- package/dist/validators/validateIOSNotification.js.map +1 -0
- package/dist/validators/validateIOSPermissions.d.ts +2 -0
- package/dist/validators/validateIOSPermissions.js +62 -0
- package/dist/validators/validateIOSPermissions.js.map +1 -0
- package/dist/validators/validateNotification.d.ts +11 -0
- package/dist/validators/validateNotification.js +129 -0
- package/dist/validators/validateNotification.js.map +1 -0
- package/dist/validators/validateTrigger.d.ts +2 -0
- package/dist/validators/validateTrigger.js +104 -0
- package/dist/validators/validateTrigger.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js.map +1 -0
- package/ios/NotifeeCore/Info.plist +22 -0
- package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.h +28 -0
- package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +72 -0
- package/ios/NotifeeCore/NotifeeCore+NSURLSession.h +25 -0
- package/ios/NotifeeCore/NotifeeCore+NSURLSession.m +55 -0
- package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.h +37 -0
- package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +242 -0
- package/ios/NotifeeCore/NotifeeCore.h +118 -0
- package/ios/NotifeeCore/NotifeeCore.m +784 -0
- package/ios/NotifeeCore/NotifeeCoreDelegateHolder.h +34 -0
- package/ios/NotifeeCore/NotifeeCoreDelegateHolder.m +70 -0
- package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.h +39 -0
- package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.m +68 -0
- package/ios/NotifeeCore/NotifeeCoreExtensionHelper.h +38 -0
- package/ios/NotifeeCore/NotifeeCoreExtensionHelper.m +224 -0
- package/ios/NotifeeCore/NotifeeCoreUtil.h +82 -0
- package/ios/NotifeeCore/NotifeeCoreUtil.m +793 -0
- package/ios/RNNotifee/NotifeeApiModule.h +25 -0
- package/ios/RNNotifee/NotifeeApiModule.m +371 -0
- package/ios/RNNotifee/NotifeeExtensionHelper.h +37 -0
- package/ios/RNNotifee/NotifeeExtensionHelper.m +37 -0
- package/ios/RNNotifee.xcodeproj/project.pbxproj +318 -0
- package/jest-mock.js +158 -0
- package/package.json +59 -0
- package/plugin/build/index.d.ts +3 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/withNotifeeProjectGradlePlugin.d.ts +5 -0
- package/plugin/build/withNotifeeProjectGradlePlugin.js +24 -0
- package/plugin/build/withNotifeeProjectGradlePlugin.js.map +1 -0
- package/plugin/src/index.ts +9 -0
- package/plugin/src/withNotifeeProjectGradlePlugin.ts +27 -0
- package/plugin/tsconfig.json +9 -0
- package/react-native.config.js +11 -0
- package/refresh-example.sh +71 -0
- package/src/NotifeeApiModule.ts +825 -0
- package/src/NotifeeJSEventEmitter.ts +11 -0
- package/src/NotifeeNativeError.ts +70 -0
- package/src/NotifeeNativeModule.ts +55 -0
- package/src/NotifeeNativeModule.web.ts +25 -0
- package/src/index.ts +33 -0
- package/src/types/Library.ts +28 -0
- package/src/types/Module.ts +625 -0
- package/src/types/Notification.ts +505 -0
- package/src/types/NotificationAndroid.ts +1443 -0
- package/src/types/NotificationIOS.ts +681 -0
- package/src/types/NotificationWeb.ts +5 -0
- package/src/types/PowerManagerInfo.ts +43 -0
- package/src/types/Trigger.ts +118 -0
- package/src/utils/id.ts +13 -0
- package/src/utils/index.ts +47 -0
- package/src/utils/validate.ts +92 -0
- package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfo.ts +45 -0
- package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.ts +33 -0
- package/src/validators/validate.ts +85 -0
- package/src/validators/validateAndroidAction.ts +54 -0
- package/src/validators/validateAndroidChannel.ts +188 -0
- package/src/validators/validateAndroidChannelGroup.ts +49 -0
- package/src/validators/validateAndroidFullScreenAction.ts +65 -0
- package/src/validators/validateAndroidInput.ts +67 -0
- package/src/validators/validateAndroidNotification.ts +704 -0
- package/src/validators/validateAndroidPressAction.ts +65 -0
- package/src/validators/validateAndroidStyle.ts +315 -0
- package/src/validators/validateIOSAttachment.ts +136 -0
- package/src/validators/validateIOSCategory.ts +150 -0
- package/src/validators/validateIOSCategoryAction.ts +65 -0
- package/src/validators/validateIOSInput.ts +38 -0
- package/src/validators/validateIOSNotification.ts +296 -0
- package/src/validators/validateIOSPermissions.ts +78 -0
- package/src/validators/validateNotification.ts +156 -0
- package/src/validators/validateTrigger.ts +134 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,34 @@
|
|
|
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 "NotifeeCore.h"
|
|
20
|
+
|
|
21
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
22
|
+
|
|
23
|
+
@interface NotifeeCoreDelegateHolder : NSObject
|
|
24
|
+
|
|
25
|
+
@property(nonatomic, weak) id<NotifeeCoreDelegate> delegate;
|
|
26
|
+
@property(atomic, strong) NSMutableArray<NSDictionary *> *pendingEvents;
|
|
27
|
+
|
|
28
|
+
+ (instancetype)instance;
|
|
29
|
+
|
|
30
|
+
- (void)didReceiveNotifeeCoreEvent:(NSDictionary *)event;
|
|
31
|
+
|
|
32
|
+
@end
|
|
33
|
+
|
|
34
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,70 @@
|
|
|
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 "NotifeeCoreDelegateHolder.h"
|
|
19
|
+
|
|
20
|
+
@implementation NotifeeCoreDelegateHolder {
|
|
21
|
+
struct {
|
|
22
|
+
unsigned int didReceiveNotificationEvent : 1;
|
|
23
|
+
} delegateRespondsTo;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@synthesize delegate;
|
|
27
|
+
|
|
28
|
+
+ (instancetype)instance {
|
|
29
|
+
static dispatch_once_t once;
|
|
30
|
+
__strong static NotifeeCoreDelegateHolder *sharedInstance;
|
|
31
|
+
dispatch_once(&once, ^{
|
|
32
|
+
sharedInstance = [[NotifeeCoreDelegateHolder alloc] init];
|
|
33
|
+
sharedInstance.pendingEvents = [[NSMutableArray alloc] init];
|
|
34
|
+
});
|
|
35
|
+
return sharedInstance;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (void)setDelegate:(id<NotifeeCoreDelegate>)aDelegate {
|
|
39
|
+
if (delegate != aDelegate) {
|
|
40
|
+
delegate = aDelegate;
|
|
41
|
+
self->delegateRespondsTo.didReceiveNotificationEvent =
|
|
42
|
+
(unsigned int)[delegate respondsToSelector:@selector(didReceiveNotifeeCoreEvent:)];
|
|
43
|
+
if (_pendingEvents.count > 0) {
|
|
44
|
+
// make sure events are only processed once the module that wraps core has
|
|
45
|
+
// set its delegate
|
|
46
|
+
static dispatch_once_t once;
|
|
47
|
+
// TODO temp workaround to delay initial start until RN module can queue
|
|
48
|
+
// events
|
|
49
|
+
dispatch_once(&once, ^{
|
|
50
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
|
|
51
|
+
dispatch_get_main_queue(), ^{
|
|
52
|
+
for (NSDictionary *event in self->_pendingEvents) {
|
|
53
|
+
[self didReceiveNotifeeCoreEvent:event];
|
|
54
|
+
}
|
|
55
|
+
self->_pendingEvents = [[NSMutableArray alloc] init];
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
- (void)didReceiveNotifeeCoreEvent:(NSDictionary *)notificationEvent {
|
|
63
|
+
if (self->delegateRespondsTo.didReceiveNotificationEvent) {
|
|
64
|
+
[self->delegate didReceiveNotifeeCoreEvent:notificationEvent];
|
|
65
|
+
} else {
|
|
66
|
+
[self->_pendingEvents addObject:notificationEvent];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@end
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
|
|
22
|
+
#define MAX_DOWNLOAD_ATTACHMENT_SIZE 50000000
|
|
23
|
+
|
|
24
|
+
@interface NotifeeCoreDownloadDelegate : NSObject <NSURLSessionDataDelegate> {
|
|
25
|
+
NSError *error;
|
|
26
|
+
NSURLResponse *response;
|
|
27
|
+
BOOL done;
|
|
28
|
+
NSFileHandle *outputHandle;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@property(readonly, getter=isDone) BOOL done;
|
|
32
|
+
@property(readonly) NSError *error;
|
|
33
|
+
@property(readonly) NSURLResponse *response;
|
|
34
|
+
|
|
35
|
+
- (id)initWithFilePath:(NSString *)path;
|
|
36
|
+
|
|
37
|
+
@end
|
|
38
|
+
|
|
39
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,68 @@
|
|
|
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 "NotifeeCoreDownloadDelegate.h"
|
|
19
|
+
|
|
20
|
+
@implementation NotifeeCoreDownloadDelegate
|
|
21
|
+
@synthesize error, response, done;
|
|
22
|
+
|
|
23
|
+
- (void)URLSession:(NSURLSession *)session
|
|
24
|
+
dataTask:(NSURLSessionDataTask *)dataTask
|
|
25
|
+
didReceiveData:(NSData *)data {
|
|
26
|
+
[outputHandle writeData:data];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
- (void)URLSession:(NSURLSession *)session
|
|
30
|
+
dataTask:(NSURLSessionDataTask *)dataTask
|
|
31
|
+
didReceiveResponse:(NSURLResponse *)aResponse
|
|
32
|
+
completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler {
|
|
33
|
+
response = aResponse;
|
|
34
|
+
long long expectedLength = response.expectedContentLength;
|
|
35
|
+
if (expectedLength > MAX_DOWNLOAD_ATTACHMENT_SIZE) { // Cancel download task if attachment is
|
|
36
|
+
// more than allowed
|
|
37
|
+
completionHandler(NSURLSessionResponseCancel);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
completionHandler(NSURLSessionResponseAllow);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
- (void)URLSession:(NSURLSession *)session didBecomeInvalidWithError:(NSError *)anError {
|
|
44
|
+
error = anError;
|
|
45
|
+
done = YES;
|
|
46
|
+
|
|
47
|
+
[outputHandle closeFile];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
- (void)URLSession:(NSURLSession *)session
|
|
51
|
+
task:(NSURLSessionTask *)task
|
|
52
|
+
didCompleteWithError:(NSError *)anError {
|
|
53
|
+
done = YES;
|
|
54
|
+
error = anError;
|
|
55
|
+
[outputHandle closeFile];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
- (id)initWithFilePath:(NSString *)path {
|
|
59
|
+
if (self = [super init]) {
|
|
60
|
+
if ([[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
61
|
+
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
|
|
62
|
+
|
|
63
|
+
[[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
|
|
64
|
+
outputHandle = [NSFileHandle fileHandleForWritingAtPath:path];
|
|
65
|
+
}
|
|
66
|
+
return self;
|
|
67
|
+
}
|
|
68
|
+
@end
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
static NSString *const kPayloadOptionsName = @"notifee_options";
|
|
24
|
+
static NSString *const kPayloadOptionsImageURLName = @"image";
|
|
25
|
+
|
|
26
|
+
@interface NotifeeCoreExtensionHelper : NSObject
|
|
27
|
+
@property(nonatomic, strong) void (^contentHandler)(UNNotificationContent *c);
|
|
28
|
+
@property(nonatomic, strong) UNMutableNotificationContent *modifiedContent;
|
|
29
|
+
|
|
30
|
+
+ (NotifeeCoreExtensionHelper *)instance NS_SWIFT_NAME(serviceExtension());
|
|
31
|
+
|
|
32
|
+
- (void)populateNotificationContent:(UNNotificationRequest *_Nullable)request
|
|
33
|
+
withContent:(UNMutableNotificationContent *)content
|
|
34
|
+
withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler;
|
|
35
|
+
|
|
36
|
+
@end
|
|
37
|
+
|
|
38
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,224 @@
|
|
|
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 "NotifeeCoreExtensionHelper.h"
|
|
19
|
+
#import "Intents/Intents.h"
|
|
20
|
+
#import "NotifeeCore.h"
|
|
21
|
+
#import "NotifeeCoreUtil.h"
|
|
22
|
+
|
|
23
|
+
static NSString *const kNoExtension = @"";
|
|
24
|
+
static NSString *const kImagePathPrefix = @"image/";
|
|
25
|
+
|
|
26
|
+
@implementation NotifeeCoreExtensionHelper
|
|
27
|
+
+ (NotifeeCoreExtensionHelper *)instance {
|
|
28
|
+
static dispatch_once_t once;
|
|
29
|
+
static NotifeeCoreExtensionHelper *instance;
|
|
30
|
+
dispatch_once(&once, ^{
|
|
31
|
+
instance = [[self alloc] init];
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return instance;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
- (void)populateNotificationContent:(UNNotificationRequest *_Nullable)request
|
|
38
|
+
withContent:(UNMutableNotificationContent *)content
|
|
39
|
+
withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler {
|
|
40
|
+
self.contentHandler = [contentHandler copy];
|
|
41
|
+
self.modifiedContent = content;
|
|
42
|
+
|
|
43
|
+
if (!content.userInfo[@"notifee_options"]) {
|
|
44
|
+
[self deliverNotification];
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// fcm: apns: { payload: {notifee_options: {} } }
|
|
49
|
+
NSMutableDictionary *options = [self.modifiedContent.userInfo[@"notifee_options"] mutableCopy];
|
|
50
|
+
|
|
51
|
+
options[@"remote"] = @YES;
|
|
52
|
+
|
|
53
|
+
// Convert options to Notification and set defaults
|
|
54
|
+
if (options[@"data"] == nil) {
|
|
55
|
+
options[@"data"] = [NSDictionary dictionary];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Pass id to event handler
|
|
59
|
+
if (request != nil && options[@"id"] == nil) {
|
|
60
|
+
options[@"id"] = request.identifier;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (options[@"title"] == nil && content.title != nil) {
|
|
64
|
+
options[@"title"] = self.modifiedContent.title;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (options[@"body"] == nil) {
|
|
68
|
+
options[@"body"] = self.modifiedContent.body;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
self.modifiedContent = [NotifeeCore buildNotificationContent:options withTrigger:nil];
|
|
72
|
+
[self processCommunicationData:options];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
- (void)processCommunicationData:(NSMutableDictionary *)options {
|
|
76
|
+
if (options[@"ios"] == nil || options[@"ios"][@"communicationInfo"] == nil) {
|
|
77
|
+
[self handleAttachmentsAndDeliverNotificaiton:options];
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (@available(iOS 15.0, *)) {
|
|
82
|
+
NSMutableDictionary *communicationInfo = [options[@"ios"][@"communicationInfo"] mutableCopy];
|
|
83
|
+
communicationInfo[@"body"] = options[@"body"];
|
|
84
|
+
INSendMessageIntent *intent = [NotifeeCoreUtil
|
|
85
|
+
generateSenderIntentForCommunicationNotifciation:options[@"ios"][@"communicationInfo"]];
|
|
86
|
+
// Use the intent to initialize the interaction.
|
|
87
|
+
INInteraction *interaction = [[INInteraction alloc] initWithIntent:intent response:nil];
|
|
88
|
+
interaction.direction = INInteractionDirectionIncoming;
|
|
89
|
+
|
|
90
|
+
NSError *error = nil;
|
|
91
|
+
UNNotificationContent *updatedContent =
|
|
92
|
+
[self.modifiedContent contentByUpdatingWithProvider:intent error:&error];
|
|
93
|
+
if (error) {
|
|
94
|
+
NSLog(@"NotifeeCoreExtensionHelper: Could not update notification content: %@", error);
|
|
95
|
+
[self handleAttachmentsAndDeliverNotificaiton:options];
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
NSLog(@"NotifeeCoreExtensionHelper: Processing communication notification");
|
|
100
|
+
self.modifiedContent = [updatedContent mutableCopy];
|
|
101
|
+
[self handleAttachmentsAndDeliverNotificaiton:options];
|
|
102
|
+
|
|
103
|
+
[interaction donateInteractionWithCompletion:^(NSError *error) {
|
|
104
|
+
if (error)
|
|
105
|
+
NSLog(@"NotifeeCoreExtensionHelper: Could not donate interaction for communication "
|
|
106
|
+
@"notification: %@",
|
|
107
|
+
error);
|
|
108
|
+
}];
|
|
109
|
+
} else {
|
|
110
|
+
// Skip, Communication notifications not supported on iOS 15
|
|
111
|
+
[self handleAttachmentsAndDeliverNotificaiton:options];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
- (void)handleAttachmentsAndDeliverNotificaiton:(NSMutableDictionary *)options {
|
|
116
|
+
NSMutableDictionary *attachmentDict = [NSMutableDictionary new];
|
|
117
|
+
|
|
118
|
+
if (options[@"ios"] != nil && options[@"ios"][@"attachments"] != nil &&
|
|
119
|
+
[options[@"ios"][@"attachments"] isKindOfClass:[NSArray class]] &&
|
|
120
|
+
[options[@"ios"][@"attachments"] count] != 0) {
|
|
121
|
+
attachmentDict = options[@"ios"][@"attachments"][0];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Check if image url is in payload and parse it if attachmentDict is empty
|
|
125
|
+
NSString *currentImageURL = options[kPayloadOptionsImageURLName];
|
|
126
|
+
if ([attachmentDict count] == 0 && ![currentImageURL isEqual:[NSNull null]] &&
|
|
127
|
+
currentImageURL.length > 1) {
|
|
128
|
+
// make into an attachment dict
|
|
129
|
+
attachmentDict[@"url"] = currentImageURL;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if ([attachmentDict count] == 0) {
|
|
133
|
+
[self deliverNotification];
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Attempt to download attachment
|
|
138
|
+
[self loadAttachment:attachmentDict
|
|
139
|
+
completionHandler:^(UNNotificationAttachment *attachment) {
|
|
140
|
+
if (attachment != nil) {
|
|
141
|
+
self.modifiedContent.attachments = @[ attachment ];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
[self deliverNotification];
|
|
145
|
+
}];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
- (NSString *)fileExtensionForResponse:(NSURLResponse *)response {
|
|
149
|
+
NSString *suggestedPathExtension = [response.suggestedFilename pathExtension];
|
|
150
|
+
if (suggestedPathExtension.length > 0) {
|
|
151
|
+
return [NSString stringWithFormat:@".%@", suggestedPathExtension];
|
|
152
|
+
}
|
|
153
|
+
if ([response.MIMEType containsString:kImagePathPrefix]) {
|
|
154
|
+
return [response.MIMEType stringByReplacingOccurrencesOfString:kImagePathPrefix
|
|
155
|
+
withString:@"."];
|
|
156
|
+
}
|
|
157
|
+
return kNoExtension;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
- (void)loadAttachment:(NSDictionary *)attachmentDict
|
|
161
|
+
completionHandler:(void (^)(UNNotificationAttachment *))completionHandler {
|
|
162
|
+
@try {
|
|
163
|
+
__block UNNotificationAttachment *attachment = nil;
|
|
164
|
+
NSString *attachmentIdentifier = attachmentDict[@"id"];
|
|
165
|
+
NSURL *attachmentURL = [NSURL URLWithString:attachmentDict[@"url"]];
|
|
166
|
+
|
|
167
|
+
NSURLSession *session = [NSURLSession
|
|
168
|
+
sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
|
|
169
|
+
[[session
|
|
170
|
+
downloadTaskWithURL:attachmentURL
|
|
171
|
+
completionHandler:^(NSURL *temporaryFileLocation, NSURLResponse *response,
|
|
172
|
+
NSError *error) {
|
|
173
|
+
if (error != nil) {
|
|
174
|
+
NSLog(
|
|
175
|
+
@"NotifeeCoreExtensionHelper: An exception occurred while attempting to download "
|
|
176
|
+
@"image with URL %@: "
|
|
177
|
+
@"%@",
|
|
178
|
+
attachmentURL, error);
|
|
179
|
+
completionHandler(attachment);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
184
|
+
NSString *fileExtension = [self fileExtensionForResponse:response];
|
|
185
|
+
NSURL *localURL = [NSURL
|
|
186
|
+
fileURLWithPath:[temporaryFileLocation.path stringByAppendingString:fileExtension]];
|
|
187
|
+
[fileManager moveItemAtURL:temporaryFileLocation toURL:localURL error:&error];
|
|
188
|
+
if (error) {
|
|
189
|
+
NSLog(@"NotifeeCoreExtensionHelper: Failed to move the image file to local location: "
|
|
190
|
+
@"%@, error %@",
|
|
191
|
+
localURL, error);
|
|
192
|
+
completionHandler(attachment);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
attachment = [UNNotificationAttachment
|
|
197
|
+
attachmentWithIdentifier:attachmentIdentifier
|
|
198
|
+
URL:localURL
|
|
199
|
+
options:[NotifeeCoreUtil
|
|
200
|
+
attachmentOptionsFromDictionary:attachmentDict]
|
|
201
|
+
error:&error];
|
|
202
|
+
if (error) {
|
|
203
|
+
NSLog(
|
|
204
|
+
@"NotifeeCoreExtensionHelper: Failed to create attachment with URL: %@, error %@",
|
|
205
|
+
localURL, error);
|
|
206
|
+
completionHandler(attachment);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
completionHandler(attachment);
|
|
210
|
+
}] resume];
|
|
211
|
+
} @catch (NSException *exception) {
|
|
212
|
+
NSLog(@"NotifeeCoreExtensionHelper: Failed to create attachment: %@, error %@", attachmentDict,
|
|
213
|
+
exception.reason);
|
|
214
|
+
completionHandler(nil);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
- (void)deliverNotification {
|
|
219
|
+
if (self.contentHandler) {
|
|
220
|
+
self.contentHandler(self.modifiedContent);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@end
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
#import <UserNotifications/UserNotifications.h>
|
|
21
|
+
#import "Intents/Intents.h"
|
|
22
|
+
|
|
23
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
24
|
+
|
|
25
|
+
static NSString *kNotifeeUserInfoNotification = @"__notifee_notification";
|
|
26
|
+
static NSString *kNotifeeUserInfoTrigger = @"__notifee_trigger";
|
|
27
|
+
|
|
28
|
+
// TimeUnit constants for IntervalTrigger
|
|
29
|
+
static NSString *kNotifeeCoreTimeUnitSeconds = @"SECONDS";
|
|
30
|
+
static NSString *kNotifeeCoreTimeUnitMinutes = @"MINUTES";
|
|
31
|
+
static NSString *kNotifeeCoreTimeUnitHours = @"HOURS";
|
|
32
|
+
static NSString *kNotifeeCoreTimeUnitDays = @"DAYS";
|
|
33
|
+
|
|
34
|
+
// Enum representing trigger notification types
|
|
35
|
+
typedef NS_ENUM(NSInteger, NotifeeCoreTriggerType) {
|
|
36
|
+
NotifeeCoreTriggerTypeTimestamp = 0,
|
|
37
|
+
NotifeeCoreTriggerTypeInterval = 1
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Enum representing repeat frequency for TimestampTrigger
|
|
41
|
+
typedef NS_ENUM(NSInteger, NotifeeCoreRepeatFrequency) {
|
|
42
|
+
NotifeeCoreRepeatFrequencyHourly = 0,
|
|
43
|
+
NotifeeCoreRepeatFrequencyDaily = 1,
|
|
44
|
+
NotifeeCoreRepeatFrequencyWeekly = 2,
|
|
45
|
+
NotifeeCoreRepeatFrequencyMonthly = 3
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
@interface NotifeeCoreUtil : NSObject
|
|
49
|
+
|
|
50
|
+
+ (NSNumber *)numberForUNNotificationSetting:(UNNotificationSetting)setting;
|
|
51
|
+
|
|
52
|
+
+ (NSMutableArray<NSDictionary *> *)notificationActionsToDictionaryArray:
|
|
53
|
+
(NSArray<UNNotificationAction *> *)notificationActions;
|
|
54
|
+
|
|
55
|
+
+ (NSMutableArray<UNNotificationAction *> *)notificationActionsFromDictionaryArray:
|
|
56
|
+
(NSArray<NSDictionary *> *)actionDictionaries;
|
|
57
|
+
|
|
58
|
+
+ (NSMutableArray<UNNotificationAttachment *> *)notificationAttachmentsFromDictionaryArray:
|
|
59
|
+
(NSArray<NSDictionary *> *)attachmentDictionaries;
|
|
60
|
+
|
|
61
|
+
+ (NSDictionary *)attachmentOptionsFromDictionary:(NSDictionary *)optionsDict;
|
|
62
|
+
|
|
63
|
+
+ (NSMutableArray<NSNumber *> *)intentIdentifiersFromStringArray:(NSArray<NSString *> *)identifiers;
|
|
64
|
+
|
|
65
|
+
+ (NSMutableArray<NSString *> *)intentIdentifiersFromNumberArray:(NSArray<NSNumber *> *)identifiers;
|
|
66
|
+
|
|
67
|
+
+ (UNNotificationTrigger *)triggerFromDictionary:(NSDictionary *)triggerDict;
|
|
68
|
+
|
|
69
|
+
+ (NSNumber *)convertToTimestamp:(NSDate *)date;
|
|
70
|
+
|
|
71
|
+
+ (NSDictionary *)parseUNNotificationRequest:(UNNotificationRequest *)request;
|
|
72
|
+
|
|
73
|
+
+ (INSendMessageIntent *)generateSenderIntentForCommunicationNotifciation:
|
|
74
|
+
(NSMutableDictionary *)options;
|
|
75
|
+
|
|
76
|
+
+ (BOOL)isAppExtension;
|
|
77
|
+
|
|
78
|
+
+ (nullable instancetype)notifeeUIApplication;
|
|
79
|
+
|
|
80
|
+
@end
|
|
81
|
+
|
|
82
|
+
NS_ASSUME_NONNULL_END
|