Skip to content

Commit a0493bd

Browse files
committed
Refactor AIActivityHandler.m
1 parent 1c63df5 commit a0493bd

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

Adjust/AIActivityHandler.m

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#import "AIAdjustFactory.h"
2020

2121
static NSString * const kActivityStateFilename = @"AdjustIoActivityState";
22+
static NSString * const kAdjustPrefix = @"adjust_";
2223
static const char * const kInternalQueueName = "io.adjust.ActivityQueue";
23-
static NSString * const kAdjustPrefix = @"adjust_";
2424

25-
static const uint64_t kTimerInterval = 60 * NSEC_PER_SEC; // 1 minute
26-
static const uint64_t kTimerLeeway = 1 * NSEC_PER_SEC; // 1 second
25+
static const uint64_t kTimerInterval = 60 * NSEC_PER_SEC; // 1 minute
26+
static const uint64_t kTimerLeeway = 1 * NSEC_PER_SEC; // 1 second
2727

2828

2929
#pragma mark -
@@ -317,32 +317,37 @@ - (void)revenueInternal:(double)amount
317317
}
318318

319319
- (void) readOpenUrlInternal:(NSURL *)url {
320-
NSString* queryString = [url query];
321-
NSArray* queryArray = [queryString componentsSeparatedByString:@"&"];
320+
NSArray* queryArray = [url.query componentsSeparatedByString:@"&"];
322321
NSMutableDictionary* adjustDeepLinks = [NSMutableDictionary dictionary];
323322

324323
for (NSString* fieldValuePair in queryArray) {
325324
NSArray* pairComponents = [fieldValuePair componentsSeparatedByString:@"="];
325+
if (pairComponents.count != 2) continue;
326+
326327
NSString* key = [pairComponents objectAtIndex:0];
327-
if ([key hasPrefix:kAdjustPrefix] && [pairComponents count] == 2) {
328-
NSString* value = [pairComponents objectAtIndex:1];
329-
NSString* keyWOutPrefix = [key substringFromIndex:[kAdjustPrefix length]];
330-
if ([keyWOutPrefix length] > 0 && [value length] > 0) {
331-
[adjustDeepLinks setObject:value forKey:keyWOutPrefix];
332-
}
333-
}
334-
}
328+
if (![key hasPrefix:kAdjustPrefix]) continue;
335329

336-
if ([adjustDeepLinks count] != 0) {
337-
AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init];
338-
reattributionBuilder.deeplinkParameters = adjustDeepLinks;
339-
[self injectGeneralAttributes:reattributionBuilder];
340-
AIActivityPackage *reattributionPackage = [reattributionBuilder buildReattributionPackage];
341-
[self.packageHandler addPackage:reattributionPackage];
342-
[self.packageHandler sendFirstPackage];
330+
NSString* value = [pairComponents objectAtIndex:1];
331+
if (value.length == 0) continue;
332+
333+
NSString* keyWOutPrefix = [key substringFromIndex:kAdjustPrefix.length];
334+
if (keyWOutPrefix.length == 0) continue;
343335

344-
[self.logger info:@"Reattribution %@", adjustDeepLinks];
336+
[adjustDeepLinks setObject:value forKey:keyWOutPrefix];
345337
}
338+
339+
if (adjustDeepLinks.count == 0) {
340+
return;
341+
}
342+
343+
AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init];
344+
reattributionBuilder.deeplinkParameters = adjustDeepLinks;
345+
[self injectGeneralAttributes:reattributionBuilder];
346+
AIActivityPackage *reattributionPackage = [reattributionBuilder buildReattributionPackage];
347+
[self.packageHandler addPackage:reattributionPackage];
348+
[self.packageHandler sendFirstPackage];
349+
350+
[self.logger debug:@"Reattribution %@", adjustDeepLinks];
346351
}
347352

348353
#pragma mark - private

0 commit comments

Comments
 (0)