Skip to content

Commit 0c19401

Browse files
committed
Merge pull request #21 from adeven/development
Support for SDK wrappers like Unity and Adobe Air
2 parents b3b8e53 + 1cb73fd commit 0c19401

File tree

11 files changed

+51
-149
lines changed

11 files changed

+51
-149
lines changed

AdjustIo/AIActivityHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

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

1920
- (void)trackSubsessionStart;
2021
- (void)trackSubsessionEnd;

AdjustIo/AIActivityHandler.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ - (id)initWithAppToken:(NSString *)yourAppToken {
6060
[self addNotificationObserver];
6161
self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL);
6262
self.environment = @"unknown"; // default value
63+
self.clientSdk = AIUtil.clientSdk;
6364

6465
dispatch_async(self.internalQueue, ^{
6566
[self initInternal:yourAppToken];
@@ -68,6 +69,10 @@ - (id)initWithAppToken:(NSString *)yourAppToken {
6869
return self;
6970
}
7071

72+
- (void)setSdkPrefix:(NSString *)sdkPrefix {
73+
self.clientSdk = [NSString stringWithFormat:@"%@@%@", sdkPrefix, self.clientSdk];
74+
}
75+
7176
- (void)trackSubsessionStart {
7277
dispatch_async(self.internalQueue, ^{
7378
[self startInternal];
@@ -112,7 +117,6 @@ - (void)initInternal:(NSString *)yourAppToken {
112117
self.idForAdvertisers = UIDevice.currentDevice.aiIdForAdvertisers;
113118
self.fbAttributionId = UIDevice.currentDevice.aiFbAttributionId;
114119
self.userAgent = AIUtil.userAgent;
115-
self.clientSdk = AIUtil.clientSdk;
116120

117121
self.packageHandler = [[AIPackageHandler alloc] init];
118122
[self readActivityState];
@@ -299,6 +303,7 @@ - (void)writeActivityState {
299303
NSString *filename = [self activityStateFilename];
300304
BOOL result = [NSKeyedArchiver archiveRootObject:self.activityState toFile:filename];
301305
if (result == YES) {
306+
[AIUtil excludeFromBackup:filename];
302307
[AILogger verbose:@"Wrote activity state: %@", self.activityState];
303308
} else {
304309
[AILogger error:@"Failed to write activity state"];

AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

AdjustIo/AIAdditions/NSMutableDictionary+AIAdditions.m

Lines changed: 0 additions & 29 deletions
This file was deleted.

AdjustIo/AIAdditions/NSString+AIAdditions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@
1515
- (NSString *)aiSha1;
1616
- (NSString *)aiUrlEncode;
1717
- (NSString *)aiRemoveColons;
18-
- (NSData *)aiDecodeBase64;
1918

2019
@end

AdjustIo/AIAdditions/NSString+AIAdditions.m

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -54,98 +54,4 @@ - (NSString *)aiRemoveColons {
5454
return [self stringByReplacingOccurrencesOfString:@":" withString:@""];
5555
}
5656

57-
static const short _base64DecodingTable[256] = {
58-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -2, -1, -1, -2, -2,
59-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
60-
-1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, -2, -2, 63,
61-
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, -2, -2, -2,
62-
-2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
63-
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, -2,
64-
-2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
65-
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2,
66-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
67-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
68-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
69-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
70-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
71-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
72-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
73-
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2
74-
};
75-
76-
// http://stackoverflow.com/a/4727124
77-
- (NSData *)aiDecodeBase64 {
78-
const char *objPointer = [self cStringUsingEncoding:NSASCIIStringEncoding];
79-
size_t intLength = strlen(objPointer);
80-
int intCurrent;
81-
int i = 0, j = 0, k;
82-
83-
unsigned char *objResult = calloc(intLength, sizeof(unsigned char));
84-
85-
// Run through the whole string, converting as we go
86-
while ( ((intCurrent = *objPointer++) != '\0') && (intLength-- > 0) ) {
87-
if (intCurrent == '=') {
88-
if (*objPointer != '=' && ((i % 4) == 1)) {// || (intLength > 0)) {
89-
// the padding character is invalid at this point -- so this entire string is invalid
90-
free(objResult);
91-
return nil;
92-
}
93-
continue;
94-
}
95-
96-
intCurrent = _base64DecodingTable[intCurrent];
97-
if (intCurrent == -1) {
98-
// we're at a whitespace -- simply skip over
99-
continue;
100-
} else if (intCurrent == -2) {
101-
// we're at an invalid character
102-
free(objResult);
103-
return nil;
104-
}
105-
106-
switch (i % 4) {
107-
case 0:
108-
objResult[j] = intCurrent << 2;
109-
break;
110-
111-
case 1:
112-
objResult[j++] |= intCurrent >> 4;
113-
objResult[j] = (intCurrent & 0x0f) << 4;
114-
break;
115-
116-
case 2:
117-
objResult[j++] |= intCurrent >>2;
118-
objResult[j] = (intCurrent & 0x03) << 6;
119-
break;
120-
121-
case 3:
122-
objResult[j++] |= intCurrent;
123-
break;
124-
}
125-
i++;
126-
}
127-
128-
// mop things up if we ended on a boundary
129-
k = j;
130-
if (intCurrent == '=') {
131-
switch (i % 4) {
132-
case 1:
133-
// Invalid state
134-
free(objResult);
135-
return nil;
136-
137-
case 2:
138-
k++;
139-
// flow through
140-
case 3:
141-
objResult[k] = 0;
142-
}
143-
}
144-
145-
// Cleanup and setup the return NSData
146-
NSData * objData = [[NSData alloc] initWithBytes:objResult length:j];
147-
free(objResult);
148-
return objData;
149-
}
150-
15157
@end

AdjustIo/AIPackageHandler.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "AIRequestHandler.h"
1111
#import "AIActivityPackage.h"
1212
#import "AILogger.h"
13+
#import "AIUtil.h"
1314

1415
static NSString * const kPackageQueueFilename = @"AdjustIoPackageQueue";
1516
static const char * const kInternalQueueName = "io.adjust.PackageQueue";
@@ -145,6 +146,7 @@ - (void)writePackageQueue {
145146
NSString *filename = [self packageQueueFilename];
146147
BOOL result = [NSKeyedArchiver archiveRootObject:self.packageQueue toFile:filename];
147148
if (result == YES) {
149+
[AIUtil excludeFromBackup:filename];
148150
[AILogger debug:@"Package handler wrote %d packages", self.packageQueue.count];
149151
} else {
150152
[AILogger error:@"Failed to write package queue"];

AdjustIo/AIUtil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
+ (NSString *)clientSdk;
1313
+ (NSString *)userAgent;
1414

15+
+ (void)excludeFromBackup:(NSString *)filename;
16+
1517
@end

AdjustIo/AIUtil.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "AIUtil.h"
10+
#import "AILogger.h"
1011
#import "UIDevice+AIAdditions.h"
1112

1213
static NSString * const kBaseUrl = @"https://app.adjust.io";
@@ -58,7 +59,7 @@ + (NSString *)sanitizeZ:(NSString *)string {
5859
return [self.class sanitize:string defaultString:@"zz"];
5960
}
6061

61-
+ (NSString *)sanitize:(NSString *)string defaultString:(NSString *)defaultString; {
62+
+ (NSString *)sanitize:(NSString *)string defaultString:(NSString *)defaultString {
6263
if (string == nil) {
6364
return defaultString;
6465
}
@@ -71,4 +72,16 @@ + (NSString *)sanitize:(NSString *)string defaultString:(NSString *)defaultStrin
7172
return result;
7273
}
7374

75+
+ (void)excludeFromBackup:(NSString *)path {
76+
NSURL *url = [NSURL fileURLWithPath:path];
77+
NSError *error = nil;
78+
BOOL success = [url setResourceValue:[NSNumber numberWithBool:YES]
79+
forKey:NSURLIsExcludedFromBackupKey
80+
error:&error];
81+
82+
if (!success) {
83+
[AILogger debug:@"Failed to exclude '%@' from backup (%@)", url.lastPathComponent, error.localizedDescription];
84+
}
85+
}
86+
7487
@end

AdjustIo/AdjustIo.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
#import "AILogger.h"
1010

11-
// TODO: add comment
11+
/**
12+
* Constants for our supported tracking environments.
13+
*/
1214
static NSString * const AIEnvironmentSandbox = @"sandbox";
1315
static NSString * const AIEnvironmentProduction = @"production";
1416

@@ -65,13 +67,24 @@ static NSString * const AIEnvironmentProduction = @"production";
6567
+ (void)trackRevenue:(double)amountInCents forEvent:(NSString *)eventToken;
6668
+ (void)trackRevenue:(double)amountInCents forEvent:(NSString *)eventToken withParameters:(NSDictionary *)parameters;
6769

68-
// TODO: add comment
69-
// sets logLevel to Assert
70-
// should be called after appDidLaunch and setLogLevel
70+
/**
71+
* Set the tracking environment to sandbox or production.
72+
*
73+
* Use sandbox for testing and production for the final build that you release.
74+
*
75+
* @param environment The new environment. Supported values:
76+
* - AIEnvironmentSandbox
77+
* - AIEnvironmentProduction
78+
*/
7179
+ (void)setEnvironment:(NSString *)environment;
7280

73-
// TODO: add comment
74-
// should be called after appDidLaunch
81+
/**
82+
* Enable or disable event buffering.
83+
*
84+
* Enable event buffering if your app triggers a lot of events.
85+
* When enabled, events get buffered and only get tracked each
86+
* minute. Buffered events are still persisted, of course.
87+
*/
7588
+ (void)setEventBufferingEnabled:(BOOL)enabled;
7689

7790
/**
@@ -91,4 +104,7 @@ static NSString * const AIEnvironmentProduction = @"production";
91104
*/
92105
+ (void)setLogLevel:(AILogLevel)logLevel;
93106

107+
// Special method used by SDK wrappers such as Adobe Air SDK.
108+
+ (void)setSdkPrefix:(NSString *)sdkPrefix __attribute__((deprecated));
109+
94110
@end

0 commit comments

Comments
 (0)