Skip to content

Commit 3036bcb

Browse files
committed
Merge pull request #3 from adeven/newSDKs20140205
New SDKs: adjust_ios_sdk 2.2.0 and adjust_android_sdk 2.1.6
2 parents f378b5c + ad8b9b5 commit 3036bcb

17 files changed

+201
-134
lines changed

src/Assets/AdjustIo/Data/SDK/iOS/AdjustIo/AIActivityHandler.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
@property (nonatomic, copy) NSString *environment;
1414
@property (nonatomic, assign) BOOL bufferEvents;
15+
@property (nonatomic, assign) BOOL trackMacMd5;
1516

1617
+ (AIActivityHandler *)handlerWithAppToken:(NSString *)appToken;
1718
- (id)initWithAppToken:(NSString *)appToken;

src/Assets/AdjustIo/Data/SDK/iOS/AdjustIo/AIActivityHandler.m

+12-6
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ - (id)initWithAppToken:(NSString *)yourAppToken {
5959

6060
[self addNotificationObserver];
6161
self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL);
62-
self.environment = @"unknown"; // default value
6362
self.clientSdk = AIUtil.clientSdk;
6463

64+
// default values
65+
self.environment = @"unknown";
66+
self.trackMacMd5 = YES;
67+
6568
dispatch_async(self.internalQueue, ^{
6669
[self initInternal:yourAppToken];
6770
});
@@ -264,7 +267,7 @@ - (BOOL)updateActivityState {
264267
double lastInterval = now - self.activityState.lastActivity;
265268
if (lastInterval < 0) {
266269
[AILogger error:@"Time travel!"];
267-
self.activityState.lastInterval = now;
270+
self.activityState.lastActivity = now;
268271
return YES;
269272
}
270273

@@ -280,11 +283,11 @@ - (BOOL)updateActivityState {
280283

281284
- (void)readActivityState {
282285
@try {
283-
NSString *filename = [self activityStateFilename];
286+
NSString *filename = self.activityStateFilename;
284287
id object = [NSKeyedUnarchiver unarchiveObjectWithFile:filename];
285288
if ([object isKindOfClass:[AIActivityState class]]) {
286289
self.activityState = object;
287-
[AILogger debug:@"Read activity state: %@", self.activityState];
290+
[AILogger debug:@"Read activity state: %@ uuid:%@", self.activityState, self.activityState.uuid];
288291
return;
289292
} else if (object == nil) {
290293
[AILogger verbose:@"Activity state file not found"];
@@ -300,7 +303,7 @@ - (void)readActivityState {
300303
}
301304

302305
- (void)writeActivityState {
303-
NSString *filename = [self activityStateFilename];
306+
NSString *filename = self.activityStateFilename;
304307
BOOL result = [NSKeyedArchiver archiveRootObject:self.activityState toFile:filename];
305308
if (result == YES) {
306309
[AIUtil excludeFromBackup:filename];
@@ -330,12 +333,15 @@ - (void)injectGeneralAttributes:(AIPackageBuilder *)builder {
330333
builder.userAgent = self.userAgent;
331334
builder.clientSdk = self.clientSdk;
332335
builder.appToken = self.appToken;
333-
builder.macShortMd5 = self.macShortMd5;
334336
builder.macSha1 = self.macSha1;
335337
builder.trackingEnabled = self.trackingEnabled;
336338
builder.idForAdvertisers = self.idForAdvertisers;
337339
builder.fbAttributionId = self.fbAttributionId;
338340
builder.environment = self.environment;
341+
342+
if (self.trackMacMd5) {
343+
builder.macShortMd5 = self.macShortMd5;
344+
}
339345
}
340346

341347
# pragma mark - timer

src/Assets/AdjustIo/Data/SDK/iOS/AdjustIo/AIActivityState.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
@interface AIActivityState : NSObject <NSCoding>
1212

13+
// persistent data
14+
@property (nonatomic, copy) NSString *uuid;
15+
1316
// global counters
1417
@property (nonatomic, assign) int eventCount;
1518
@property (nonatomic, assign) int sessionCount;
@@ -19,11 +22,12 @@
1922
@property (nonatomic, assign) double sessionLength; // all durations in seconds
2023
@property (nonatomic, assign) double timeSpent;
2124
@property (nonatomic, assign) double lastActivity; // all times in seconds since 1970
22-
2325
@property (nonatomic, assign) double createdAt;
26+
27+
// not persisted, only injected
2428
@property (nonatomic, assign) double lastInterval;
2529

26-
- (void)resetSessionAttributes:(long)now;
30+
- (void)resetSessionAttributes:(double)now;
2731

2832
- (void)injectSessionAttributes:(AIPackageBuilder *)packageBilder;
2933
- (void)injectEventAttributes:(AIPackageBuilder *)packageBilder;

src/Assets/AdjustIo/Data/SDK/iOS/AdjustIo/AIActivityState.m

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "AIActivityState.h"
1010
#import "AIPackageBuilder.h"
11+
#import "UIDevice+AIAdditions.h"
1112

1213

1314
#pragma mark public implementation
@@ -17,6 +18,9 @@ - (id)init {
1718
self = [super init];
1819
if (self == nil) return nil;
1920

21+
// create UUID for new devices
22+
self.uuid = [UIDevice.currentDevice aiCreateUuid];
23+
2024
self.eventCount = 0;
2125
self.sessionCount = 0;
2226
self.subsessionCount = -1; // -1 means unknown
@@ -29,7 +33,7 @@ - (id)init {
2933
return self;
3034
}
3135

32-
- (void)resetSessionAttributes:(long)now {
36+
- (void)resetSessionAttributes:(double)now {
3337
self.subsessionCount = 1;
3438
self.sessionLength = 0;
3539
self.timeSpent = 0;
@@ -67,6 +71,12 @@ - (id)initWithCoder:(NSCoder *)decoder {
6771
self.timeSpent = [decoder decodeDoubleForKey:@"timeSpent"];
6872
self.createdAt = [decoder decodeDoubleForKey:@"createdAt"];
6973
self.lastActivity = [decoder decodeDoubleForKey:@"lastActivity"];
74+
self.uuid = [decoder decodeObjectForKey:@"uuid"];
75+
76+
// create UUID for migrating devices
77+
if (self.uuid == nil) {
78+
self.uuid = [UIDevice.currentDevice aiCreateUuid];
79+
}
7080

7181
self.lastInterval = -1;
7282

@@ -81,6 +91,7 @@ - (void)encodeWithCoder:(NSCoder *)encoder {
8191
[encoder encodeDouble:self.timeSpent forKey:@"timeSpent"];
8292
[encoder encodeDouble:self.createdAt forKey:@"createdAt"];
8393
[encoder encodeDouble:self.lastActivity forKey:@"lastActivity"];
94+
[encoder encodeObject:self.uuid forKey:@"uuid"];
8495
}
8596

8697

@@ -92,6 +103,7 @@ - (void)injectGeneralAttributes:(AIPackageBuilder *)builder {
92103
builder.sessionLength = self.sessionLength;
93104
builder.timeSpent = self.timeSpent;
94105
builder.createdAt = self.createdAt;
106+
builder.uuid = self.uuid;
95107
}
96108

97109
@end

src/Assets/AdjustIo/Data/SDK/iOS/AdjustIo/AIAdditions/NSString+AIAdditions.h

+2
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
- (NSString *)aiUrlEncode;
1717
- (NSString *)aiRemoveColons;
1818

19+
+ (NSString *)aiJoin:(NSString *)strings, ...;
20+
1921
@end

src/Assets/AdjustIo/Data/SDK/iOS/AdjustIo/AIAdditions/NSString+AIAdditions.m

+14
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,18 @@ - (NSString *)aiRemoveColons {
5454
return [self stringByReplacingOccurrencesOfString:@":" withString:@""];
5555
}
5656

57+
+ (NSString *)aiJoin:(NSString *)first, ... {
58+
NSString *iter, *result = first;
59+
va_list strings;
60+
va_start(strings, first);
61+
62+
while ((iter = va_arg(strings, NSString*))) {
63+
NSString *capitalized = iter.capitalizedString;
64+
result = [result stringByAppendingString:capitalized];
65+
}
66+
67+
va_end(strings);
68+
return result;
69+
}
70+
5771
@end

src/Assets/AdjustIo/Data/SDK/iOS/AdjustIo/AIAdditions/UIDevice+AIAdditions.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
- (NSString *)aiMacAddress;
1717
- (NSString *)aiDeviceType;
1818
- (NSString *)aiDeviceName;
19+
- (NSString *)aiCreateUuid;
1920

2021
@end

src/Assets/AdjustIo/Data/SDK/iOS/AdjustIo/AIAdditions/UIDevice+AIAdditions.m

+64-7
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,74 @@
99
#import "UIDevice+AIAdditions.h"
1010
#import "NSString+AIAdditions.h"
1111

12-
#import <AdSupport/ASIdentifierManager.h>
1312
#import <sys/socket.h>
1413
#import <sys/sysctl.h>
1514
#import <net/if.h>
1615
#import <net/if_dl.h>
1716

17+
#if !ADJUST_NO_IDFA
18+
#import <AdSupport/ASIdentifierManager.h>
19+
#endif
20+
1821
@implementation UIDevice(AIAdditions)
1922

2023
- (BOOL)aiTrackingEnabled {
21-
if (NSClassFromString(@"ASIdentifierManager")) {
22-
return ASIdentifierManager.sharedManager.advertisingTrackingEnabled;
23-
} else {
24+
#if !ADJUST_NO_IDFA
25+
NSString *className = [NSString aiJoin:@"A", @"S", @"identifier", @"manager", nil];
26+
NSString *keyManager = [NSString aiJoin:@"shared", @"manager", nil];
27+
NSString *keyEnabled = [NSString aiJoin:@"is", @"advertising", @"tracking", @"enabled", nil];
28+
29+
Class class = NSClassFromString(className);
30+
if (class) {
31+
@try {
32+
SEL selManager = NSSelectorFromString(keyManager);
33+
SEL selEnabled = NSSelectorFromString(keyEnabled);
34+
35+
#pragma clang diagnostic push
36+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
37+
id manager = [class performSelector:selManager];
38+
BOOL enabled = (BOOL)[manager performSelector:selEnabled];
39+
#pragma clang diagnostic pop
40+
41+
return enabled;
42+
} @catch (NSException *e) {
43+
return NO;
44+
}
45+
} else
46+
#endif
47+
{
2448
return NO;
2549
}
2650
}
2751

2852
- (NSString *)aiIdForAdvertisers {
29-
if (NSClassFromString(@"ASIdentifierManager")) {
30-
return ASIdentifierManager.sharedManager.advertisingIdentifier.UUIDString;
31-
} else {
53+
#if !ADJUST_NO_IDFA
54+
NSString *className = [NSString aiJoin:@"A", @"S", @"identifier", @"manager", nil];
55+
NSString *keyManager = [NSString aiJoin:@"shared", @"manager", nil];
56+
NSString *keyIdentifier = [NSString aiJoin:@"advertising", @"identifier", nil];
57+
NSString *keyString = [NSString aiJoin:@"UUID", @"string", nil];
58+
59+
Class class = NSClassFromString(className);
60+
if (class) {
61+
@try {
62+
SEL selManager = NSSelectorFromString(keyManager);
63+
SEL selIdentifier = NSSelectorFromString(keyIdentifier);
64+
SEL selString = NSSelectorFromString(keyString);
65+
66+
#pragma clang diagnostic push
67+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
68+
id manager = [class performSelector:selManager];
69+
id identifier = [manager performSelector:selIdentifier];
70+
NSString *string = [identifier performSelector:selString];
71+
#pragma clang diagnostic pop
72+
73+
return string;
74+
} @catch (NSException *e) {
75+
return @"";
76+
}
77+
} else
78+
#endif
79+
{
3280
return @"";
3381
}
3482
}
@@ -101,4 +149,13 @@ - (NSString *)aiDeviceName {
101149
return machine;
102150
}
103151

152+
- (NSString *)aiCreateUuid {
153+
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
154+
CFStringRef stringRef = CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
155+
NSString *uuidString = (__bridge_transfer NSString*)stringRef;
156+
NSString *lowerUuid = [uuidString lowercaseString];
157+
CFRelease(newUniqueId);
158+
return lowerUuid;
159+
}
160+
104161
@end

src/Assets/AdjustIo/Data/SDK/iOS/AdjustIo/AILogger.h

+1-15
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,13 @@ typedef enum {
1818
// A simple logger with multiple log levels.
1919
@interface AILogger : NSObject
2020

21-
@property (copy) NSString *logTag;
22-
@property (assign) AILogLevel logLevel;
23-
24-
// convenience methods
25-
+ (void)setLogTag:(NSString *)logTag;
2621
+ (void)setLogLevel:(AILogLevel)logLevel;
22+
2723
+ (void)verbose:(NSString *)message, ...;
2824
+ (void)debug: (NSString *)message, ...;
2925
+ (void)info: (NSString *)message, ...;
3026
+ (void)warn: (NSString *)message, ...;
3127
+ (void)error: (NSString *)message, ...;
3228
+ (void)assert: (NSString *)message, ...;
3329

34-
+ (AILogger *)loggerWithTag:(NSString *)logTag;
35-
- (id)initWithTag:(NSString *)logTag;
36-
37-
- (void)verbose:(NSString *)message, ...;
38-
- (void)debug: (NSString *)message, ...;
39-
- (void)info: (NSString *)message, ...;
40-
- (void)warn: (NSString *)message, ...;
41-
- (void)error: (NSString *)message, ...;
42-
- (void)assert: (NSString *)message, ...;
43-
4430
@end

0 commit comments

Comments
 (0)