Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AdjustIo/AIActivityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

+ (AIActivityHandler *)handlerWithAppToken:(NSString *)appToken;
- (id)initWithAppToken:(NSString *)appToken;
- (void)setSdkPrefix:(NSString *)sdkPrefix;

- (void)trackSubsessionStart;
- (void)trackSubsessionEnd;
Expand Down
7 changes: 6 additions & 1 deletion AdjustIo/AIActivityHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -299,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"];
Expand Down
17 changes: 0 additions & 17 deletions AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.h

This file was deleted.

29 changes: 0 additions & 29 deletions AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.m

This file was deleted.

1 change: 0 additions & 1 deletion AdjustIo/AIAdditions/NSString+AIAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
- (NSString *)aiSha1;
- (NSString *)aiUrlEncode;
- (NSString *)aiRemoveColons;
- (NSData *)aiDecodeBase64;

@end
94 changes: 0 additions & 94 deletions AdjustIo/AIAdditions/NSString+AIAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions AdjustIo/AIPackageHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"];
Expand Down
2 changes: 2 additions & 0 deletions AdjustIo/AIUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
+ (NSString *)clientSdk;
+ (NSString *)userAgent;

+ (void)excludeFromBackup:(NSString *)filename;

@end
15 changes: 14 additions & 1 deletion AdjustIo/AIUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "AIUtil.h"
#import "AILogger.h"
#import "UIDevice+AIAdditions.h"

static NSString * const kBaseUrl = @"https://app.adjust.io";
Expand Down Expand Up @@ -58,7 +59,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;
}
Expand All @@ -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
28 changes: 22 additions & 6 deletions AdjustIo/AdjustIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;

/**
Expand All @@ -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
4 changes: 4 additions & 0 deletions AdjustIo/AdjustIo.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down