Skip to content

Commit 8a55f63

Browse files
committed
fix: add nil checks for native jsonResponse
1 parent 19a71e8 commit 8a55f63

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

Assets/Adjust/Native/iOS/AdjustUnity.mm

+7-6
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,13 @@ void _AdjustGetAttribution(AdjustDelegateAttributionGetter callback) {
372372
addValueOrEmpty(dictionary, @"costType", attribution.costType);
373373
addValueOrEmpty(dictionary, @"costAmount", attribution.costAmount);
374374
addValueOrEmpty(dictionary, @"costCurrency", attribution.costCurrency);
375-
376-
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:attribution.jsonResponse
377-
options:0
378-
error:nil];
379-
NSString *strJsonResponse = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
380-
addValueOrEmpty(dictionary, @"jsonResponse", strJsonResponse);
375+
if (attribution.jsonResponse != nil) {
376+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:attribution.jsonResponse
377+
options:0
378+
error:nil];
379+
NSString *strJsonResponse = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
380+
addValueOrEmpty(dictionary, @"jsonResponse", strJsonResponse);
381+
}
381382

382383
NSData *dataAttribution = [NSJSONSerialization dataWithJSONObject:dictionary
383384
options:0

Assets/Adjust/Native/iOS/AdjustUnityDelegate.mm

+9-7
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,15 @@ - (void)adjustAttributionChangedWannabe:(ADJAttribution *)attribution {
124124
forKey:@"costCurrency"
125125
toDictionary:dictionary];
126126

127-
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:attribution.jsonResponse
128-
options:0
129-
error:nil];
130-
NSString *strJsonResponse = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
131-
[self addValueOrEmpty:strJsonResponse
132-
forKey:@"jsonResponse"
133-
toDictionary:dictionary];
127+
if (attribution.jsonResponse != nil) {
128+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:attribution.jsonResponse
129+
options:0
130+
error:nil];
131+
NSString *strJsonResponse = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
132+
[self addValueOrEmpty:strJsonResponse
133+
forKey:@"jsonResponse"
134+
toDictionary:dictionary];
135+
}
134136

135137
NSData *dataAttribution = [NSJSONSerialization dataWithJSONObject:dictionary
136138
options:0

0 commit comments

Comments
 (0)