Skip to content

Commit 2e591de

Browse files
committed
Make null values safe for IAM request payload
* If subscription ID (most common) or other properties such as app ID are `nil`, the app crashes when requests for IAM impressions or clicks are created. * The app will crash with Exception `[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]` * Use a null-safe dictionary that will omit the entry if the value is null * We choose to send these requests so we have record of 400-ing requests
1 parent f1489cc commit 2e591de

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Requests/OSInAppMessagingRequests.m

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ + (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId
4444
forVariantId:(NSString *)variantId {
4545
let request = [OSRequestInAppMessageViewed new];
4646

47-
request.parameters = @{
48-
@"device_type": @0,
49-
@"player_id": playerId,
50-
@"app_id": appId,
51-
@"variant_id": variantId
52-
};
47+
let params = [NSMutableDictionary new];
48+
params[@"device_type"] = @0;
49+
params[@"player_id"] = playerId;
50+
params[@"app_id"] = appId;
51+
params[@"variant_id"] = variantId;
5352

53+
request.parameters = params;
5454
request.method = POST;
5555
request.path = [NSString stringWithFormat:@"in_app_messages/%@/impression", messageId];
5656

@@ -66,14 +66,14 @@ + (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId
6666
forVariantId:(NSString *)variantId {
6767
let request = [OSRequestInAppMessagePageViewed new];
6868

69-
request.parameters = @{
70-
@"device_type": @0,
71-
@"player_id": playerId,
72-
@"app_id": appId,
73-
@"variant_id": variantId,
74-
@"page_id": pageId
75-
};
69+
let params = [NSMutableDictionary new];
70+
params[@"device_type"] = @0;
71+
params[@"player_id"] = playerId;
72+
params[@"app_id"] = appId;
73+
params[@"variant_id"] = variantId;
74+
params[@"page_id"] = pageId;
7675

76+
request.parameters = params;
7777
request.method = POST;
7878
request.path = [NSString stringWithFormat:@"in_app_messages/%@/pageImpression", messageId];
7979

@@ -89,15 +89,15 @@ + (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId
8989
withAction:(OSInAppMessageClickResult * _Nonnull)action {
9090
let request = [OSRequestInAppMessageClicked new];
9191

92-
request.parameters = @{
93-
@"app_id": appId,
94-
@"device_type": @0,
95-
@"player_id": playerId,
96-
@"click_id": action.clickId ?: @"",
97-
@"variant_id": variantId,
98-
@"first_click": @(action.firstClick)
99-
};
92+
let params = [NSMutableDictionary new];
93+
params[@"app_id"] = appId;
94+
params[@"device_type"] = @0;
95+
params[@"player_id"] = playerId;
96+
params[@"click_id"] = action.clickId ?: @"";
97+
params[@"variant_id"] = variantId;
98+
params[@"first_click"] = @(action.firstClick);
10099

100+
request.parameters = params;
101101
request.method = POST;
102102
request.path = [NSString stringWithFormat:@"in_app_messages/%@/click", messageId];
103103

0 commit comments

Comments
 (0)