From 99c1462c71edf463f4000875c5b2c1b68bc6ecb7 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Wed, 20 Nov 2013 17:37:21 +0100 Subject: [PATCH 1/5] Add special method setSdkPrefix for SDK wrappers --- AdjustIo/AIActivityHandler.h | 1 + AdjustIo/AIActivityHandler.m | 6 +++++- AdjustIo/AdjustIo.h | 28 ++++++++++++++++++++++------ AdjustIo/AdjustIo.m | 4 ++++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/AdjustIo/AIActivityHandler.h b/AdjustIo/AIActivityHandler.h index 8421c577d..0de2f7a40 100644 --- a/AdjustIo/AIActivityHandler.h +++ b/AdjustIo/AIActivityHandler.h @@ -15,6 +15,7 @@ + (AIActivityHandler *)handlerWithAppToken:(NSString *)appToken; - (id)initWithAppToken:(NSString *)appToken; +- (void)setSdkPrefix:(NSString *)sdkPrefix; - (void)trackSubsessionStart; - (void)trackSubsessionEnd; diff --git a/AdjustIo/AIActivityHandler.m b/AdjustIo/AIActivityHandler.m index e72c9a9ad..d225fe748 100644 --- a/AdjustIo/AIActivityHandler.m +++ b/AdjustIo/AIActivityHandler.m @@ -60,6 +60,7 @@ - (id)initWithAppToken:(NSString *)yourAppToken { [self addNotificationObserver]; self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); self.environment = @"unknown"; // default value + self.clientSdk = AIUtil.clientSdk; dispatch_async(self.internalQueue, ^{ [self initInternal:yourAppToken]; @@ -68,6 +69,10 @@ - (id)initWithAppToken:(NSString *)yourAppToken { return self; } +- (void)setSdkPrefix:(NSString *)sdkPrefix { + self.clientSdk = [NSString stringWithFormat:@"%@@%@", sdkPrefix, self.clientSdk]; +} + - (void)trackSubsessionStart { dispatch_async(self.internalQueue, ^{ [self startInternal]; @@ -112,7 +117,6 @@ - (void)initInternal:(NSString *)yourAppToken { self.idForAdvertisers = UIDevice.currentDevice.aiIdForAdvertisers; self.fbAttributionId = UIDevice.currentDevice.aiFbAttributionId; self.userAgent = AIUtil.userAgent; - self.clientSdk = AIUtil.clientSdk; self.packageHandler = [[AIPackageHandler alloc] init]; [self readActivityState]; diff --git a/AdjustIo/AdjustIo.h b/AdjustIo/AdjustIo.h index 66982fc6b..b8f8dbd57 100644 --- a/AdjustIo/AdjustIo.h +++ b/AdjustIo/AdjustIo.h @@ -8,7 +8,9 @@ #import "AILogger.h" -// TODO: add comment +/** + * Constants for our supported tracking environments. + */ static NSString * const AIEnvironmentSandbox = @"sandbox"; static NSString * const AIEnvironmentProduction = @"production"; @@ -65,13 +67,24 @@ static NSString * const AIEnvironmentProduction = @"production"; + (void)trackRevenue:(double)amountInCents forEvent:(NSString *)eventToken; + (void)trackRevenue:(double)amountInCents forEvent:(NSString *)eventToken withParameters:(NSDictionary *)parameters; -// TODO: add comment -// sets logLevel to Assert -// should be called after appDidLaunch and setLogLevel +/** + * Set the tracking environment to sandbox or production. + * + * Use sandbox for testing and production for the final build that you release. + * + * @param environment The new environment. Supported values: + * - AIEnvironmentSandbox + * - AIEnvironmentProduction + */ + (void)setEnvironment:(NSString *)environment; -// TODO: add comment -// should be called after appDidLaunch +/** + * Enable or disable event buffering. + * + * Enable event buffering if your app triggers a lot of events. + * When enabled, events get buffered and only get tracked each + * minute. Buffered events are still persisted, of course. + */ + (void)setEventBufferingEnabled:(BOOL)enabled; /** @@ -91,4 +104,7 @@ static NSString * const AIEnvironmentProduction = @"production"; */ + (void)setLogLevel:(AILogLevel)logLevel; +// Special method used by SDK wrappers such as Adobe Air SDK. ++ (void)setSdkPrefix:(NSString *)sdkPrefix __attribute__((deprecated)); + @end diff --git a/AdjustIo/AdjustIo.m b/AdjustIo/AdjustIo.m index 16bb085a9..6351e6cf2 100644 --- a/AdjustIo/AdjustIo.m +++ b/AdjustIo/AdjustIo.m @@ -24,6 +24,10 @@ + (void)appDidLaunch:(NSString *)yourAppToken { activityHandler = [AIActivityHandler handlerWithAppToken:yourAppToken]; } ++ (void)setSdkPrefix:(NSString *)sdkPrefix { + [activityHandler setSdkPrefix:sdkPrefix]; +} + + (void)trackEvent:(NSString *)eventToken { [activityHandler trackEvent:eventToken withParameters:nil]; } From ceb129905a963338088ffbcf48c0958bdf9682b9 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Wed, 20 Nov 2013 18:56:23 +0100 Subject: [PATCH 2/5] Remove unnecessary semicolon --- AdjustIo/AIUtil.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdjustIo/AIUtil.m b/AdjustIo/AIUtil.m index 6bdf52c76..0181ed8fb 100644 --- a/AdjustIo/AIUtil.m +++ b/AdjustIo/AIUtil.m @@ -58,7 +58,7 @@ + (NSString *)sanitizeZ:(NSString *)string { return [self.class sanitize:string defaultString:@"zz"]; } -+ (NSString *)sanitize:(NSString *)string defaultString:(NSString *)defaultString; { ++ (NSString *)sanitize:(NSString *)string defaultString:(NSString *)defaultString { if (string == nil) { return defaultString; } From ceae1956ae1d17ea91e4d35f08e45d41289e4716 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Wed, 20 Nov 2013 19:31:12 +0100 Subject: [PATCH 3/5] Exclude local files from backups --- AdjustIo/AIActivityHandler.m | 1 + AdjustIo/AIPackageHandler.m | 2 ++ AdjustIo/AIUtil.h | 2 ++ AdjustIo/AIUtil.m | 13 +++++++++++++ 4 files changed, 18 insertions(+) diff --git a/AdjustIo/AIActivityHandler.m b/AdjustIo/AIActivityHandler.m index d225fe748..990d6b2ac 100644 --- a/AdjustIo/AIActivityHandler.m +++ b/AdjustIo/AIActivityHandler.m @@ -303,6 +303,7 @@ - (void)writeActivityState { NSString *filename = [self activityStateFilename]; BOOL result = [NSKeyedArchiver archiveRootObject:self.activityState toFile:filename]; if (result == YES) { + [AIUtil excludeFromBackup:filename]; [AILogger verbose:@"Wrote activity state: %@", self.activityState]; } else { [AILogger error:@"Failed to write activity state"]; diff --git a/AdjustIo/AIPackageHandler.m b/AdjustIo/AIPackageHandler.m index e8308e008..eddb05c88 100644 --- a/AdjustIo/AIPackageHandler.m +++ b/AdjustIo/AIPackageHandler.m @@ -10,6 +10,7 @@ #import "AIRequestHandler.h" #import "AIActivityPackage.h" #import "AILogger.h" +#import "AIUtil.h" static NSString * const kPackageQueueFilename = @"AdjustIoPackageQueue"; static const char * const kInternalQueueName = "io.adjust.PackageQueue"; @@ -145,6 +146,7 @@ - (void)writePackageQueue { NSString *filename = [self packageQueueFilename]; BOOL result = [NSKeyedArchiver archiveRootObject:self.packageQueue toFile:filename]; if (result == YES) { + [AIUtil excludeFromBackup:filename]; [AILogger debug:@"Package handler wrote %d packages", self.packageQueue.count]; } else { [AILogger error:@"Failed to write package queue"]; diff --git a/AdjustIo/AIUtil.h b/AdjustIo/AIUtil.h index 2e9a3a8e7..bda96393d 100644 --- a/AdjustIo/AIUtil.h +++ b/AdjustIo/AIUtil.h @@ -12,4 +12,6 @@ + (NSString *)clientSdk; + (NSString *)userAgent; ++ (void)excludeFromBackup:(NSString *)filename; + @end diff --git a/AdjustIo/AIUtil.m b/AdjustIo/AIUtil.m index 0181ed8fb..48181ac78 100644 --- a/AdjustIo/AIUtil.m +++ b/AdjustIo/AIUtil.m @@ -7,6 +7,7 @@ // #import "AIUtil.h" +#import "AILogger.h" #import "UIDevice+AIAdditions.h" static NSString * const kBaseUrl = @"https://app.adjust.io"; @@ -71,4 +72,16 @@ + (NSString *)sanitize:(NSString *)string defaultString:(NSString *)defaultStrin return result; } ++ (void)excludeFromBackup:(NSString *)path { + NSURL *url = [NSURL fileURLWithPath:path]; + NSError *error = nil; + BOOL success = [url setResourceValue:[NSNumber numberWithBool:YES] + forKey:NSURLIsExcludedFromBackupKey + error:&error]; + + if (!success) { + [AILogger debug:@"Failed to exclude '%@' from backup (%@)", url.lastPathComponent, error.localizedDescription]; + } +} + @end From 190c456ffe0b6a3bda0af68a30058267eab390f4 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Thu, 21 Nov 2013 14:44:02 +0100 Subject: [PATCH 4/5] Remove unused NSMutableDictionary additions --- .../NSMutableDictionary+AIAdditions.h | 17 ----------- .../NSMutableDictionary+AIAdditions.m | 29 ------------------- 2 files changed, 46 deletions(-) delete mode 100644 AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.h delete mode 100644 AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.m diff --git a/AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.h b/AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.h deleted file mode 100644 index 3167edd64..000000000 --- a/AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// NSMutableDictionary.h -// AdjustIosApp -// -// Created by Christian Wellenbrock on 03.06.13. -// Copyright (c) 2013 adeven. All rights reserved. -// - -#import - -@interface NSMutableDictionary(AIAdditions) - -- (void)trySetObject:(id)value forKey:(NSString *)key; -- (void)setInteger:(int)value forKey:(NSString *)key; -- (void)setDate:(NSDate *)date forKey:(NSString *)key; - -@end diff --git a/AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.m b/AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.m deleted file mode 100644 index 92a2c6616..000000000 --- a/AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.m +++ /dev/null @@ -1,29 +0,0 @@ -// -// NSMutableDictionary.m -// AdjustIosApp -// -// Created by Christian Wellenbrock on 03.06.13. -// Copyright (c) 2013 adeven. All rights reserved. -// - -#import "NSMutableDictionary+AIAdditions.h" - -@implementation NSMutableDictionary(AIAdditions) - -- (void)trySetObject:(id)value forKey:(NSString *)key { - if (value != nil) { - [self setObject:value forKey:key]; - } -} - -- (void)setInteger:(int)value forKey:(NSString *)key { - [self setObject:[NSNumber numberWithInt:value] forKey:key]; -} - -- (void)setDate:(NSDate *)date forKey:(NSString *)key { - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZZZZ"; - [self setObject:[formatter stringFromDate:date] forKey:key]; -} - -@end From 1cb73fda8d163203b5459e5da5d123ae39b2a100 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Thu, 21 Nov 2013 14:48:19 +0100 Subject: [PATCH 5/5] Remove unused aiDecodeBase64 --- AdjustIo/AIAdditions/NSString+AIAdditions.h | 1 - AdjustIo/AIAdditions/NSString+AIAdditions.m | 94 --------------------- 2 files changed, 95 deletions(-) diff --git a/AdjustIo/AIAdditions/NSString+AIAdditions.h b/AdjustIo/AIAdditions/NSString+AIAdditions.h index 13a3017aa..af09d2c7a 100644 --- a/AdjustIo/AIAdditions/NSString+AIAdditions.h +++ b/AdjustIo/AIAdditions/NSString+AIAdditions.h @@ -15,6 +15,5 @@ - (NSString *)aiSha1; - (NSString *)aiUrlEncode; - (NSString *)aiRemoveColons; -- (NSData *)aiDecodeBase64; @end diff --git a/AdjustIo/AIAdditions/NSString+AIAdditions.m b/AdjustIo/AIAdditions/NSString+AIAdditions.m index b9a8d7141..9318ae9db 100644 --- a/AdjustIo/AIAdditions/NSString+AIAdditions.m +++ b/AdjustIo/AIAdditions/NSString+AIAdditions.m @@ -54,98 +54,4 @@ - (NSString *)aiRemoveColons { return [self stringByReplacingOccurrencesOfString:@":" withString:@""]; } -static const short _base64DecodingTable[256] = { - -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -2, -1, -1, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, -2, -2, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, -2, -2, -2, - -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, -2, - -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 -}; - -// http://stackoverflow.com/a/4727124 -- (NSData *)aiDecodeBase64 { - const char *objPointer = [self cStringUsingEncoding:NSASCIIStringEncoding]; - size_t intLength = strlen(objPointer); - int intCurrent; - int i = 0, j = 0, k; - - unsigned char *objResult = calloc(intLength, sizeof(unsigned char)); - - // Run through the whole string, converting as we go - while ( ((intCurrent = *objPointer++) != '\0') && (intLength-- > 0) ) { - if (intCurrent == '=') { - if (*objPointer != '=' && ((i % 4) == 1)) {// || (intLength > 0)) { - // the padding character is invalid at this point -- so this entire string is invalid - free(objResult); - return nil; - } - continue; - } - - intCurrent = _base64DecodingTable[intCurrent]; - if (intCurrent == -1) { - // we're at a whitespace -- simply skip over - continue; - } else if (intCurrent == -2) { - // we're at an invalid character - free(objResult); - return nil; - } - - switch (i % 4) { - case 0: - objResult[j] = intCurrent << 2; - break; - - case 1: - objResult[j++] |= intCurrent >> 4; - objResult[j] = (intCurrent & 0x0f) << 4; - break; - - case 2: - objResult[j++] |= intCurrent >>2; - objResult[j] = (intCurrent & 0x03) << 6; - break; - - case 3: - objResult[j++] |= intCurrent; - break; - } - i++; - } - - // mop things up if we ended on a boundary - k = j; - if (intCurrent == '=') { - switch (i % 4) { - case 1: - // Invalid state - free(objResult); - return nil; - - case 2: - k++; - // flow through - case 3: - objResult[k] = 0; - } - } - - // Cleanup and setup the return NSData - NSData * objData = [[NSData alloc] initWithBytes:objResult length:j]; - free(objResult); - return objData; -} - @end