@@ -49,27 +49,22 @@ -(void)processMutableContent:(UNNotificationRequest *_Nonnull)request withConten
4949 }
5050
5151 UNMutableNotificationContent *bestAttemptContent = [request.content mutableCopy ];
52- if ([request.content.userInfo valueForKey: @" attachment-url" ]) {
53- NSString *urlString = [request.content.userInfo valueForKey: @" attachment-url" ];
54- NSURL *fileUrl = [NSURL URLWithString: urlString];
55- [[[NSURLSession sharedSession ] downloadTaskWithURL: fileUrl
56- completionHandler: ^(NSURL *location, NSURLResponse *response, NSError *error) {
57- if (location) {
58- NSString *tmpDirectory = NSTemporaryDirectory ();
59- NSString *tmpFile = [[@" file://" stringByAppendingString: tmpDirectory] stringByAppendingString: fileUrl.lastPathComponent];
60- NSURL *tmpUrl = [NSURL URLWithString: tmpFile];
61- BOOL success = [[NSFileManager defaultManager ] moveItemAtURL: location toURL: tmpUrl error: nil ];
62- UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier: @" " URL: tmpUrl options: nil error: nil ];
63- if (attachment) {
64- bestAttemptContent.attachments = @[attachment];
65- }
52+ NSString *urlString = [request.content.userInfo valueForKey: @" attachment-url" ];
53+ NSURL *fileUrl = [NSURL URLWithString: urlString];
54+ [[[NSURLSession sharedSession ] downloadTaskWithURL: fileUrl
55+ completionHandler: ^(NSURL *location, NSURLResponse *response, NSError *error) {
56+ if (location) {
57+ NSString *tmpDirectory = NSTemporaryDirectory ();
58+ NSString *tmpFile = [[@" file://" stringByAppendingString: tmpDirectory] stringByAppendingString: fileUrl.lastPathComponent];
59+ NSURL *tmpUrl = [NSURL URLWithString: tmpFile];
60+ BOOL success = [[NSFileManager defaultManager ] moveItemAtURL: location toURL: tmpUrl error: nil ];
61+ UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier: @" " URL: tmpUrl options: nil error: nil ];
62+ if (attachment) {
63+ bestAttemptContent.attachments = @[attachment];
6664 }
67- contentHandler (bestAttemptContent);
68- }] resume ];
69- }
70- else {
71- contentHandler (bestAttemptContent);
72- }
65+ }
66+ contentHandler (bestAttemptContent);
67+ }] resume ];
7368}
7469
7570-(UNNotificationRequest *)prepareRequestWithIosImmediatePush : (UNNotificationRequest *)request {
@@ -100,7 +95,7 @@ -(UNNotificationRequest *)createRequestFromTemplate:(NSDictionary *)iosPushTempl
10095 NSNumber *contentAvailable = [iosPushTemplate valueForKey: @" contentAvailable" ];
10196 NSInteger contentAvailableInt = [contentAvailable integerValue ];
10297 if (contentAvailableInt == 1 ) {
103-
98+
10499 }
105100 else {
106101 content.body = [[[request.content.userInfo valueForKey: @" aps" ] valueForKey: @" alert" ] valueForKey: @" body" ];
@@ -134,6 +129,7 @@ -(UNNotificationRequest *)createRequestFromTemplate:(NSDictionary *)iosPushTempl
134129 [userInfo setObject: urlString forKey: @" attachment-url" ];
135130 content.userInfo = userInfo;
136131 }
132+
137133 NSArray *actionsArray = [iosPushTemplate valueForKey: @" actions" ];
138134 content.categoryIdentifier = [self setActions: actionsArray];
139135 }
@@ -150,7 +146,6 @@ -(UNNotificationRequest *)createRequestFromTemplate:(NSDictionary *)iosPushTempl
150146
151147-(NSString *)setActions : (NSArray *)actions {
152148 NSMutableArray *categoryActions = [NSMutableArray new ];
153-
154149 for (NSDictionary *action in actions) {
155150 NSString *actionId = [action valueForKey: @" id" ];
156151 NSString *actionTitle = [action valueForKey: @" title" ];
@@ -160,7 +155,8 @@ -(NSString *)setActions:(NSArray *)actions {
160155 }
161156 NSString *categoryId = @" buttonActionsTemplate" ;
162157 UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier: categoryId actions: categoryActions intentIdentifiers: @[] options: UNNotificationCategoryOptionNone ];
163- [UNUserNotificationCenter .currentNotificationCenter setNotificationCategories: [NSSet setWithObject: category]];
158+ [[UNUserNotificationCenter currentNotificationCenter ] setNotificationCategories: [NSSet setWithObject: category]];
159+
164160 return categoryId;
165161}
166162
0 commit comments