Skip to content

Commit

Permalink
Merge pull request #263 from adjust/v4110
Browse files Browse the repository at this point in the history
Version 4.11.0
  • Loading branch information
uerceg authored Dec 27, 2016
2 parents cfe173a + 1ed5b3c commit 87aca45
Show file tree
Hide file tree
Showing 45 changed files with 618 additions and 412 deletions.
4 changes: 2 additions & 2 deletions Adjust.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "Adjust"
s.version = "4.10.3"
s.version = "4.11.0"
s.summary = "This is the iOS SDK of adjust. You can read more about it at http://adjust.com."
s.homepage = "https://github.com/adjust/ios_sdk"
s.license = { :type => 'MIT', :file => 'MIT-LICENSE' }
s.author = { "Christian Wellenbrock" => "welle@adjust.com" }
s.source = { :git => "https://github.com/adjust/ios_sdk.git", :tag => "v4.10.3" }
s.source = { :git => "https://github.com/adjust/ios_sdk.git", :tag => "v4.11.0" }
s.ios.deployment_target = '6.0'
s.tvos.deployment_target = '9.0'
s.framework = 'SystemConfiguration'
Expand Down
80 changes: 80 additions & 0 deletions Adjust.xcodeproj/xcshareddata/xcschemes/AdjustSdkTv.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9DFB060F1D747070006D48FC"
BuildableName = "AdjustSdkTv.framework"
BlueprintName = "AdjustSdkTv"
ReferencedContainer = "container:Adjust.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9DFB060F1D747070006D48FC"
BuildableName = "AdjustSdkTv.framework"
BlueprintName = "AdjustSdkTv"
ReferencedContainer = "container:Adjust.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9DFB060F1D747070006D48FC"
BuildableName = "AdjustSdkTv.framework"
BlueprintName = "AdjustSdkTv"
ReferencedContainer = "container:Adjust.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
12 changes: 6 additions & 6 deletions Adjust/ADJActivityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
@property (nonatomic, assign) BOOL background;
@property (nonatomic, assign) BOOL delayStart;
@property (nonatomic, assign) BOOL updatePackages;
@property (nonatomic, copy) NSData* deviceToken;

- (id)init;

Expand All @@ -34,6 +33,9 @@

@protocol ADJActivityHandler <NSObject>

@property (nonatomic, copy) ADJAttribution *attribution;
- (NSString *)adid;

- (id)initWithConfig:(ADJConfig *)adjustConfig
sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray
deviceToken:(NSData*)deviceToken;
Expand All @@ -53,14 +55,13 @@ sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray
- (void)appWillOpenUrl:(NSURL*)url;
- (void)setDeviceToken:(NSData *)deviceToken;

- (void)setAttribution:(ADJAttribution*)attribution;
- (void)setAskingAttribution:(BOOL)askingAttribution;

- (BOOL)updateAttributionI:(id<ADJActivityHandler>)selfI attribution:(ADJAttribution *)attribution;
- (void)setIadDate:(NSDate*)iAdImpressionDate withPurchaseDate:(NSDate*)appPurchaseDate;
- (void)setIadDetails:(NSDictionary *)attributionDetails
error:(NSError *)error
retriesLeft:(int)retriesLeft;
- (void)setAttributionDetails:(NSDictionary *)attributionDetails
error:(NSError *)error
retriesLeft:(int)retriesLeft;

- (void)setOfflineMode:(BOOL)offline;
- (ADJInternalState*) internalState;
Expand All @@ -83,7 +84,6 @@ sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray
+ (id<ADJActivityHandler>)handlerWithConfig:(ADJConfig *)adjustConfig
sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray
deviceToken:(NSData*)deviceToken;
- (ADJAttribution*) attribution;

- (void)addSessionCallbackParameterI:(ADJActivityHandler *)selfI
key:(NSString *)key
Expand Down
128 changes: 104 additions & 24 deletions Adjust/ADJActivityHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ @interface ADJActivityHandler()
@property (nonatomic, weak) id<ADJLogger> logger;
@property (nonatomic, weak) NSObject<AdjustDelegate> *adjustDelegate;
// copy for objects shared with the user
@property (nonatomic, copy) ADJAttribution *attribution;
@property (nonatomic, copy) ADJConfig *adjustConfig;
@property (nonatomic, copy) NSData* deviceTokenData;

@end

Expand All @@ -97,6 +97,8 @@ typedef NS_ENUM(NSInteger, AdjADClientError) {
#pragma mark -
@implementation ADJActivityHandler

@synthesize attribution = _attribution;

+ (id<ADJActivityHandler>)handlerWithConfig:(ADJConfig *)adjustConfig
sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray
deviceToken:(NSData*)deviceToken
Expand Down Expand Up @@ -156,7 +158,7 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig
} else {
self.internalState.updatePackages = self.activityState.updatePackages;
}
self.internalState.deviceToken = deviceToken;
self.deviceTokenData = deviceToken;

self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL);
[ADJUtil launchInQueue:self.internalQueue
Expand Down Expand Up @@ -318,6 +320,13 @@ - (BOOL)isEnabled {
return [self isEnabledI:self];
}

- (NSString *)adid {
if (self.activityState == nil) {
return nil;
}
return self.activityState.adid;
}

- (BOOL)hasChangedState:(BOOL)previousState
nextState:(BOOL)nextState
trueMessage:(NSString *)trueMessage
Expand Down Expand Up @@ -401,9 +410,9 @@ - (void)setIadDate:(NSDate *)iAdImpressionDate withPurchaseDate:(NSDate *)appPur
[self.sdkClickHandler sendSdkClick:clickPackage];
}

- (void)setIadDetails:(NSDictionary *)attributionDetails
error:(NSError *)error
retriesLeft:(int)retriesLeft
- (void)setAttributionDetails:(NSDictionary *)attributionDetails
error:(NSError *)error
retriesLeft:(int)retriesLeft
{
if (![ADJUtil isNull:error]) {
[self.logger warn:@"Unable to read iAd details"];
Expand All @@ -422,23 +431,67 @@ - (void)setIadDetails:(NSDictionary *)attributionDetails
return;
}

if ([ADJUtil isNull:attributionDetails]) {
// check if it's a valid attribution details
if (![ADJUtil checkAttributionDetails:attributionDetails]) {
return;
}

double now = [NSDate.date timeIntervalSince1970];
ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc]
initWithDeviceInfo:self.deviceInfo
activityState:self.activityState
config:self.adjustConfig
createdAt:now];
// send immediately if there is no previous attribution details
if (self.activityState == nil ||
self.activityState.attributionDetails == nil)
{
// send immediately
[self sendIad3ClickPackage:self attributionDetails:attributionDetails];
// save in the background queue
[ADJUtil launchInQueue:self.internalQueue
selfInject:self
block:^(ADJActivityHandler * selfI) {
[selfI saveAttributionDetailsI:selfI
attributionDetails:attributionDetails];

}];
return;
}

clickBuilder.iadDetails = attributionDetails;
// check if new updates previous written one
[ADJUtil launchInQueue:self.internalQueue
selfInject:self
block:^(ADJActivityHandler * selfI) {
if ([attributionDetails isEqualToDictionary:selfI.activityState.attributionDetails]) {
return;
}

ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad3"];
[self.sdkClickHandler sendSdkClick:clickPackage];
[selfI sendIad3ClickPackage:selfI attributionDetails:attributionDetails];

// save new iAd details
[selfI saveAttributionDetailsI:selfI
attributionDetails:attributionDetails];
}];
}

- (void)sendIad3ClickPackage:(ADJActivityHandler *)selfI
attributionDetails:(NSDictionary *)attributionDetails
{
double now = [NSDate.date timeIntervalSince1970];
ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc]
initWithDeviceInfo:selfI.deviceInfo
activityState:selfI.activityState
config:selfI.adjustConfig
createdAt:now];

clickBuilder.attributionDetails = attributionDetails;

ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad3"];
[selfI.sdkClickHandler sendSdkClick:clickPackage];
}

- (void)saveAttributionDetailsI:(ADJActivityHandler *)selfI
attributionDetails:(NSDictionary *)attributionDetails
{
// save new iAd details
selfI.activityState.attributionDetails = attributionDetails;
[selfI writeAttributionI:selfI];
}

- (void)setAskingAttribution:(BOOL)askingAttribution {
[self writeActivityStateS:self changesInStateBlock:^{
Expand Down Expand Up @@ -595,6 +648,13 @@ - (void)initI:(ADJActivityHandler *)selfI
[selfI.logger info:@"Default tracker: '%@'", selfI.adjustConfig.defaultTracker];
}

if (selfI.deviceTokenData != nil) {
[selfI.logger info:@"Push token: '%@'", selfI.deviceTokenData];
if (selfI.activityState != nil) {
[selfI setDeviceToken:selfI.deviceTokenData];
}
}

selfI.foregroundTimer = [ADJTimerCycle timerWithBlock:^{
[selfI foregroundTimerFired];
}
Expand Down Expand Up @@ -675,7 +735,7 @@ - (void)processSessionI:(ADJActivityHandler *)selfI {
if (selfI.activityState == nil) {
selfI.activityState = [[ADJActivityState alloc] init];
selfI.activityState.sessionCount = 1; // this is the first session
selfI.activityState.deviceToken = [ADJUtil convertDeviceToken:self.internalState.deviceToken];
selfI.activityState.deviceToken = [ADJUtil convertDeviceToken:selfI.deviceTokenData];

[selfI transferSessionPackageI:selfI now:now];
[selfI.activityState resetSessionAttributes:now];
Expand Down Expand Up @@ -795,6 +855,8 @@ - (void)eventI:(ADJActivityHandler *)selfI

- (void)launchEventResponseTasksI:(ADJActivityHandler *)selfI
eventResponseData:(ADJEventResponseData *)eventResponseData {
[selfI updateAdidI:selfI adid:eventResponseData.adid];

// event success callback
if (eventResponseData.success
&& [selfI.adjustDelegate respondsToSelector:@selector(adjustEventTrackingSucceeded:)])
Expand All @@ -819,6 +881,8 @@ - (void)launchEventResponseTasksI:(ADJActivityHandler *)selfI

- (void)launchSessionResponseTasksI:(ADJActivityHandler *)selfI
sessionResponseData:(ADJSessionResponseData *)sessionResponseData {
[selfI updateAdidI:selfI adid:sessionResponseData.adid];

BOOL toLaunchAttributionDelegate = [selfI updateAttributionI:selfI attribution:sessionResponseData.attribution];

// session success callback
Expand Down Expand Up @@ -851,6 +915,8 @@ - (void)launchSessionResponseTasksI:(ADJActivityHandler *)selfI

- (void)launchAttributionResponseTasksI:(ADJActivityHandler *)selfI
attributionResponseData:(ADJAttributionResponseData *)attributionResponseData {
[selfI updateAdidI:selfI adid:attributionResponseData.adid];

BOOL toLaunchAttributionDelegate = [selfI updateAttributionI:selfI
attribution:attributionResponseData.attribution];

Expand Down Expand Up @@ -890,6 +956,20 @@ - (void)prepareDeeplinkI:(ADJActivityHandler *)selfI
}];
}

- (void)updateAdidI:(ADJActivityHandler *)selfI
adid:(NSString *)adid {
if (adid == nil) {
return;
}

if ([adid isEqualToString:selfI.activityState.adid]) {
return;
}

selfI.activityState.adid = adid;
[selfI writeActivityStateI:selfI];
}

- (BOOL)updateAttributionI:(ADJActivityHandler *)selfI
attribution:(ADJAttribution *)attribution {
if (attribution == nil) {
Expand Down Expand Up @@ -1018,22 +1098,22 @@ - (void)setDeviceTokenI:(ADJActivityHandler *)selfI
return;
}

// save new push token
selfI.activityState.deviceToken = deviceTokenString;
[selfI writeActivityStateI:selfI];

// send info package
double now = [NSDate.date timeIntervalSince1970];
ADJPackageBuilder * infoBuilder = [[ADJPackageBuilder alloc]
initWithDeviceInfo:selfI.deviceInfo
activityState:selfI.activityState
config:selfI.adjustConfig
createdAt:now];

infoBuilder.deviceToken = deviceTokenString;
ADJActivityPackage * infoPackage = [infoBuilder buildInfoPackage:@"push"];

ADJActivityPackage * clickPackage = [infoBuilder buildInfoPackage:@"push"];

[selfI.sdkClickHandler sendSdkClick:clickPackage];

// save new push token
selfI.activityState.deviceToken = deviceTokenString;
[selfI writeActivityStateI:selfI];
[selfI.packageHandler addPackage:infoPackage];
[selfI.packageHandler sendFirstPackage];
}

#pragma mark - private
Expand Down
3 changes: 3 additions & 0 deletions Adjust/ADJActivityState.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
@property (nonatomic, copy) NSString *deviceToken;
@property (nonatomic, assign) BOOL updatePackages;

@property (nonatomic, copy) NSString *adid;
@property (nonatomic, strong) NSDictionary *attributionDetails;

// Global counters
@property (nonatomic, assign) int eventCount;
@property (nonatomic, assign) int sessionCount;
Expand Down
Loading

0 comments on commit 87aca45

Please sign in to comment.