Skip to content

Fix for App Crashes During JSON Serialization After Updates #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions ios/Classes/AdjustSdk.m
Original file line number Diff line number Diff line change
@@ -267,7 +267,7 @@ - (void)initSdk:(FlutterMethodCall *)call withResult:(FlutterResult)result {
[adjustConfig disableIdfvReading];
}
}

// SKAdNetwork attribution
if ([self isFieldValid:isSkanAttributionEnabled]) {
if ([isSkanAttributionEnabled boolValue] == NO) {
@@ -419,7 +419,7 @@ - (void)processDeeplink:(FlutterMethodCall *)call withResult:(FlutterResult)resu
if (urlString == nil) {
return;
}

NSURL *url = [NSURL URLWithString:urlString];
ADJDeeplink *deeplink = [[ADJDeeplink alloc] initWithDeeplink:url];
[Adjust processDeeplink:deeplink];
@@ -456,12 +456,12 @@ - (void)trackAdRevenue:(FlutterMethodCall *)call withResult:(FlutterResult)resul
if ([self isFieldValid:adRevenueNetwork]) {
[adjustAdRevenue setAdRevenueNetwork:adRevenueNetwork];
}

// ad revenue unit
if ([self isFieldValid:adRevenueUnit]) {
[adjustAdRevenue setAdRevenueUnit:adRevenueUnit];
}

// ad revenue placement
if ([self isFieldValid:adRevenuePlacement]) {
[adjustAdRevenue setAdRevenuePlacement:adRevenuePlacement];
@@ -576,13 +576,19 @@ - (void)getAttribution:(FlutterMethodCall *)call withResult:(FlutterResult)resul
[self addValueOrEmpty:attribution.costType withKey:@"costType" toDictionary:dictionary];
[self addNumberOrEmpty:attribution.costAmount withKey:@"costAmount" toDictionary:dictionary];
[self addValueOrEmpty:attribution.costCurrency withKey:@"costCurrency" toDictionary:dictionary];
NSData *dataJsonResponse = [NSJSONSerialization dataWithJSONObject:attribution.jsonResponse

// Add nil check before serializing jsonResponse
if (attribution.jsonResponse != nil) {
NSData *dataJsonResponse = [NSJSONSerialization dataWithJSONObject:attribution.jsonResponse
options:0
error:nil];
NSString *stringJsonResponse = [[NSString alloc] initWithBytes:[dataJsonResponse bytes]
NSString *stringJsonResponse = [[NSString alloc] initWithBytes:[dataJsonResponse bytes]
length:[dataJsonResponse length]
encoding:NSUTF8StringEncoding];
[self addValueOrEmpty:stringJsonResponse withKey:@"jsonResponse" toDictionary:dictionary];
[self addValueOrEmpty:stringJsonResponse withKey:@"jsonResponse" toDictionary:dictionary];
} else {
[self addValueOrEmpty:@"" withKey:@"jsonResponse" toDictionary:dictionary];
}
result(dictionary);
}];
}
@@ -687,7 +693,7 @@ - (void)verifyAppStorePurchase:(FlutterMethodCall *)call withResult:(FlutterResu
if (verificationResult == nil) {
result(dictionary);
}

[self addValueOrEmpty:verificationResult.verificationStatus
withKey:@"verificationStatus"
toDictionary:dictionary];
@@ -788,7 +794,7 @@ - (void)verifyAndTrackAppStorePurchase:(FlutterMethodCall *)call withResult:(Flu
if (verificationResult == nil) {
result(dictionary);
}

[self addValueOrEmpty:verificationResult.verificationStatus
withKey:@"verificationStatus"
toDictionary:dictionary];
24 changes: 15 additions & 9 deletions ios/Classes/AdjustSdkDelegate.m
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ + (id)getInstanceWithSwizzleOfAttributionCallback:(NSString *)swizzleAttribution
methodChannel:(FlutterMethodChannel *)channel {
dispatch_once(&onceToken, ^{
defaultInstance = [[AdjustSdkDelegate alloc] init];

// do the swizzling where and if needed
if (swizzleAttributionCallback != nil) {
[defaultInstance swizzleCallbackMethod:@selector(adjustAttributionChanged:)
@@ -107,7 +107,7 @@ - (void)adjustAttributionChangedWannabe:(ADJAttribution *)attribution {
if (nil == attribution || nil == dartAttributionCallback) {
return;
}

id keys[] = {
@"trackerToken",
@"trackerName",
@@ -121,12 +121,18 @@ - (void)adjustAttributionChangedWannabe:(ADJAttribution *)attribution {
@"costCurrency",
@"jsonResponse"
};
NSData *dataJsonResponse = [NSJSONSerialization dataWithJSONObject:attribution.jsonResponse
options:0
error:nil];
NSString *stringJsonResponse = [[NSString alloc] initWithBytes:[dataJsonResponse bytes]
length:[dataJsonResponse length]
encoding:NSUTF8StringEncoding];

// Add nil check before serializing jsonResponse
NSString *stringJsonResponse = @"";
if (attribution.jsonResponse != nil) {
NSData *dataJsonResponse = [NSJSONSerialization dataWithJSONObject:attribution.jsonResponse
options:0
error:nil];
stringJsonResponse = [[NSString alloc] initWithBytes:[dataJsonResponse bytes]
length:[dataJsonResponse length]
encoding:NSUTF8StringEncoding];
}

id values[] = {
[self getValueOrEmpty:[attribution trackerToken]],
[self getValueOrEmpty:[attribution trackerName]],
@@ -202,7 +208,7 @@ - (void)adjustEventTrackingSucceededWannabe:(ADJEventSuccess *)eventSuccessRespo
if (nil == eventSuccessResponseData || nil == dartEventSuccessCallback) {
return;
}

id keys[] = {
@"message",
@"timestamp",