|
19 | 19 | #import "AIAdjustFactory.h"
|
20 | 20 |
|
21 | 21 | static NSString * const kActivityStateFilename = @"AdjustIoActivityState";
|
| 22 | +static NSString * const kAdjustPrefix = @"adjust_"; |
22 | 23 | static const char * const kInternalQueueName = "io.adjust.ActivityQueue";
|
23 | 24 |
|
24 |
| -static const uint64_t kTimerInterval = 60 * NSEC_PER_SEC; // 1 minute |
25 |
| -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 |
26 | 27 |
|
27 | 28 |
|
28 | 29 | #pragma mark -
|
@@ -141,6 +142,12 @@ - (BOOL)isEnabled {
|
141 | 142 | }
|
142 | 143 | }
|
143 | 144 |
|
| 145 | +- (void)readOpenUrl:(NSURL*)url { |
| 146 | + dispatch_async(self.internalQueue, ^{ |
| 147 | + [self readOpenUrlInternal:url]; |
| 148 | + }); |
| 149 | +} |
| 150 | + |
144 | 151 | #pragma mark - internal
|
145 | 152 | - (void)initInternal:(NSString *)yourAppToken {
|
146 | 153 | if (![self checkAppTokenNotNil:yourAppToken]) return;
|
@@ -309,6 +316,40 @@ - (void)revenueInternal:(double)amount
|
309 | 316 | [self.logger debug:@"Event %d (revenue)", self.activityState.eventCount];
|
310 | 317 | }
|
311 | 318 |
|
| 319 | +- (void) readOpenUrlInternal:(NSURL *)url { |
| 320 | + NSArray* queryArray = [url.query componentsSeparatedByString:@"&"]; |
| 321 | + NSMutableDictionary* adjustDeepLinks = [NSMutableDictionary dictionary]; |
| 322 | + |
| 323 | + for (NSString* fieldValuePair in queryArray) { |
| 324 | + NSArray* pairComponents = [fieldValuePair componentsSeparatedByString:@"="]; |
| 325 | + if (pairComponents.count != 2) continue; |
| 326 | + |
| 327 | + NSString* key = [pairComponents objectAtIndex:0]; |
| 328 | + if (![key hasPrefix:kAdjustPrefix]) continue; |
| 329 | + |
| 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; |
| 335 | + |
| 336 | + [adjustDeepLinks setObject:value forKey:keyWOutPrefix]; |
| 337 | + } |
| 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]; |
| 351 | +} |
| 352 | + |
312 | 353 | #pragma mark - private
|
313 | 354 |
|
314 | 355 | // returns whether or not the activity state should be written
|
@@ -358,7 +399,7 @@ - (void)writeActivityState {
|
358 | 399 | BOOL result = [NSKeyedArchiver archiveRootObject:self.activityState toFile:filename];
|
359 | 400 | if (result == YES) {
|
360 | 401 | [AIUtil excludeFromBackup:filename];
|
361 |
| - [self.logger verbose:@"Wrote activity state: %@", self.activityState]; |
| 402 | + [self.logger debug:@"Wrote activity state: %@", self.activityState]; |
362 | 403 | } else {
|
363 | 404 | [self.logger error:@"Failed to write activity state"];
|
364 | 405 | }
|
|
0 commit comments