Skip to content

Commit e011389

Browse files
Nightsd01jkasten2
authored andcommitted
Fixes some format issues
* Resolves a few typos/conflicts that broke buttons and attachments on the old push notification format vs. new.
1 parent 304fb7a commit e011389

File tree

2 files changed

+110
-68
lines changed

2 files changed

+110
-68
lines changed

iOS_SDK/OneSignalSDK/Source/OSNotificationPayload.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,18 @@ -(void)parseOriginalPayload {
6161
[self parseRemoteSlient:_rawPayload];
6262
else {
6363
[self parseApnsFields];
64-
_attachments = _rawPayload[@"at"];
65-
[self parseActionButtons:_rawPayload[@"o"]];
64+
_attachments = _rawPayload[@"att"];
65+
[self parseActionButtons:_rawPayload[@"buttons"]];
6666
}
6767

6868
[self parseCommonOneSignalFields:_rawPayload[@"custom"]];
6969
_additionalData = _rawPayload[@"custom"][@"a"];
70+
71+
//fixes an issue where actionSelected was a top level property in _rawPayload
72+
//and 'actionSelected' was not being set in additionalData
73+
if (_rawPayload[@"actionSelected"] && !_additionalData) {
74+
_additionalData = @{@"actionSelected" : _rawPayload[@"actionSelected"]};
75+
}
7076
}
7177

7278
// New OneSignal playload format.

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 102 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,31 +1248,23 @@ - (void)testNotificationOpenFromButtonPressWithNewformat {
12481248
}
12491249

12501250
// Testing iOS 10 - 2.4.0+ button fromat - with os_data aps payload format
1251-
- (void)testNotificationAlertButtonsDisplayWithNewformat {
1251+
- (void)notificationAlertButtonsDisplayWithFormat:(NSDictionary *)userInfo {
12521252
__block BOOL openedWasFire = false;
1253-
1254-
[OneSignal initWithLaunchOptions:nil appId:@"b2f7f966-d8cc-11e4-bed1-df8f05be55ba" handleNotificationAction:^(OSNotificationOpenedResult *result) {
1253+
id receiveBlock = ^(OSNotificationOpenedResult *result) {
12551254
XCTAssertEqual(result.action.type, OSNotificationActionTypeActionTaken);
12561255
XCTAssertEqualObjects(result.action.actionID, @"id1");
12571256
id actionButons = @[@{@"id": @"id1", @"text": @"text1"}];
12581257
XCTAssertEqualObjects(result.notification.payload.actionButtons, actionButons);
12591258
XCTAssertEqualObjects(result.notification.payload.additionalData[@"actionSelected"], @"id1");
12601259

12611260
openedWasFire = true;
1262-
}];
1261+
};
1262+
1263+
[OneSignal initWithLaunchOptions:nil appId:@"b2f7f966-d8cc-11e4-bed1-df8f05be55ba" handleNotificationAction:receiveBlock];
12631264

12641265
[self resumeApp];
12651266
[self runBackgroundThreads];
12661267

1267-
id userInfo = @{@"aps": @{
1268-
@"mutable-content": @1,
1269-
@"alert": @{@"body": @"Message Body", @"title": @"title"}
1270-
},
1271-
@"os_data": @{
1272-
@"i": @"b2f7f966-d8cc-11e4-bed1-df8f05be55bf",
1273-
@"buttons": @[@{@"i": @"id1", @"n": @"text1"}],
1274-
}};
1275-
12761268
id notifResponse = [self createBasiciOSNotificationResponseWithPayload:userInfo];
12771269
[notifResponse setValue:@"id1" forKeyPath:@"actionIdentifier"];
12781270

@@ -1287,6 +1279,34 @@ - (void)testNotificationAlertButtonsDisplayWithNewformat {
12871279
XCTAssertEqual(openedWasFire, true);
12881280
}
12891281

1282+
- (void)testOldFormatNotificationAlertButtonsDisplay {
1283+
id oldFormat = @{@"aps" : @{
1284+
@"mutable-content" : @1,
1285+
@"alert" : @{
1286+
@"title" : @"Test Title"
1287+
}
1288+
},
1289+
@"buttons" : @[@{@"i": @"id1", @"n": @"text1"}],
1290+
@"custom" : @{
1291+
@"i" : @"b2f7f966-d8cc-11e4-bed1-df8f05be55bf"
1292+
}
1293+
};
1294+
1295+
[self notificationAlertButtonsDisplayWithFormat:oldFormat];
1296+
}
1297+
1298+
- (void)testNewFormatNotificationAlertButtonsDisplay {
1299+
id newFormat = @{@"aps": @{
1300+
@"mutable-content": @1,
1301+
@"alert": @{@"body": @"Message Body", @"title": @"title"}
1302+
},
1303+
@"os_data": @{
1304+
@"i": @"b2f7f966-d8cc-11e4-bed1-df8f05be55bf",
1305+
@"buttons": @[@{@"i": @"id1", @"n": @"text1"}],
1306+
}};
1307+
1308+
[self notificationAlertButtonsDisplayWithFormat:newFormat];
1309+
}
12901310

12911311
// Testing iOS 10 - with original aps payload format
12921312
- (void)testOpeningWithAdditionalData {
@@ -1332,30 +1352,20 @@ - (void)testOpeningWithAdditionalData {
13321352
}
13331353

13341354
// Testing iOS 10 - pre-2.4.0 button fromat - with os_data aps payload format
1335-
- (void)testRecievedCallbackWithButtons {
1355+
- (void)receivedCallbackWithButtonsWithUserInfo:(NSDictionary *)userInfo {
13361356
__block BOOL recievedWasFire = false;
13371357

13381358
[OneSignal initWithLaunchOptions:nil
13391359
appId:@"b2f7f966-d8cc-11e4-bed1-df8f05be55ba"
13401360
handleNotificationReceived:^(OSNotification *notification) {
1341-
recievedWasFire = true;
1342-
let actionButons = @[ @{@"id": @"id1", @"text": @"text1"} ];
1343-
XCTAssertEqualObjects(notification.payload.actionButtons, actionButons);
1361+
recievedWasFire = true;
1362+
let actionButons = @[ @{@"id": @"id1", @"text": @"text1"} ];
1363+
XCTAssertEqualObjects(notification.payload.actionButtons, actionButons);
13441364
}
13451365
handleNotificationAction:nil
13461366
settings:nil];
13471367
[self runBackgroundThreads];
13481368

1349-
let userInfo = @{@"aps": @{@"content_available": @1},
1350-
@"os_data": @{
1351-
@"i": @"b2f7f966-d8cc-11e4-bed1-df8f05be55bb",
1352-
@"buttons": @{
1353-
@"m": @"alert body only",
1354-
@"o": @[@{@"i": @"id1", @"n": @"text1"}]
1355-
}
1356-
}
1357-
};
1358-
13591369
let notifResponse = [self createBasiciOSNotificationResponseWithPayload:userInfo];
13601370
UNUserNotificationCenter *notifCenter = [UNUserNotificationCenter currentNotificationCenter];
13611371
let notifCenterDelegate = notifCenter.delegate;
@@ -1368,6 +1378,33 @@ - (void)testRecievedCallbackWithButtons {
13681378
XCTAssertEqual(recievedWasFire, true);
13691379
}
13701380

1381+
- (void)testReceivedCallbackWithButtonsWithNewFormat {
1382+
let newFormat = @{@"aps": @{@"content_available": @1},
1383+
@"os_data": @{
1384+
@"i": @"b2f7f966-d8cc-11e4-bed1-df8f05be55bb",
1385+
@"buttons": @{
1386+
@"m": @"alert body only",
1387+
@"o": @[@{@"i": @"id1", @"n": @"text1"}]
1388+
}
1389+
}
1390+
};
1391+
1392+
id oldFormat = @{@"aps" : @{
1393+
@"mutable-content" : @1,
1394+
@"alert" : @{
1395+
@"title" : @"Test Title"
1396+
}
1397+
},
1398+
@"buttons" : @[@{@"i": @"id1", @"n": @"text1"}],
1399+
@"custom" : @{
1400+
@"i" : @"b2f7f966-d8cc-11e4-bed1-df8f05be55bf"
1401+
}
1402+
};
1403+
1404+
[self receivedCallbackWithButtonsWithUserInfo:newFormat];
1405+
[self receivedCallbackWithButtonsWithUserInfo:oldFormat];
1406+
}
1407+
13711408
-(void)fireDidReceiveRemoteNotification:(NSDictionary*)userInfo {
13721409
let appDelegate = [UIApplication sharedApplication].delegate;
13731410
[appDelegate application:[UIApplication sharedApplication]
@@ -1702,50 +1739,49 @@ -(UNNotificationCategory*)unNotificagionCategoryWithId:(NSString*)identifier {
17021739
}
17031740

17041741
// iOS 10 - Notification Service Extension test
1705-
- (void)testDidReceiveNotificatioExtensionRequest {
1706-
// Example of a pre-existing category a developer setup.
1707-
// Plus possibly an existing "__dynamic__" category of ours.
1708-
let categorySet = [NSMutableSet new];
1709-
[categorySet addObject:[self unNotificagionCategoryWithId:@"some_category"]];
1710-
[categorySet addObject:[self unNotificagionCategoryWithId:@"__dynamic__"]];
1711-
[categorySet addObject:[self unNotificagionCategoryWithId:@"some_category2"]];
1712-
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categorySet];
1713-
1714-
var userInfo = @{@"aps": @{
1715-
@"mutable-content": @1,
1716-
@"alert": @"Message Body"
1717-
},
1718-
@"os_data": @{
1719-
@"i": @"b2f7f966-d8cc-11e4-bed1-df8f05be55bb",
1720-
@"buttons": @[@{@"i": @"id1", @"n": @"text1"}],
1721-
@"att": @{ @"id": @"http://domain.com/file.jpg" }
1722-
}};
1742+
- (void) didReceiveNotificationExtensionRequestDontOverrideCateogoryWithUserInfo:(NSDictionary *)userInfo {
1743+
id notifResponse = [self createBasiciOSNotificationResponseWithPayload:userInfo];
17231744

1724-
var notifResponse = [self createBasiciOSNotificationResponseWithPayload:userInfo];
1725-
let content = [OneSignal didReceiveNotificationExtensionRequest:[notifResponse notification].request withMutableNotificationContent:nil];
1745+
[[notifResponse notification].request.content setValue:@"some_category" forKey:@"categoryIdentifier"];
17261746

1727-
// Make sure butons were added.
1728-
XCTAssertEqualObjects(content.categoryIdentifier, @"__dynamic__");
1747+
UNMutableNotificationContent* content = [OneSignal didReceiveNotificationExtensionRequest:[notifResponse notification].request withMutableNotificationContent:nil];
1748+
1749+
// Make sure we didn't override an existing category
1750+
XCTAssertEqualObjects(content.categoryIdentifier, @"some_category");
17291751
// Make sure attachments were added.
17301752
XCTAssertEqualObjects(content.attachments[0].identifier, @"id");
17311753
XCTAssertEqualObjects(content.attachments[0].URL.scheme, @"file");
1732-
1733-
1734-
// Run again with different buttons.
1735-
userInfo = @{@"aps": @{
1736-
@"mutable-content": @1,
1737-
@"alert": @"Message Body"
1738-
},
1739-
@"os_data": @{
1740-
@"i": @"b2f7f966-d8cc-11e4-bed1-df8f05be55bb",
1741-
@"buttons": @[@{@"i": @"id2", @"n": @"text2"}],
1742-
@"att": @{ @"id": @"http://domain.com/file.jpg"}
1743-
}};
1744-
1745-
notifResponse = [self createBasiciOSNotificationResponseWithPayload:userInfo];
1746-
[OneSignal didReceiveNotificationExtensionRequest:[notifResponse notification].request withMutableNotificationContent:nil];
1747-
1748-
XCTAssertEqual(UNUserNotificationCenterOverrider.lastSetCategoriesCount, 3);
1754+
}
1755+
1756+
- (void)testDidReceiveNotificationExtensionRequestDontOverrideCategory
1757+
{
1758+
id newFormat = @{@"aps": @{
1759+
@"mutable-content": @1,
1760+
@"alert": @"Message Body"
1761+
},
1762+
@"os_data": @{
1763+
@"i": @"b2f7f966-d8cc-11e4-bed1-df8f05be55bb",
1764+
@"buttons": @[@{@"i": @"id1", @"n": @"text1"}],
1765+
@"att": @{ @"id": @"http://domain.com/file.jpg" }
1766+
}};
1767+
1768+
id oldFormat = @{@"aps" : @{
1769+
@"mutable-content" : @1,
1770+
@"alert" : @{
1771+
@"title" : @"Test Title"
1772+
}
1773+
},
1774+
1775+
@"att": @{ @"id": @"http://domain.com/file.jpg" },
1776+
@"buttons" : @[@{@"i": @"id1", @"n": @"text1"}],
1777+
@"custom" : @{
1778+
@"i" : @"b2f7f966-d8cc-11e4-bed1-df8f05be55bf"
1779+
}
1780+
};
1781+
1782+
1783+
[self didReceiveNotificationExtensionRequestDontOverrideCateogoryWithUserInfo:oldFormat];
1784+
[self didReceiveNotificationExtensionRequestDontOverrideCateogoryWithUserInfo:newFormat];
17491785
}
17501786

17511787
// iOS 10 - Notification Service Extension test

0 commit comments

Comments
 (0)