Skip to content

Commit 1039cd1

Browse files
author
Olga Danylova
authored
Merge pull request #212 from olgadanylova/master
Push templates fixed to work correctly when adding new button options
2 parents ada1ac2 + b1cfa13 commit 1039cd1

File tree

16 files changed

+29
-33
lines changed

16 files changed

+29
-33
lines changed

SDK/backendlessAPI/Classes/Messaging/BackendlessPushHelper.m

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

SDK/backendlessAPI/backendlessAPI.xcodeproj/xcshareddata/xcschemes/backendless-device.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1010"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SDK/backendlessAPI/backendlessAPI.xcodeproj/xcshareddata/xcschemes/backendless-fat.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1010"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SDK/backendlessAPI/backendlessAPI.xcodeproj/xcshareddata/xcschemes/backendless-mac.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1010"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SDK/backendlessAPI/backendlessAPI.xcodeproj/xcshareddata/xcschemes/backendless-simulator.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1010"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SDK/backendlessAPI/backendlessAPI.xcodeproj/xcshareddata/xcschemes/backendless-tv-device.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1010"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SDK/backendlessAPI/backendlessAPI.xcodeproj/xcshareddata/xcschemes/backendless-tv-simulator.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1010"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SDK/backendlessAPI/backendlessAPI.xcodeproj/xcshareddata/xcschemes/backendless-watch-device.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1010"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SDK/backendlessAPI/backendlessAPI.xcodeproj/xcshareddata/xcschemes/backendless-watch-simulator.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1010"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SDK/backendlessAPI/backendlessAPI.xcodeproj/xcshareddata/xcschemes/bkndlss-device.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1010"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

0 commit comments

Comments
 (0)