Skip to content

Commit 01ce064

Browse files
committed
Detection of iAd
1 parent 8a1d1c8 commit 01ce064

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

Adjust.xcodeproj/project.pbxproj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
96325E89190E892000A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
11+
96325E8A190E892600A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
12+
96325E8B190E8D6200A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
13+
96325E8C190E8D6B00A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
1014
9679921118BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; };
1115
9679921F18BBAE2800394606 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921E18BBAE2800394606 /* XCTest.framework */; };
1216
9679922018BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; };
@@ -67,6 +71,8 @@
6771
/* End PBXCopyFilesBuildPhase section */
6872

6973
/* Begin PBXFileReference section */
74+
96325E84190E5CD900A97911 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
75+
96325E86190E5CE400A97911 /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iAd.framework; path = System/Library/Frameworks/iAd.framework; sourceTree = SDKROOT; };
7076
9679920D18BBAE2800394606 /* libAdjust.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAdjust.a; sourceTree = BUILT_PRODUCTS_DIR; };
7177
9679921018BBAE2800394606 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
7278
9679921D18BBAE2800394606 /* AdjustTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AdjustTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -129,6 +135,8 @@
129135
isa = PBXFrameworksBuildPhase;
130136
buildActionMask = 2147483647;
131137
files = (
138+
96325E8A190E892600A97911 /* AdSupport.framework in Frameworks */,
139+
96325E89190E892000A97911 /* iAd.framework in Frameworks */,
132140
9679921118BBAE2800394606 /* Foundation.framework in Frameworks */,
133141
96E5E3B918BBB75F008E7B30 /* XCTest.framework in Frameworks */,
134142
);
@@ -138,6 +146,8 @@
138146
isa = PBXFrameworksBuildPhase;
139147
buildActionMask = 2147483647;
140148
files = (
149+
96325E8C190E8D6B00A97911 /* AdSupport.framework in Frameworks */,
150+
96325E8B190E8D6200A97911 /* iAd.framework in Frameworks */,
141151
9679922518BBAE2800394606 /* libAdjust.a in Frameworks */,
142152
9679921F18BBAE2800394606 /* XCTest.framework in Frameworks */,
143153
9679922218BBAE2800394606 /* UIKit.framework in Frameworks */,
@@ -170,6 +180,8 @@
170180
9679920F18BBAE2800394606 /* Frameworks */ = {
171181
isa = PBXGroup;
172182
children = (
183+
96325E86190E5CE400A97911 /* iAd.framework */,
184+
96325E84190E5CD900A97911 /* AdSupport.framework */,
173185
9679921018BBAE2800394606 /* Foundation.framework */,
174186
9679921E18BBAE2800394606 /* XCTest.framework */,
175187
9679922118BBAE2800394606 /* UIKit.framework */,
@@ -421,8 +433,9 @@
421433
GCC_WARN_UNINITIALIZED_AUTOS = YES;
422434
GCC_WARN_UNUSED_FUNCTION = YES;
423435
GCC_WARN_UNUSED_VARIABLE = YES;
424-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
436+
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
425437
ONLY_ACTIVE_ARCH = YES;
438+
OTHER_CFLAGS = "-DADJUST_NO_IDA";
426439
SDKROOT = iphoneos;
427440
};
428441
name = Debug;
@@ -452,7 +465,8 @@
452465
GCC_WARN_UNINITIALIZED_AUTOS = YES;
453466
GCC_WARN_UNUSED_FUNCTION = YES;
454467
GCC_WARN_UNUSED_VARIABLE = YES;
455-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
468+
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
469+
OTHER_CFLAGS = "-DADJUST_NO_IDA";
456470
SDKROOT = iphoneos;
457471
VALIDATE_PRODUCT = YES;
458472
};
@@ -505,6 +519,7 @@
505519
"$(inherited)",
506520
);
507521
INFOPLIST_FILE = "AdjustTests/AdjustTests-Info.plist";
522+
OTHER_CFLAGS = "-DADJUST_NO_IDA";
508523
PRODUCT_NAME = "$(TARGET_NAME)";
509524
WRAPPER_EXTENSION = xctest;
510525
};
@@ -521,6 +536,7 @@
521536
GCC_PRECOMPILE_PREFIX_HEADER = YES;
522537
GCC_PREFIX_HEADER = "AdjustTests/Adjust-Prefix.pch";
523538
INFOPLIST_FILE = "AdjustTests/AdjustTests-Info.plist";
539+
OTHER_CFLAGS = "-DADJUST_NO_IDA";
524540
PRODUCT_NAME = "$(TARGET_NAME)";
525541
WRAPPER_EXTENSION = xctest;
526542
};

Adjust/AIActivityHandler.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#import "UIDevice+AIAdditions.h"
1818
#import "NSString+AIAdditions.h"
1919
#import "AIAdjustFactory.h"
20+
#if !ADJUST_NO_IDA
21+
#import <iAd/iAd.h>
22+
#endif
2023

2124
static NSString * const kActivityStateFilename = @"AdjustIoActivityState";
2225
static NSString * const kAdjustPrefix = @"adjust_";
@@ -44,6 +47,7 @@ @interface AIActivityHandler()
4447
@property (nonatomic, copy) NSString *clientSdk;
4548
@property (nonatomic, assign) BOOL trackingEnabled;
4649
@property (nonatomic, assign) BOOL internalEnabled;
50+
@property (nonatomic, assign) BOOL isIad;
4751

4852
@end
4953

@@ -164,6 +168,14 @@ - (void)initInternal:(NSString *)yourAppToken {
164168
self.fbAttributionId = UIDevice.currentDevice.aiFbAttributionId;
165169
self.userAgent = AIUtil.userAgent;
166170

171+
#if !ADJUST_NO_IDA
172+
if (NSClassFromString(@"ADClient")) {
173+
[ADClient.sharedClient determineAppInstallationAttributionWithCompletionHandler:^(BOOL appInstallationWasAttributedToiAd) {
174+
self.isIad = appInstallationWasAttributedToiAd;
175+
}];
176+
}
177+
#endif
178+
167179
self.packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:self];
168180
[self readActivityState];
169181

@@ -430,6 +442,7 @@ - (void)injectGeneralAttributes:(AIPackageBuilder *)builder {
430442
builder.idForAdvertisers = self.idForAdvertisers;
431443
builder.fbAttributionId = self.fbAttributionId;
432444
builder.environment = self.environment;
445+
builder.isIad = self.isIad;
433446

434447
if (self.trackMacMd5) {
435448
builder.macShortMd5 = self.macShortMd5;

Adjust/AIPackageBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@property (nonatomic, copy) NSString *clientSdk;
2323
@property (nonatomic, copy) NSString *uuid;
2424
@property (nonatomic, assign) BOOL trackingEnabled;
25+
@property (nonatomic, assign) BOOL isIad;
2526

2627
// sessions
2728
@property (nonatomic, assign) int sessionCount;

Adjust/AIPackageBuilder.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ - (NSMutableDictionary *)defaultParameters {
8888
[self parameters:parameters setString:self.fbAttributionId forKey:@"fb_id"];
8989
[self parameters:parameters setString:self.environment forKey:@"environment"];
9090
[self parameters:parameters setInt:self.trackingEnabled forKey:@"tracking_enabled"];
91+
[self parameters:parameters setBool:self.isIad forKey:@"is_iad"];
9192

9293
// session related (used for events as well)
9394
[self parameters:parameters setInt:self.sessionCount forKey:@"session_count"];
@@ -167,5 +168,12 @@ - (void)parameters:(NSMutableDictionary *)parameters setDictionaryJson:(NSDictio
167168
[self parameters:parameters setString:dictionaryString forKey:key];
168169
}
169170

171+
- (void)parameters:(NSMutableDictionary *)parameters setBool:(BOOL)value forKey:(NSString *)key {
172+
if (value < 0) return;
173+
174+
int valueInt = [[NSNumber numberWithBool:value] intValue];
175+
176+
[self parameters:parameters setInt:valueInt forKey:key];
177+
}
170178
@end
171179

AdjustTests/AIActivityHandlerTests.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ - (void)testFirstRun
112112
// lastInterval -1, same as before
113113
XCTAssertNil(parameters[@"last_interval"], @"%@", activityPackage.extendedString);
114114

115+
// is_iad should be false
116+
XCTAssertEqual(NO, [(NSString *)parameters[@"is_iad"] boolValue], @"%@", activityPackage.extendedString);
117+
118+
// vendorId of the simulator
119+
XCTAssertNotNil((NSString *)parameters[@"idfv"], @"%@", activityPackage.extendedString);
120+
115121
// after adding, the activity handler ping the Package handler to send the package
116122
XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"],
117123
@"%@", self.loggerMock);

0 commit comments

Comments
 (0)