From 581f80d91cc9eeff1f7da3ad1b6176fad46544e8 Mon Sep 17 00:00:00 2001 From: nonelse Date: Fri, 5 May 2017 18:39:12 +0200 Subject: [PATCH 01/74] Fix api changes in unit tests --- AdjustTests/ADJActivityHandlerMock.m | 29 ++++++++++++++++++++++----- AdjustTests/ADJActivityHandlerTests.m | 11 ++-------- AdjustTests/ADJPackageHandlerTests.m | 2 +- AdjustTests/ADJRequestHandlerMock.m | 2 +- AdjustTests/ADJTest.h | 2 +- AdjustTests/ADJTestActivityPackage.m | 3 +-- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/AdjustTests/ADJActivityHandlerMock.m b/AdjustTests/ADJActivityHandlerMock.m index 9020bf376..62431442e 100644 --- a/AdjustTests/ADJActivityHandlerMock.m +++ b/AdjustTests/ADJActivityHandlerMock.m @@ -16,6 +16,8 @@ @interface ADJActivityHandlerMock() @property (nonatomic, strong) ADJLoggerMock *loggerMock; @property (nonatomic, retain) ADJResponseData * lastResponseData; +@property (nonatomic, strong) NSArray *sessionParametersActionsArray; +@property (nonatomic, copy) NSData * deviceToken; @end @@ -23,13 +25,17 @@ @implementation ADJActivityHandlerMock - (id)initWithConfig:(ADJConfig *)adjustConfig sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray + deviceToken:(NSData*)deviceToken { self = [super init]; if (self == nil) return nil; self.loggerMock = (ADJLoggerMock *) [ADJAdjustFactory logger]; - [self.loggerMock test:[prefix stringByAppendingFormat:@"initWithConfig, %@", sessionParametersActionsArray]]; + self.sessionParametersActionsArray = sessionParametersActionsArray; + self.deviceToken = deviceToken; + + [self.loggerMock test:[prefix stringByAppendingFormat:@"initWithConfig"]]; return self; } @@ -61,6 +67,13 @@ - (void)launchSessionResponseTasks:(ADJSessionResponseData *)sessionResponseData self.lastResponseData = sessionResponseData; } +- (void)launchSdkClickResponseTasks:(ADJSdkClickResponseData *)sdkClickResponseData +{ + [self.loggerMock test:[prefix stringByAppendingFormat:@"launchSdkClickResponseTasks, %@", sdkClickResponseData]]; + self.lastResponseData = sdkClickResponseData; +} + + - (void)launchAttributionResponseTasks:(ADJAttributionResponseData *)attributionResponseData { [self.loggerMock test:[prefix stringByAppendingFormat:@"launchAttributionResponseTasks, %@", attributionResponseData]]; self.lastResponseData = attributionResponseData; @@ -106,10 +119,11 @@ - (void) setIadDate:(NSDate*)iAdImpressionDate withPurchaseDate:(NSDate*)appPurc [self.loggerMock test:[prefix stringByAppendingFormat:@"setIadDate, iAdImpressionDate %@ appPurchaseDate, %@", iAdImpressionDate, appPurchaseDate]]; } -- (void)setIadDetails:(NSDictionary *)attributionDetails - error:(NSError *)error - retriesLeft:(int)retriesLeft { - [self.loggerMock test:[prefix stringByAppendingFormat:@"setIadDetails, %@ error, %@", attributionDetails, error]]; +- (void)setAttributionDetails:(NSDictionary *)attributionDetails + error:(NSError *)error + retriesLeft:(int)retriesLeft +{ + [self.loggerMock test:[prefix stringByAppendingFormat:@"setAttributionDetails, %@ error, %@", attributionDetails, error]]; } - (void) setOfflineMode:(BOOL)enabled { @@ -150,6 +164,11 @@ - (void)resetSessionPartnerParameters { [self.loggerMock test:[prefix stringByAppendingFormat:@"resetSessionPartnerParameters"]]; } +- (NSString *)adid { + [self.loggerMock test:[prefix stringByAppendingFormat:@"adid"]]; + return nil; +} + - (void)teardown:(BOOL)deleteState { [self.loggerMock test:[prefix stringByAppendingFormat:@"teardown"]]; } diff --git a/AdjustTests/ADJActivityHandlerTests.m b/AdjustTests/ADJActivityHandlerTests.m index 9839ec667..4b672e4c7 100644 --- a/AdjustTests/ADJActivityHandlerTests.m +++ b/AdjustTests/ADJActivityHandlerTests.m @@ -3178,7 +3178,7 @@ - (void)checkStartInternal:(ADJSessionState *)sessionState { { // test the subsession message NSString * startedSubsessionLog = [NSString stringWithFormat:@"Started subsession %ld of session %ld", - sessionState.subsessionCount, sessionState.sessionCount]; + (long)sessionState.subsessionCount, sessionState.sessionCount]; aVerbose(startedSubsessionLog); break; } @@ -3198,7 +3198,7 @@ - (void)checkStartInternal:(ADJSessionState *)sessionState { // after processing the session, writes the activity state if (sessionState.sessionType != ADJSessionTypeNonSession) { NSString * wroteActivityLog = [NSString stringWithFormat:@"Wrote Activity state: ec:%ld sc:%ld ssc:%ld", - sessionState.eventCount, sessionState.sessionCount, sessionState.subsessionCount]; + (long)sessionState.eventCount, sessionState.sessionCount, sessionState.subsessionCount]; aDebug(wroteActivityLog); } // check Attribution State @@ -3332,13 +3332,6 @@ - (void)checkFinishTasks:(NSObject *)delegateTest // create activity package test ADJPackageFields * firstSessionPackageFields = [ADJPackageFields fields]; - firstSessionPackageFields.hasResponseDelegate = - attributionDelegatePresent || - eventFailureDelegatePresent || - eventSuccessDelegatePresent || - sessionFailureDelegatePresent || - sessionSuccessDelegatePresent; - // test first session [self testPackageSession:firstSessionPackage fields:firstSessionPackageFields sessionCount:@"1"]; diff --git a/AdjustTests/ADJPackageHandlerTests.m b/AdjustTests/ADJPackageHandlerTests.m index f6d41bcaa..e0a9e614a 100644 --- a/AdjustTests/ADJPackageHandlerTests.m +++ b/AdjustTests/ADJPackageHandlerTests.m @@ -648,7 +648,7 @@ - (void)checkSendFirst:(ADJSendFirst)sendFirstState if (sendFirstState == ADJSendFirstSend) { NSString * aActivitySend = [NSString stringWithFormat:@"RequestHandler sendPackage, activityPackage %@", packageString]; aTest(aActivitySend); - NSString * aQueueSizeSend = [NSString stringWithFormat:@"RequestHandler sendPackage, queueSize %lu", queueSize]; + NSString * aQueueSizeSend = [NSString stringWithFormat:@"RequestHandler sendPackage, queueSize %lu", (unsigned long)queueSize]; aTest(aQueueSizeSend); } else { anTest(@"RequestHandler sendPackage"); diff --git a/AdjustTests/ADJRequestHandlerMock.m b/AdjustTests/ADJRequestHandlerMock.m index e5a9c4e8e..b7d2e67e5 100644 --- a/AdjustTests/ADJRequestHandlerMock.m +++ b/AdjustTests/ADJRequestHandlerMock.m @@ -39,7 +39,7 @@ - (void)sendPackage:(ADJActivityPackage *)activityPackage queueSize:(NSUInteger)queueSize { [self.loggerMock test:[prefix stringByAppendingFormat:@"sendPackage, activityPackage %@", activityPackage]]; - [self.loggerMock test:[prefix stringByAppendingFormat:@"sendPackage, queueSize %lu", queueSize]]; + [self.loggerMock test:[prefix stringByAppendingFormat:@"sendPackage, queueSize %lu", (unsigned long)queueSize]]; /* NSDictionary *jsonDict; diff --git a/AdjustTests/ADJTest.h b/AdjustTests/ADJTest.h index 17de36030..3cb38fffa 100644 --- a/AdjustTests/ADJTest.h +++ b/AdjustTests/ADJTest.h @@ -112,7 +112,7 @@ // assert equals long integer #define aliEquals(field, value) \ - alilEquals(field, value, self.loggerMock) + alilEquals((long)field, (long)value, self.loggerMock) // assert equals #define aEquals(field, value) \ diff --git a/AdjustTests/ADJTestActivityPackage.m b/AdjustTests/ADJTestActivityPackage.m index ea3f174dd..cbb60205c 100644 --- a/AdjustTests/ADJTestActivityPackage.m +++ b/AdjustTests/ADJTestActivityPackage.m @@ -307,8 +307,7 @@ - (void)testConfig:(ADJActivityPackage *)package // environment apspEquals(@"environment", fields.environment); // needs_attribution_data - NSString * hasDelegateString = [NSString stringWithFormat:@"%d",fields.hasResponseDelegate]; - apspEquals(@"needs_response_details", hasDelegateString); + apspEquals(@"needs_response_details", @"1"); // event_buffering_enabled NSString * eventBufferingEnabledString = [NSString stringWithFormat:@"%d",fields.eventBufferingEnabled]; apspEquals(@"event_buffering_enabled", eventBufferingEnabledString); From ca545f459fa775a2dc5d1fa99a907b7d4bc89cd9 Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 29 Jun 2017 15:52:55 +0200 Subject: [PATCH 02/74] Queue set enabled and offline operations --- Adjust/ADJActivityHandler.m | 243 +++++++++++++++++++----------------- 1 file changed, 131 insertions(+), 112 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 75d10595c..bc70dbe96 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -284,62 +284,19 @@ - (void)launchAttributionResponseTasks:(ADJAttributionResponseData *)attribution } - (void)setEnabled:(BOOL)enabled { - // compare with the saved or internal state - if (![self hasChangedState:[self isEnabled] - nextState:enabled - trueMessage:@"Adjust already enabled" - falseMessage:@"Adjust already disabled"]) - { - return; - } - - // save new enabled state in internal state - self.internalState.enabled = enabled; - - if (self.activityState == nil) { - [self updateState:!enabled - pausingMessage:@"Handlers will start as paused due to the SDK being disabled" - remainsPausedMessage:@"Handlers will still start as paused" - unPausingMessage:@"Handlers will start as active due to the SDK being enabled"]; - return; - } - - // save new enabled state in activity state - [self writeActivityStateS:self changesInStateBlock:^{ - self.activityState.enabled = enabled; - }]; - - [self updateState:!enabled - pausingMessage:@"Pausing handlers due to SDK being disabled" - remainsPausedMessage:@"Handlers remain paused" - unPausingMessage:@"Resuming handlers due to SDK being enabled"]; + [ADJUtil launchInQueue:self.internalQueue + selfInject:self + block:^(ADJActivityHandler * selfI) { + [selfI setEnabledI:selfI enabled:enabled]; + }]; } - (void)setOfflineMode:(BOOL)offline { - // compare with the internal state - if (![self hasChangedState:[self.internalState isOffline] - nextState:offline - trueMessage:@"Adjust already in offline mode" - falseMessage:@"Adjust already in online mode"]) - { - return; - } - - // save new offline state in internal state - self.internalState.offline = offline; - - if (self.activityState == nil) { - [self updateState:offline - pausingMessage:@"Handlers will start paused due to SDK being offline" - remainsPausedMessage:@"Handlers will still start as paused" - unPausingMessage:@"Handlers will start as active due to SDK being online"]; - return; - } - - [self updateState:offline - pausingMessage:@"Pausing handlers to put SDK offline mode" - remainsPausedMessage:@"Handlers remain paused" - unPausingMessage:@"Resuming handlers to put SDK in online mode"]; + [ADJUtil launchInQueue:self.internalQueue + selfInject:self + block:^(ADJActivityHandler * selfI) { + [selfI setOfflineModeI:selfI offline:offline]; + }]; } - (BOOL)isEnabled { @@ -353,50 +310,6 @@ - (NSString *)adid { return self.activityState.adid; } -- (BOOL)hasChangedState:(BOOL)previousState - nextState:(BOOL)nextState - trueMessage:(NSString *)trueMessage - falseMessage:(NSString *)falseMessage -{ - if (previousState != nextState) { - return YES; - } - - if (previousState) { - [self.logger debug:trueMessage]; - } else { - [self.logger debug:falseMessage]; - } - - return NO; -} - -- (void)updateState:(BOOL)pausingState - pausingMessage:(NSString *)pausingMessage -remainsPausedMessage:(NSString *)remainsPausedMessage - unPausingMessage:(NSString *)unPausingMessage -{ - // it is changing from an active state to a pause state - if (pausingState) { - [self.logger info:pausingMessage]; - } - // check if it's remaining in a pause state - else if ([self pausedI:self sdkClickHandlerOnly:NO]) { - // including the sdk click handler - if ([self pausedI:self sdkClickHandlerOnly:YES]) { - [self.logger info:remainsPausedMessage]; - } else { - // or except it - [self.logger info:[remainsPausedMessage stringByAppendingString:@", except the Sdk Click Handler"]]; - } - } else { - // it is changing from a pause state to an active state - [self.logger info:unPausingMessage]; - } - - [self updateHandlersStatusAndSend]; -} - - (void)appWillOpenUrl:(NSURL*)url { [ADJUtil launchInQueue:self.internalQueue selfInject:self @@ -516,14 +429,6 @@ - (void)setAskingAttribution:(BOOL)askingAttribution { }]; } -- (void)updateHandlersStatusAndSend { - [ADJUtil launchInQueue:self.internalQueue - selfInject:self - block:^(ADJActivityHandler * selfI) { - [selfI updateHandlersStatusAndSendI:selfI]; - }]; -} - - (void)foregroundTimerFired { [ADJUtil launchInQueue:self.internalQueue selfInject:self @@ -933,7 +838,7 @@ - (void)launchSessionResponseTasksI:(ADJActivityHandler *)selfI withObject:sessionResponseData.attribution]; } - self.internalState.sessionResponseProcessed = YES; + selfI.internalState.sessionResponseProcessed = YES; } - (void)launchSdkClickResponseTasksI:(ADJActivityHandler *)selfI @@ -1032,6 +937,120 @@ - (BOOL)updateAttributionI:(ADJActivityHandler *)selfI return YES; } + +- (void)setEnabledI:(ADJActivityHandler *)selfI + enabled:(BOOL)enabled +{ + // compare with the saved or internal state + if (![selfI hasChangedStateI:selfI + previousState:[selfI isEnabled] + nextState:enabled + trueMessage:@"Adjust already enabled" + falseMessage:@"Adjust already disabled"]) + { + return; + } + + // save new enabled state in internal state + selfI.internalState.enabled = enabled; + + if (selfI.activityState == nil) { + [selfI checkStatusI:selfI + pausingState:!enabled + pausingMessage:@"Handlers will start as paused due to the SDK being disabled" + remainsPausedMessage:@"Handlers will still start as paused" + unPausingMessage:@"Handlers will start as active due to the SDK being enabled"]; + return; + } + + // save new enabled state in activity state + selfI.activityState.enabled = enabled; + [selfI writeActivityStateI:selfI]; + + [selfI checkStatusI:selfI + pausingState:!enabled + pausingMessage:@"Pausing handlers due to SDK being disabled" + remainsPausedMessage:@"Handlers remain paused" + unPausingMessage:@"Resuming handlers due to SDK being enabled"]; +} + +- (void)setOfflineModeI:(ADJActivityHandler *)selfI + offline:(BOOL)offline { + // compare with the internal state + if (![selfI hasChangedStateI:selfI + previousState:[selfI.internalState isOffline] + nextState:offline + trueMessage:@"Adjust already in offline mode" + falseMessage:@"Adjust already in online mode"]) + { + return; + } + + // save new offline state in internal state + selfI.internalState.offline = offline; + + if (selfI.activityState == nil) { + [selfI checkStatusI:selfI + pausingState:offline + pausingMessage:@"Handlers will start paused due to SDK being offline" + remainsPausedMessage:@"Handlers will still start as paused" + unPausingMessage:@"Handlers will start as active due to SDK being online"]; + return; + } + + [selfI checkStatusI:selfI + pausingState:offline + pausingMessage:@"Pausing handlers to put SDK offline mode" + remainsPausedMessage:@"Handlers remain paused" + unPausingMessage:@"Resuming handlers to put SDK in online mode"]; +} + +- (BOOL)hasChangedStateI:(ADJActivityHandler *)selfI + previousState:(BOOL)previousState + nextState:(BOOL)nextState + trueMessage:(NSString *)trueMessage + falseMessage:(NSString *)falseMessage +{ + if (previousState != nextState) { + return YES; + } + + if (previousState) { + [selfI.logger debug:trueMessage]; + } else { + [selfI.logger debug:falseMessage]; + } + + return NO; +} + +- (void)checkStatusI:(ADJActivityHandler *)selfI + pausingState:(BOOL)pausingState + pausingMessage:(NSString *)pausingMessage +remainsPausedMessage:(NSString *)remainsPausedMessage + unPausingMessage:(NSString *)unPausingMessage +{ + // it is changing from an active state to a pause state + if (pausingState) { + [selfI.logger info:pausingMessage]; + } + // check if it's remaining in a pause state + else if ([selfI pausedI:selfI sdkClickHandlerOnly:NO]) { + // including the sdk click handler + if ([selfI pausedI:selfI sdkClickHandlerOnly:YES]) { + [selfI.logger info:remainsPausedMessage]; + } else { + // or except it + [selfI.logger info:[remainsPausedMessage stringByAppendingString:@", except the Sdk Click Handler"]]; + } + } else { + // it is changing from a pause state to an active state + [selfI.logger info:unPausingMessage]; + } + + [selfI updateHandlersStatusAndSendI:selfI]; +} + - (void)appWillOpenUrlI:(ADJActivityHandler *)selfI url:(NSURL *)url { if ([ADJUtil isNull:url]) { @@ -1162,11 +1181,11 @@ - (void)setIadDateI:(ADJActivityHandler *)selfI withPurchaseDate:(NSDate *)appPurchaseDate { if (iAdImpressionDate == nil) { - [self.logger debug:@"iAdImpressionDate not received"]; + [selfI.logger debug:@"iAdImpressionDate not received"]; return; } - [self.logger debug:@"iAdImpressionDate received: %@", iAdImpressionDate]; + [selfI.logger debug:@"iAdImpressionDate received: %@", iAdImpressionDate]; double now = [NSDate.date timeIntervalSince1970]; if (selfI.activityState != nil) { @@ -1175,16 +1194,16 @@ - (void)setIadDateI:(ADJActivityHandler *)selfI } ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc] - initWithDeviceInfo:self.deviceInfo - activityState:self.activityState - config:self.adjustConfig + initWithDeviceInfo:selfI.deviceInfo + activityState:selfI.activityState + config:selfI.adjustConfig createdAt:now]; clickBuilder.purchaseTime = appPurchaseDate; clickBuilder.clickTime = iAdImpressionDate; ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad" sessionParameters:selfI.sessionParameters]; - [self.sdkClickHandler sendSdkClick:clickPackage]; + [selfI.sdkClickHandler sendSdkClick:clickPackage]; } From c80581cc71e96eee721b58f769e5f9168f0baa27 Mon Sep 17 00:00:00 2001 From: nonelse Date: Fri, 30 Jun 2017 14:52:14 +0200 Subject: [PATCH 03/74] Rename internal state vars --- Adjust/ADJActivityHandler.h | 12 ++++----- Adjust/ADJActivityHandler.m | 38 +++++++++++++-------------- AdjustTests/ADJActivityHandlerTests.m | 6 ++--- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Adjust/ADJActivityHandler.h b/Adjust/ADJActivityHandler.h index 9164abef7..5489dc063 100644 --- a/Adjust/ADJActivityHandler.h +++ b/Adjust/ADJActivityHandler.h @@ -25,13 +25,13 @@ - (BOOL)isDisabled; - (BOOL)isOffline; - (BOOL)isOnline; -- (BOOL)isBackground; -- (BOOL)isForeground; -- (BOOL)isDelayStart; -- (BOOL)isToStartNow; -- (BOOL)isToUpdatePackages; +- (BOOL)isInBackground; +- (BOOL)isInForeground; +- (BOOL)isInDelayedStart; +- (BOOL)isNotInDelayedStart; +- (BOOL)itHasToUpdatePackages; - (BOOL)isFirstLaunch; -- (BOOL)hasSessionResponseNotProcessed; +- (BOOL)hasSessionResponseNotBeenProcessed; @end diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index bc70dbe96..27344a15a 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -57,13 +57,13 @@ - (BOOL)isEnabled { return self.enabled; } - (BOOL)isDisabled { return !self.enabled; } - (BOOL)isOffline { return self.offline; } - (BOOL)isOnline { return !self.offline; } -- (BOOL)isBackground { return self.background; } -- (BOOL)isForeground { return !self.background; } -- (BOOL)isDelayStart { return self.delayStart; } -- (BOOL)isToStartNow { return !self.delayStart; } -- (BOOL)isToUpdatePackages { return self.updatePackages; } +- (BOOL)isInBackground { return self.background; } +- (BOOL)isInForeground { return !self.background; } +- (BOOL)isInDelayedStart { return self.delayStart; } +- (BOOL)isNotInDelayedStart { return !self.delayStart; } +- (BOOL)itHasToUpdatePackages { return self.updatePackages; } - (BOOL)isFirstLaunch { return self.firstLaunch; } -- (BOOL)hasSessionResponseNotProcessed { return !self.sessionResponseProcessed; } +- (BOOL)hasSessionResponseNotBeenProcessed { return !self.sessionResponseProcessed; } @end @@ -610,7 +610,7 @@ - (void)initI:(ADJActivityHandler *)selfI sdkClickHandlerOnly:NO]]; // update session parameters in package queue - if ([selfI isToUpdatePackagesI:selfI]) { + if ([selfI itHasToUpdatePackagesI:selfI]) { [selfI updatePackagesI:selfI]; } @@ -663,7 +663,7 @@ - (void)processSessionI:(ADJActivityHandler *)selfI { [selfI transferSessionPackageI:selfI now:now]; [selfI.activityState resetSessionAttributes:now]; selfI.activityState.enabled = [selfI.internalState isEnabled]; - selfI.activityState.updatePackages = [selfI.internalState isToUpdatePackages]; + selfI.activityState.updatePackages = [selfI.internalState itHasToUpdatePackages]; [selfI writeActivityStateI:selfI]; return; } @@ -709,7 +709,7 @@ - (void)transferSessionPackageI:(ADJActivityHandler *)selfI activityState:selfI.activityState config:selfI.adjustConfig createdAt:now]; - ADJActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage:selfI.sessionParameters isInDelay:[selfI.internalState isDelayStart]]; + ADJActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage:selfI.sessionParameters isInDelay:[selfI.internalState isInDelayedStart]]; [selfI.packageHandler addPackage:sessionPackage]; [selfI.packageHandler sendFirstPackage]; } @@ -720,7 +720,7 @@ - (void)checkAttributionStateI:(ADJActivityHandler *)selfI { // if it's the first launch if ([selfI.internalState isFirstLaunch]) { // and it hasn't received the session response - if ([selfI.internalState hasSessionResponseNotProcessed]) { + if ([selfI.internalState hasSessionResponseNotBeenProcessed]) { return; } } @@ -762,7 +762,7 @@ - (void)eventI:(ADJActivityHandler *)selfI activityState:selfI.activityState config:selfI.adjustConfig createdAt:now]; - ADJActivityPackage *eventPackage = [eventBuilder buildEventPackage:event sessionParameters:selfI.sessionParameters isInDelay:[selfI.internalState isDelayStart]]; + ADJActivityPackage *eventPackage = [eventBuilder buildEventPackage:event sessionParameters:selfI.sessionParameters isInDelay:[selfI.internalState isInDelayedStart]]; [selfI.packageHandler addPackage:eventPackage]; if (selfI.adjustConfig.eventBufferingEnabled) { @@ -772,7 +772,7 @@ - (void)eventI:(ADJActivityHandler *)selfI } // if it is in the background and it can send, start the background timer - if (selfI.adjustConfig.sendInBackground && [selfI.internalState isBackground]) { + if (selfI.adjustConfig.sendInBackground && [selfI.internalState isInBackground]) { [selfI startBackgroundTimerI:selfI]; } @@ -1217,11 +1217,11 @@ - (BOOL)isEnabledI:(ADJActivityHandler *)selfI { } } -- (BOOL)isToUpdatePackagesI:(ADJActivityHandler *)selfI { +- (BOOL)itHasToUpdatePackagesI:(ADJActivityHandler *)selfI { if (selfI.activityState != nil) { return selfI.activityState.updatePackages; } else { - return [selfI.internalState isToUpdatePackages]; + return [selfI.internalState itHasToUpdatePackages]; } } @@ -1413,7 +1413,7 @@ - (BOOL)pausedI:(ADJActivityHandler *)selfI // other handlers are paused if either: return [selfI.internalState isOffline] || // it's offline ![selfI isEnabledI:selfI] || // is disabled - [selfI.internalState isDelayStart]; // is in delayed start + [selfI.internalState isInDelayedStart]; // is in delayed start } - (BOOL)toSendI:(ADJActivityHandler *)selfI { @@ -1434,7 +1434,7 @@ - (BOOL)toSendI:(ADJActivityHandler *)selfI } // doesn't have the option -> depends on being on the background/foreground - return [selfI.internalState isForeground]; + return [selfI.internalState isInForeground]; } # pragma mark - timer @@ -1503,12 +1503,12 @@ - (void)backgroundTimerFiredI:(ADJActivityHandler *)selfI { #pragma mark - delay - (void)delayStartI:(ADJActivityHandler *)selfI { // it's not configured to start delayed or already finished - if ([selfI.internalState isToStartNow]) { + if ([selfI.internalState isNotInDelayedStart]) { return; } // the delay has already started - if ([selfI isToUpdatePackagesI:selfI]) { + if ([selfI itHasToUpdatePackagesI:selfI]) { return; } @@ -1538,7 +1538,7 @@ - (void)delayStartI:(ADJActivityHandler *)selfI { } - (void)sendFirstPackagesI:(ADJActivityHandler *)selfI { - if ([selfI.internalState isToStartNow]) { + if ([selfI.internalState isNotInDelayedStart]) { [selfI.logger info:@"Start delay expired or never configured"]; return; } diff --git a/AdjustTests/ADJActivityHandlerTests.m b/AdjustTests/ADJActivityHandlerTests.m index 4b672e4c7..56922aa6a 100644 --- a/AdjustTests/ADJActivityHandlerTests.m +++ b/AdjustTests/ADJActivityHandlerTests.m @@ -3066,7 +3066,7 @@ - (void)stopActivity:(id)activityHandler { ADJInternalState * internalState = [activityHandler internalState]; // goes to the background - aTrue([internalState isBackground]); + aTrue([internalState isInBackground]); } - (id)getFirstActivityHandler:(ADJConfig *)config @@ -3090,8 +3090,8 @@ - (void)stopActivity:(id)activityHandler { // test default values aiEquals(cState.startEnabled, [internalState isEnabled]); aTrue([internalState isOnline]); - aTrue([internalState isBackground]); - aTrue([internalState isToStartNow]); + aTrue([internalState isInBackground]); + aTrue([internalState isNotInDelayedStart]); aiEquals(cState.isToUpdatePackages, [internalState isToUpdatePackages]); } From ea13fdb496e1f859985dcb20db179d26bd90816d Mon Sep 17 00:00:00 2001 From: nonelse Date: Fri, 30 Jun 2017 15:02:07 +0200 Subject: [PATCH 04/74] Send first session package even with buffering --- Adjust/ADJActivityHandler.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 27344a15a..bedcba46f 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -1374,6 +1374,14 @@ - (void)updateHandlersStatusAndSendI:(ADJActivityHandler *)selfI { [selfI resumeSendingI:selfI]; + // try to send if it's the first launch and it hasn't received the session response + // even if event buffering is enabled + if ([selfI.internalState isFirstLaunch] && + [selfI.internalState hasSessionResponseNotBeenProcessed]) + { + [selfI.packageHandler sendFirstPackage]; + } + // try to send if (!selfI.adjustConfig.eventBufferingEnabled) { [selfI.packageHandler sendFirstPackage]; From d6719b0dd24568f9afaad9e766241e59dca18e24 Mon Sep 17 00:00:00 2001 From: nonelse Date: Fri, 30 Jun 2017 15:06:49 +0200 Subject: [PATCH 05/74] Save askingAttribution inside internal queue --- Adjust/ADJActivityHandler.m | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index bedcba46f..94c43ce5b 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -424,9 +424,12 @@ - (void)saveAttributionDetailsI:(ADJActivityHandler *)selfI } - (void)setAskingAttribution:(BOOL)askingAttribution { - [self writeActivityStateS:self changesInStateBlock:^{ - self.activityState.askingAttribution = askingAttribution; - }]; + [ADJUtil launchInQueue:self.internalQueue + selfInject:self + block:^(ADJActivityHandler * selfI) { + [selfI setAskingAttributionI:selfI + askingAttribution:askingAttribution]; + }]; } - (void)foregroundTimerFired { @@ -1249,21 +1252,12 @@ - (BOOL)updateActivityStateI:(ADJActivityHandler *)selfI } - (void)writeActivityStateI:(ADJActivityHandler *)selfI -{ - [selfI writeActivityStateS:selfI changesInStateBlock:nil]; -} - -- (void)writeActivityStateS:(ADJActivityHandler *)selfS - changesInStateBlock:(void (^)(void))changesInStateBlock { @synchronized ([ADJActivityState class]) { - if (selfS.activityState == nil) { + if (selfI.activityState == nil) { return; } - if (changesInStateBlock != nil) { - changesInStateBlock(); - } - [ADJUtil writeObject:selfS.activityState filename:kActivityStateFilename objectName:@"Activity state"]; + [ADJUtil writeObject:selfI.activityState filename:kActivityStateFilename objectName:@"Activity state"]; } } @@ -1445,6 +1439,13 @@ - (BOOL)toSendI:(ADJActivityHandler *)selfI return [selfI.internalState isInForeground]; } +- (void)setAskingAttributionI:(ADJActivityHandler *)selfI + askingAttribution:(BOOL)askingAttribution +{ + selfI.activityState.askingAttribution = askingAttribution; + [selfI writeActivityStateI:selfI]; +} + # pragma mark - timer - (void)startForegroundTimerI:(ADJActivityHandler *)selfI { // don't start the timer when it's disabled From a7ce1441d37927159a66b79031ff2c92a656347e Mon Sep 17 00:00:00 2001 From: nonelse Date: Mon, 3 Jul 2017 14:53:12 +0200 Subject: [PATCH 06/74] Refac adjust instance logs --- Adjust/Adjust.m | 69 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index eb6eb3a7a..6348e7862 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -152,44 +152,45 @@ - (void)appDidLaunch:(ADJConfig *)adjustConfig { } - (void)trackEvent:(ADJEvent *)event { - if (![self checkActivityHandler]) return; + if (![self checkActivityHandler]) { return; } [self.activityHandler trackEvent:event]; } - (void)trackSubsessionStart { - if (![self checkActivityHandler]) return; + if (![self checkActivityHandler]) { return; } [self.activityHandler applicationDidBecomeActive]; } - (void)trackSubsessionEnd { - if (![self checkActivityHandler]) return; + if (![self checkActivityHandler]) { return; } [self.activityHandler applicationWillResignActive]; } - (void)setEnabled:(BOOL)enabled { - if (![self checkActivityHandler]) return; + if (![self checkActivityHandler]) { return; } [self.activityHandler setEnabled:enabled]; } - (BOOL)isEnabled { - if (![self checkActivityHandler]) return NO; + if (![self checkActivityHandler]) { return NO; } return [self.activityHandler isEnabled]; } - (void)appWillOpenUrl:(NSURL *)url { - if (![self checkActivityHandler]) return; + if (![self checkActivityHandler]) { return; } [self.activityHandler appWillOpenUrl:url]; } - (void)setDeviceToken:(NSData *)deviceToken { - self.deviceTokenData = deviceToken; - if (self.activityHandler != nil) { + if (![self checkActivityHandler:@"device token"]) { + self.deviceTokenData = deviceToken; + } else { [self.activityHandler setDeviceToken:deviceToken]; } } - (void)setOfflineMode:(BOOL)enabled { - if (![self checkActivityHandler]) return; + if (![self checkActivityHandler]) { return; } [self.activityHandler setOfflineMode:enabled]; } @@ -202,13 +203,14 @@ - (NSURL *)convertUniversalLink:(NSURL *)url scheme:(NSString *)scheme { } - (void)sendFirstPackages { - if (![self checkActivityHandler]) return; + if (![self checkActivityHandler]) { return; } [self.activityHandler sendFirstPackages]; } - (void)addSessionCallbackParameter:(NSString *)key - value:(NSString *)value { - if (self.activityHandler != nil) { + value:(NSString *)value +{ + if ([self checkActivityHandler:@"adding session callback parameter"]) { [self.activityHandler addSessionCallbackParameter:key value:value]; return; } @@ -223,8 +225,9 @@ - (void)addSessionCallbackParameter:(NSString *)key } - (void)addSessionPartnerParameter:(NSString *)key - value:(NSString *)value { - if (self.activityHandler != nil) { + value:(NSString *)value +{ + if ([self checkActivityHandler:@"adding session partner parameter"]) { [self.activityHandler addSessionPartnerParameter:key value:value]; return; } @@ -238,8 +241,9 @@ - (void)addSessionPartnerParameter:(NSString *)key }]; } -- (void)removeSessionCallbackParameter:(NSString *)key { - if (self.activityHandler != nil) { +- (void)removeSessionCallbackParameter:(NSString *)key +{ + if ([self checkActivityHandler:@"removing session callback parameter"]) { [self.activityHandler removeSessionCallbackParameter:key]; return; } @@ -254,7 +258,7 @@ - (void)removeSessionCallbackParameter:(NSString *)key { } - (void)removeSessionPartnerParameter:(NSString *)key { - if (self.activityHandler != nil) { + if ([self checkActivityHandler:@"removing session partner parameter"]) { [self.activityHandler removeSessionPartnerParameter:key]; return; } @@ -269,7 +273,7 @@ - (void)removeSessionPartnerParameter:(NSString *)key { } - (void)resetSessionCallbackParameters { - if (self.activityHandler != nil) { + if ([self checkActivityHandler:@"resetting session callback parameters"]) { [self.activityHandler resetSessionCallbackParameters]; return; } @@ -284,7 +288,7 @@ - (void)resetSessionCallbackParameters { } - (void)resetSessionPartnerParameters { - if (self.activityHandler != nil) { + if ([self checkActivityHandler:@"resetting session partner parameters"]) { [self.activityHandler resetSessionPartnerParameters]; return; } @@ -299,12 +303,12 @@ - (void)resetSessionPartnerParameters { } - (ADJAttribution *)attribution { - if (![self checkActivityHandler]) return nil; + if (![self checkActivityHandler]) { return nil; } return [self.activityHandler attribution]; } - (NSString *)adid { - if (![self checkActivityHandler]) return nil; + if (![self checkActivityHandler]) { return nil; } return [self.activityHandler adid]; } @@ -320,12 +324,33 @@ - (void)teardown:(BOOL)deleteState { #pragma mark - private - (BOOL)checkActivityHandler { + return [self checkActivityHandler:nil]; +} + +- (BOOL)checkActivityHandler:(BOOL)status + trueMessage:(NSString *)trueMessage + falseMessage:(NSString *)falseMessage +{ + if (status) { + return [self checkActivityHandler:trueMessage]; + } else { + return [self checkActivityHandler:falseMessage]; + } +} + +- (BOOL)checkActivityHandler:(NSString *)savedForLaunchWarningSuffixMessage +{ if (self.activityHandler == nil) { - [self.logger error:@"Please initialize Adjust by calling 'appDidLaunch' before"]; + if (savedForLaunchWarningSuffixMessage != nil) { + [self.logger warn:@"Adjust not initialized, but %@ saved for launch", savedForLaunchWarningSuffixMessage]; + } else { + [self.logger error:@"Please initialize Adjust by calling 'appDidLaunch' before"]; + } return NO; } else { return YES; } + } @end From fbff7f7f35c7a0cba4a109e1a80062fd56050f12 Mon Sep 17 00:00:00 2001 From: nonelse Date: Mon, 3 Jul 2017 15:06:41 +0200 Subject: [PATCH 07/74] Refac save properties into class --- Adjust/ADJActivityHandler.h | 15 +++++++++---- Adjust/ADJActivityHandler.m | 24 +++++++++++++------- Adjust/ADJAdjustFactory.h | 3 +-- Adjust/ADJAdjustFactory.m | 9 +++----- Adjust/Adjust.m | 45 ++++++++++++++++++------------------- 5 files changed, 53 insertions(+), 43 deletions(-) diff --git a/Adjust/ADJActivityHandler.h b/Adjust/ADJActivityHandler.h index 5489dc063..468fb44f3 100644 --- a/Adjust/ADJActivityHandler.h +++ b/Adjust/ADJActivityHandler.h @@ -35,14 +35,22 @@ @end +@interface ADJSavedPreLaunch : NSObject + +@property (nonatomic, strong) NSMutableArray *sessionParametersActionsArray; +@property (nonatomic, copy) NSData *deviceTokenData; + +- (id)init; + +@end + @protocol ADJActivityHandler @property (nonatomic, copy) ADJAttribution *attribution; - (NSString *)adid; - (id)initWithConfig:(ADJConfig *)adjustConfig -sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray - deviceToken:(NSData*)deviceToken; + savedPreLaunch:(ADJSavedPreLaunch *)savedPreLaunch; - (void)applicationDidBecomeActive; - (void)applicationWillResignActive; @@ -87,8 +95,7 @@ sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray @interface ADJActivityHandler : NSObject + (id)handlerWithConfig:(ADJConfig *)adjustConfig - sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray - deviceToken:(NSData*)deviceToken; + savedPreLaunch:(ADJSavedPreLaunch *)savedPreLaunch; - (void)addSessionCallbackParameterI:(ADJActivityHandler *)selfI key:(NSString *)key diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 94c43ce5b..5ab16ad84 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -67,6 +67,17 @@ - (BOOL)hasSessionResponseNotBeenProcessed { return !self.sessionResponseProcess @end +@implementation ADJSavedPreLaunch + +- (id)init { + self = [super init]; + if (self == nil) return nil; + + return self; +} + +@end + #pragma mark - @interface ADJActivityHandler() @@ -102,17 +113,14 @@ @implementation ADJActivityHandler @synthesize attribution = _attribution; + (id)handlerWithConfig:(ADJConfig *)adjustConfig - sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray - deviceToken:(NSData*)deviceToken + savedPreLaunch:(ADJSavedPreLaunch *)savedPreLaunch { return [[ADJActivityHandler alloc] initWithConfig:adjustConfig - sessionParametersActionsArray:sessionParametersActionsArray - deviceToken:deviceToken]; + savedPreLaunch:savedPreLaunch]; } - (id)initWithConfig:(ADJConfig *)adjustConfig -sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray - deviceToken:(NSData*)deviceToken + savedPreLaunch:(ADJSavedPreLaunch *)savedPreLaunch { self = [super init]; if (self == nil) return nil; @@ -170,14 +178,14 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig } // does not have the session response by default self.internalState.sessionResponseProcessed = NO; - self.deviceTokenData = deviceToken; + self.deviceTokenData = savedPreLaunch.deviceTokenData; self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); [ADJUtil launchInQueue:self.internalQueue selfInject:self block:^(ADJActivityHandler * selfI) { [selfI initI:selfI - sessionParametersActionsArray:sessionParametersActionsArray]; + sessionParametersActionsArray:savedPreLaunch.sessionParametersActionsArray]; }]; [self addNotificationObserver]; diff --git a/Adjust/ADJAdjustFactory.h b/Adjust/ADJAdjustFactory.h index 02a6a9fbc..81c45381f 100644 --- a/Adjust/ADJAdjustFactory.h +++ b/Adjust/ADJAdjustFactory.h @@ -22,8 +22,7 @@ startsSending:(BOOL)startsSending; + (id)requestHandlerForPackageHandler:(id)packageHandler; + (id)activityHandlerWithConfig:(ADJConfig *)adjustConfig - sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray - deviceToken:(NSData*)deviceToken; + savedPreLaunch:(ADJSavedPreLaunch *)savedPreLaunch; + (id)sdkClickHandlerWithStartsPaused:(id)activityHandler startsSending:(BOOL)startsSending; diff --git a/Adjust/ADJAdjustFactory.m b/Adjust/ADJAdjustFactory.m index a2de8f731..35c686bbd 100644 --- a/Adjust/ADJAdjustFactory.m +++ b/Adjust/ADJAdjustFactory.m @@ -43,18 +43,15 @@ @implementation ADJAdjustFactory } + (id)activityHandlerWithConfig:(ADJConfig *)adjustConfig - sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray - deviceToken:(NSData*)deviceToken + savedPreLaunch:(ADJSavedPreLaunch *)savedPreLaunch { if (internalActivityHandler == nil) { return [ADJActivityHandler handlerWithConfig:adjustConfig - sessionParametersActionsArray:sessionParametersActionsArray - deviceToken:deviceToken + savedPreLaunch:savedPreLaunch ]; } return [internalActivityHandler initWithConfig:adjustConfig - sessionParametersActionsArray:sessionParametersActionsArray - deviceToken:deviceToken]; + savedPreLaunch:savedPreLaunch]; } + (id)logger { diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 6348e7862..fd20a5b62 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -24,8 +24,7 @@ @interface Adjust() @property (nonatomic, weak) id logger; @property (nonatomic, strong) id activityHandler; -@property (nonatomic, strong) NSMutableArray *sessionParametersActionsArray; -@property (nonatomic, copy) NSData *deviceTokenData; +@property (nonatomic, strong) ADJSavedPreLaunch *savedPreLaunch; @end @@ -136,6 +135,7 @@ - (id) init { self.activityHandler = nil; self.logger = [ADJAdjustFactory logger]; + self.savedPreLaunch = [[ADJSavedPreLaunch alloc] init]; return self; } @@ -147,8 +147,7 @@ - (void)appDidLaunch:(ADJConfig *)adjustConfig { } self.activityHandler = [ADJAdjustFactory activityHandlerWithConfig:adjustConfig - sessionParametersActionsArray:self.sessionParametersActionsArray - deviceToken:self.deviceTokenData]; + savedPreLaunch:self.savedPreLaunch]; } - (void)trackEvent:(ADJEvent *)event { @@ -183,7 +182,7 @@ - (void)appWillOpenUrl:(NSURL *)url { - (void)setDeviceToken:(NSData *)deviceToken { if (![self checkActivityHandler:@"device token"]) { - self.deviceTokenData = deviceToken; + self.savedPreLaunch.deviceTokenData = deviceToken; } else { [self.activityHandler setDeviceToken:deviceToken]; } @@ -215,11 +214,11 @@ - (void)addSessionCallbackParameter:(NSString *)key return; } - if (self.sessionParametersActionsArray == nil) { - self.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.sessionParametersActionsArray == nil) { + self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; } - [self.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler addSessionCallbackParameterI:activityHandler key:key value:value]; }]; } @@ -232,11 +231,11 @@ - (void)addSessionPartnerParameter:(NSString *)key return; } - if (self.sessionParametersActionsArray == nil) { - self.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.sessionParametersActionsArray == nil) { + self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; } - [self.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler addSessionPartnerParameterI:activityHandler key:key value:value]; }]; } @@ -248,11 +247,11 @@ - (void)removeSessionCallbackParameter:(NSString *)key return; } - if (self.sessionParametersActionsArray == nil) { - self.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.sessionParametersActionsArray == nil) { + self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; } - [self.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler removeSessionCallbackParameterI:activityHandler key:key]; }]; } @@ -263,11 +262,11 @@ - (void)removeSessionPartnerParameter:(NSString *)key { return; } - if (self.sessionParametersActionsArray == nil) { - self.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.sessionParametersActionsArray == nil) { + self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; } - [self.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler removeSessionPartnerParameterI:activityHandler key:key]; }]; } @@ -278,11 +277,11 @@ - (void)resetSessionCallbackParameters { return; } - if (self.sessionParametersActionsArray == nil) { - self.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.sessionParametersActionsArray == nil) { + self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; } - [self.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler resetSessionCallbackParametersI:activityHandler]; }]; } @@ -293,11 +292,11 @@ - (void)resetSessionPartnerParameters { return; } - if (self.sessionParametersActionsArray == nil) { - self.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.sessionParametersActionsArray == nil) { + self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; } - [self.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler resetSessionPartnerParametersI:activityHandler]; }]; } From 5e94e02fc518a7e2c2dff7503ca72fbfbdcb6656 Mon Sep 17 00:00:00 2001 From: nonelse Date: Mon, 3 Jul 2017 16:42:37 +0200 Subject: [PATCH 08/74] Inject enabled and disabled at start time --- Adjust/ADJActivityHandler.h | 4 ++- Adjust/ADJActivityHandler.m | 31 +++++++++++++------ Adjust/Adjust.m | 59 ++++++++++++++++++++++--------------- 3 files changed, 61 insertions(+), 33 deletions(-) diff --git a/Adjust/ADJActivityHandler.h b/Adjust/ADJActivityHandler.h index 468fb44f3..e67eb388d 100644 --- a/Adjust/ADJActivityHandler.h +++ b/Adjust/ADJActivityHandler.h @@ -37,8 +37,10 @@ @interface ADJSavedPreLaunch : NSObject -@property (nonatomic, strong) NSMutableArray *sessionParametersActionsArray; +@property (nonatomic, strong) NSMutableArray *preLaunchActionsArray; @property (nonatomic, copy) NSData *deviceTokenData; +@property (nonatomic, copy) NSNumber *enabled; +@property (nonatomic, assign) BOOL offline; - (id)init; diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 5ab16ad84..4cddf07df 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -73,6 +73,8 @@ - (id)init { self = [super init]; if (self == nil) return nil; + // online by default + self.offline = NO; return self; } @@ -152,6 +154,17 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig self.internalState = [[ADJInternalState alloc] init]; + if (savedPreLaunch.enabled != nil) { + if (savedPreLaunch.preLaunchActionsArray == nil) { + savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; + } + + BOOL newEnabled = [savedPreLaunch.enabled boolValue]; + [savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [activityHandler setEnabledI:activityHandler enabled:newEnabled]; + }]; + } + // enabled by default if (self.activityState == nil) { self.internalState.enabled = YES; @@ -159,8 +172,8 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig self.internalState.enabled = self.activityState.enabled; } - // online by default - self.internalState.offline = NO; + // reads offline mode from pre launch + self.internalState.offline = savedPreLaunch.offline; // in the background by default self.internalState.background = YES; // delay start not configured by default @@ -185,7 +198,7 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig selfInject:self block:^(ADJActivityHandler * selfI) { [selfI initI:selfI - sessionParametersActionsArray:savedPreLaunch.sessionParametersActionsArray]; + preLaunchActionsArray:savedPreLaunch.preLaunchActionsArray]; }]; [self addNotificationObserver]; @@ -556,7 +569,7 @@ - (void)teardown:(BOOL)deleteState #pragma mark - internal - (void)initI:(ADJActivityHandler *)selfI -sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray +preLaunchActionsArray:(NSArray*)preLaunchActionsArray { // get session values kSessionInterval = ADJAdjustFactory.sessionInterval; @@ -643,7 +656,7 @@ - (void)initI:(ADJActivityHandler *)selfI [[UIDevice currentDevice] adjSetIad:selfI triesV3Left:kTryIadV3]; - [selfI sessionParametersActionsI:selfI sessionParametersActionsArray:sessionParametersActionsArray]; + [selfI preLaunchActionsI:selfI preLaunchActionsArray:preLaunchActionsArray]; [selfI startI:selfI]; } @@ -1708,13 +1721,13 @@ - (void)resetSessionPartnerParametersI:(ADJActivityHandler *)selfI { [selfI writeSessionPartnerParametersI:selfI]; } -- (void)sessionParametersActionsI:(ADJActivityHandler *)selfI - sessionParametersActionsArray:(NSArray*)sessionParametersActionsArray +- (void)preLaunchActionsI:(ADJActivityHandler *)selfI + preLaunchActionsArray:(NSArray*)preLaunchActionsArray { - if (sessionParametersActionsArray == nil) { + if (preLaunchActionsArray == nil) { return; } - for (activityHandlerBlockI activityHandlerActionI in sessionParametersActionsArray) { + for (activityHandlerBlockI activityHandlerActionI in preLaunchActionsArray) { activityHandlerActionI(selfI); } } diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index fd20a5b62..02501220d 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -48,7 +48,8 @@ + (void)trackSubsessionEnd { } + (void)setEnabled:(BOOL)enabled { - [[Adjust getInstance] setEnabled:enabled]; + Adjust * instance = [Adjust getInstance]; + [instance setEnabled:enabled]; } + (BOOL)isEnabled { @@ -166,8 +167,14 @@ - (void)trackSubsessionEnd { } - (void)setEnabled:(BOOL)enabled { - if (![self checkActivityHandler]) { return; } - [self.activityHandler setEnabled:enabled]; + if (![self checkActivityHandler: enabled + trueMessage:@"enabled mode" + falseMessage:@"disabled mode"]) + { + self.savedPreLaunch.enabled = [NSNumber numberWithBool:enabled]; + } else { + [self.activityHandler setEnabled:enabled]; + } } - (BOOL)isEnabled { @@ -189,8 +196,14 @@ - (void)setDeviceToken:(NSData *)deviceToken { } - (void)setOfflineMode:(BOOL)enabled { - if (![self checkActivityHandler]) { return; } - [self.activityHandler setOfflineMode:enabled]; + if (![self checkActivityHandler:enabled + trueMessage:@"offline mode" + falseMessage:@"online mode"]) + { + self.savedPreLaunch.offline = enabled; + } else { + [self.activityHandler setOfflineMode:enabled]; + } } - (NSString *)idfa { @@ -214,11 +227,11 @@ - (void)addSessionCallbackParameter:(NSString *)key return; } - if (self.savedPreLaunch.sessionParametersActionsArray == nil) { - self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.preLaunchActionsArray == nil) { + self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler addSessionCallbackParameterI:activityHandler key:key value:value]; }]; } @@ -231,11 +244,11 @@ - (void)addSessionPartnerParameter:(NSString *)key return; } - if (self.savedPreLaunch.sessionParametersActionsArray == nil) { - self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.preLaunchActionsArray == nil) { + self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler addSessionPartnerParameterI:activityHandler key:key value:value]; }]; } @@ -247,11 +260,11 @@ - (void)removeSessionCallbackParameter:(NSString *)key return; } - if (self.savedPreLaunch.sessionParametersActionsArray == nil) { - self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.preLaunchActionsArray == nil) { + self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler removeSessionCallbackParameterI:activityHandler key:key]; }]; } @@ -262,11 +275,11 @@ - (void)removeSessionPartnerParameter:(NSString *)key { return; } - if (self.savedPreLaunch.sessionParametersActionsArray == nil) { - self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.preLaunchActionsArray == nil) { + self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler removeSessionPartnerParameterI:activityHandler key:key]; }]; } @@ -277,11 +290,11 @@ - (void)resetSessionCallbackParameters { return; } - if (self.savedPreLaunch.sessionParametersActionsArray == nil) { - self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.preLaunchActionsArray == nil) { + self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler resetSessionCallbackParametersI:activityHandler]; }]; } @@ -292,11 +305,11 @@ - (void)resetSessionPartnerParameters { return; } - if (self.savedPreLaunch.sessionParametersActionsArray == nil) { - self.savedPreLaunch.sessionParametersActionsArray = [[NSMutableArray alloc] init]; + if (self.savedPreLaunch.preLaunchActionsArray == nil) { + self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.sessionParametersActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ [activityHandler resetSessionPartnerParametersI:activityHandler]; }]; } From 235d058a0a306612f7fc691ad2e762f80979f544 Mon Sep 17 00:00:00 2001 From: nonelse Date: Mon, 3 Jul 2017 16:46:47 +0200 Subject: [PATCH 09/74] Block adding packages when disabled --- Adjust/ADJActivityHandler.m | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 4cddf07df..3f452b07c 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -419,6 +419,10 @@ - (void)setAttributionDetails:(NSDictionary *)attributionDetails - (void)sendIad3ClickPackage:(ADJActivityHandler *)selfI attributionDetails:(NSDictionary *)attributionDetails { + if (![selfI isEnabledI:selfI]) { + return; + } + double now = [NSDate.date timeIntervalSince1970]; if (selfI.activityState != nil) { double lastInterval = now - selfI.activityState.lastActivity; @@ -684,7 +688,11 @@ - (void)processSessionI:(ADJActivityHandler *)selfI { selfI.activityState.sessionCount = 1; // this is the first session selfI.activityState.deviceToken = [ADJUtil convertDeviceToken:selfI.deviceTokenData]; - [selfI transferSessionPackageI:selfI now:now]; + // track the first session package only if it's enabled + if ([selfI.internalState isEnabled]) { + [selfI transferSessionPackageI:selfI now:now]; + } + [selfI.activityState resetSessionAttributes:now]; selfI.activityState.enabled = [selfI.internalState isEnabled]; selfI.activityState.updatePackages = [selfI.internalState itHasToUpdatePackages]; @@ -961,7 +969,6 @@ - (BOOL)updateAttributionI:(ADJActivityHandler *)selfI return YES; } - - (void)setEnabledI:(ADJActivityHandler *)selfI enabled:(BOOL)enabled { @@ -1081,6 +1088,10 @@ - (void)appWillOpenUrlI:(ADJActivityHandler *)selfI return; } + if (![selfI isEnabledI:selfI]) { + return; + } + if ([[url absoluteString] length] == 0) { return; } @@ -1209,6 +1220,10 @@ - (void)setIadDateI:(ADJActivityHandler *)selfI return; } + if (![selfI isEnabledI:selfI]) { + return; + } + [selfI.logger debug:@"iAdImpressionDate received: %@", iAdImpressionDate]; double now = [NSDate.date timeIntervalSince1970]; From 1d6b2745becc25903134b74215c5e08d6c5ae75f Mon Sep 17 00:00:00 2001 From: nonelse Date: Mon, 3 Jul 2017 17:12:05 +0200 Subject: [PATCH 10/74] Read idfa for every package --- Adjust/ADJPackageBuilder.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index ccc6676c0..ea9349484 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -12,6 +12,7 @@ #import "ADJPackageBuilder.h" #import "ADJActivityPackage.h" #import "NSData+ADJAdditions.h" +#import "UIDevice+ADJAdditions.h" @interface ADJPackageBuilder() @@ -227,7 +228,7 @@ - (void)injectCommonParameters:(NSMutableDictionary *)parameters { } - (void)injectDeviceInfoIds:(ADJDeviceInfo *)deviceInfo intoParameters:(NSMutableDictionary *)parameters { - [ADJPackageBuilder parameters:parameters setString:deviceInfo.idForAdvertisers forKey:@"idfa"]; + [ADJPackageBuilder parameters:parameters setString:UIDevice.currentDevice.adjIdForAdvertisers forKey:@"idfa"]; [ADJPackageBuilder parameters:parameters setString:deviceInfo.vendorId forKey:@"idfv"]; } From 872cb58c3de75923277e591f519280499b579378 Mon Sep 17 00:00:00 2001 From: Obaied Date: Fri, 14 Jul 2017 10:50:01 +0200 Subject: [PATCH 11/74] Add sending mcc and mnc to ADJDeviceInfo --- Adjust/ADJDeviceInfo.h | 2 ++ Adjust/ADJDeviceInfo.m | 10 ++++++++++ Adjust/ADJPackageBuilder.m | 2 ++ 3 files changed, 14 insertions(+) diff --git a/Adjust/ADJDeviceInfo.h b/Adjust/ADJDeviceInfo.h index 73f6d5fb4..8af6ec7b2 100644 --- a/Adjust/ADJDeviceInfo.h +++ b/Adjust/ADJDeviceInfo.h @@ -28,6 +28,8 @@ @property (nonatomic, copy) NSString *cpuSubtype; @property (nonatomic, copy) NSString *installReceiptBase64; @property (nonatomic, copy) NSString *osBuild; +@property (nonatomic, copy) NSString *mcc; +@property (nonatomic, copy) NSString *mnc; - (id)initWithSdkPrefix:(NSString *)sdkPrefix; + (ADJDeviceInfo *)deviceInfoWithSdkPrefix:(NSString *)sdkPrefix; diff --git a/Adjust/ADJDeviceInfo.m b/Adjust/ADJDeviceInfo.m index 475ece787..354b9e416 100644 --- a/Adjust/ADJDeviceInfo.m +++ b/Adjust/ADJDeviceInfo.m @@ -12,6 +12,10 @@ #import "ADJUtil.h" #import "ADJSystemProfile.h" #import "NSData+ADJAdditions.h" +#import +#import + + @implementation ADJDeviceInfo @@ -44,6 +48,12 @@ - (id)initWithSdkPrefix:(NSString *)sdkPrefix { self.machineModel = [ADJSystemProfile machineModel]; self.cpuSubtype = [ADJSystemProfile cpuSubtype]; self.osBuild = [ADJSystemProfile osVersion]; + + //MCC & MNC + CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; + CTCarrier *carrier = [networkInfo subscriberCellularProvider]; + self.mcc = [carrier mobileCountryCode]; + self.mnc = [carrier mobileNetworkCode]; if (sdkPrefix == nil) { self.clientSdk = ADJUtil.clientSdk; diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index ea9349484..e8a3a027f 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -250,6 +250,8 @@ - (void)injectDeviceInfo:(ADJDeviceInfo *)deviceInfo intoParameters:(NSMutableDi [ADJPackageBuilder parameters:parameters setString:deviceInfo.cpuSubtype forKey:@"cpu_type"]; [ADJPackageBuilder parameters:parameters setString:deviceInfo.installReceiptBase64 forKey:@"install_receipt"]; [ADJPackageBuilder parameters:parameters setString:deviceInfo.osBuild forKey:@"os_build"]; + [ADJPackageBuilder parameters:parameters setString:deviceInfo.mcc forKey:@"mcc"]; + [ADJPackageBuilder parameters:parameters setString:deviceInfo.mnc forKey:@"mnc"]; } - (void)injectConfig:(ADJConfig *)adjustConfig intoParameters:(NSMutableDictionary *) parameters { From b88b2603d9e6c1af35f35d3105d15910659c844a Mon Sep 17 00:00:00 2001 From: Obaied Date: Fri, 14 Jul 2017 10:52:54 +0200 Subject: [PATCH 12/74] Add CoreTelephpny.framework as an optional framework --- Adjust.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index a8440fb59..8aa9d8264 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 2067002A1F18BDC700B4FDE1 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9601C19C1A31DD7F00A9AE21 /* CoreTelephony.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 9601C1A01A31DD8900A9AE21 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9601C19C1A31DD7F00A9AE21 /* CoreTelephony.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 9601C1A31A31DE0D00A9AE21 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9601C1A11A31DE0300A9AE21 /* SystemConfiguration.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 9601CAE41C74B70600670879 /* ADJEventSuccess.h in Headers */ = {isa = PBXBuildFile; fileRef = 9601CAE21C74B70600670879 /* ADJEventSuccess.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -660,6 +661,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 2067002A1F18BDC700B4FDE1 /* CoreTelephony.framework in Frameworks */, 96325E89190E892000A97911 /* iAd.framework in Frameworks */, 9DE7C8FD1AE688DA001556E5 /* UIKit.framework in Frameworks */, 96325E8A190E892600A97911 /* AdSupport.framework in Frameworks */, From 054db97b47c4358de13b3a2a812286f204f5ddc0 Mon Sep 17 00:00:00 2001 From: nonelse Date: Tue, 25 Jul 2017 17:47:07 +0200 Subject: [PATCH 13/74] Teardown static util instances --- Adjust/ADJActivityHandler.m | 2 ++ Adjust/ADJUtil.h | 2 ++ Adjust/ADJUtil.m | 30 ++++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 3f452b07c..a3cb100ee 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -557,6 +557,8 @@ - (void)teardown:(BOOL)deleteState [self teardownAttributionS:deleteState]; [self teardownAllSessionParametersS:deleteState]; + [ADJUtil teardown]; + self.internalQueue = nil; self.packageHandler = nil; self.attributionHandler = nil; diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index 95cf09bb9..e3fe18fff 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -19,6 +19,8 @@ typedef void (^selfInjectedBlock)(id); @interface ADJUtil : NSObject ++ (void)teardown; + + (id)readObject:(NSString *)filename objectName:(NSString *)objectName class:(Class)classToRead; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 3e1f5c6a7..06820f2ec 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -56,6 +56,15 @@ + (void)initialize { [self initializeUrlSessionConfiguration]; } ++ (void)teardown { + dateFormat = nil; + universalLinkRegex = nil; + secondsNumberFormatter = nil; + optionalRedirectRegex = nil; + shortUniversalLinkRegex = nil; + urlSessionConfiguration = nil; +} + + (void)initializeDateFormat { dateFormat = [[NSDateFormatter alloc] init]; @@ -134,6 +143,14 @@ + (void)initializeSecondsNumberFormatter { [secondsNumberFormatter setPositiveFormat:@"0.0"]; } ++ (NSURLSessionConfiguration *)getUrlSessionConfiguration { + if (urlSessionConfiguration != nil) { + return urlSessionConfiguration; + } else { + return [NSURLSessionConfiguration defaultSessionConfiguration]; + } +} + + (void)initializeUrlSessionConfiguration { urlSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; } @@ -199,6 +216,9 @@ + (NSString *)formatSeconds1970:(double)value { } + (NSString *)formatDate:(NSDate *)value { + if (dateFormat == nil) { + return nil; + } return [dateFormat stringFromDate:value]; } @@ -427,7 +447,7 @@ + (void)sendNSURLSessionRequest:(NSMutableURLRequest *)request suffixErrorMessage:(NSString *)suffixErrorMessage activityPackage:(ADJActivityPackage *)activityPackage responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { - NSURLSession *session = [NSURLSession sessionWithConfiguration:urlSessionConfiguration]; + NSURLSession *session = [NSURLSession sessionWithConfiguration:[ADJUtil getUrlSessionConfiguration]]; NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: @@ -546,7 +566,9 @@ + (NSDictionary *)convertDictionaryValues:(NSDictionary *)dictionary { } else if ([value isKindOfClass:[NSDate class]]) { // Format date to our custom format NSString *dateStingValue = [ADJUtil formatDate:value]; - [convertedDictionary setObject:dateStingValue forKey:key]; + if (dateStingValue != nil) { + [convertedDictionary setObject:dateStingValue forKey:key]; + } } else { // Convert all other objects directly to string NSString *stringValue = [NSString stringWithFormat:@"%@", value]; @@ -739,6 +761,10 @@ + (NSString *)secondsNumberFormat:(double)seconds { seconds = seconds * -1; } + if (secondsNumberFormatter == nil) { + return nil; + } + return [secondsNumberFormatter stringFromNumber:[NSNumber numberWithDouble:seconds]]; } From 74062fa9ded130a6fe962af71e619a0fb2eeca3f Mon Sep 17 00:00:00 2001 From: nonelse Date: Wed, 26 Jul 2017 15:27:21 +0200 Subject: [PATCH 14/74] Move MCC MNC from device info --- Adjust/ADJDeviceInfo.h | 2 -- Adjust/ADJDeviceInfo.m | 6 ------ Adjust/ADJPackageBuilder.m | 4 ++-- Adjust/ADJUtil.h | 4 ++++ Adjust/ADJUtil.m | 26 ++++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Adjust/ADJDeviceInfo.h b/Adjust/ADJDeviceInfo.h index 8af6ec7b2..73f6d5fb4 100644 --- a/Adjust/ADJDeviceInfo.h +++ b/Adjust/ADJDeviceInfo.h @@ -28,8 +28,6 @@ @property (nonatomic, copy) NSString *cpuSubtype; @property (nonatomic, copy) NSString *installReceiptBase64; @property (nonatomic, copy) NSString *osBuild; -@property (nonatomic, copy) NSString *mcc; -@property (nonatomic, copy) NSString *mnc; - (id)initWithSdkPrefix:(NSString *)sdkPrefix; + (ADJDeviceInfo *)deviceInfoWithSdkPrefix:(NSString *)sdkPrefix; diff --git a/Adjust/ADJDeviceInfo.m b/Adjust/ADJDeviceInfo.m index 354b9e416..e82e55e51 100644 --- a/Adjust/ADJDeviceInfo.m +++ b/Adjust/ADJDeviceInfo.m @@ -49,12 +49,6 @@ - (id)initWithSdkPrefix:(NSString *)sdkPrefix { self.cpuSubtype = [ADJSystemProfile cpuSubtype]; self.osBuild = [ADJSystemProfile osVersion]; - //MCC & MNC - CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; - CTCarrier *carrier = [networkInfo subscriberCellularProvider]; - self.mcc = [carrier mobileCountryCode]; - self.mnc = [carrier mobileNetworkCode]; - if (sdkPrefix == nil) { self.clientSdk = ADJUtil.clientSdk; } else { diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index e8a3a027f..afb0eded0 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -250,8 +250,8 @@ - (void)injectDeviceInfo:(ADJDeviceInfo *)deviceInfo intoParameters:(NSMutableDi [ADJPackageBuilder parameters:parameters setString:deviceInfo.cpuSubtype forKey:@"cpu_type"]; [ADJPackageBuilder parameters:parameters setString:deviceInfo.installReceiptBase64 forKey:@"install_receipt"]; [ADJPackageBuilder parameters:parameters setString:deviceInfo.osBuild forKey:@"os_build"]; - [ADJPackageBuilder parameters:parameters setString:deviceInfo.mcc forKey:@"mcc"]; - [ADJPackageBuilder parameters:parameters setString:deviceInfo.mnc forKey:@"mnc"]; + [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMCC] forKey:@"mcc"]; + [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMNC] forKey:@"mnc"]; } - (void)injectConfig:(ADJConfig *)adjustConfig intoParameters:(NSMutableDictionary *) parameters { diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index e3fe18fff..fb80f63af 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -112,4 +112,8 @@ responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler + (NSTimeInterval)waitingTime:(NSInteger)retries backoffStrategy:(ADJBackoffStrategy *)backoffStrategy; ++ (NSString *)readMCC; + ++ (NSString *)readMNC; + @end diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 06820f2ec..195882ac6 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -18,6 +18,8 @@ #import "ADJAdjustFactory.h" #import "UIDevice+ADJAdditions.h" #import "NSString+ADJAdditions.h" +#import +#import static const double kRequestTimeout = 60; // 60 seconds @@ -27,6 +29,7 @@ static NSRegularExpression *optionalRedirectRegex = nil; static NSRegularExpression *shortUniversalLinkRegex = nil; static NSURLSessionConfiguration *urlSessionConfiguration = nil; +static CTCarrier *carrier = nil; static NSString *userAgent = nil; @@ -54,6 +57,7 @@ + (void)initialize { [self initializeShortUniversalLinkRegex]; [self initializeOptionalRedirectRegex]; [self initializeUrlSessionConfiguration]; + [self initializeCarrier]; } + (void)teardown { @@ -63,6 +67,7 @@ + (void)teardown { optionalRedirectRegex = nil; shortUniversalLinkRegex = nil; urlSessionConfiguration = nil; + carrier = nil; } + (void)initializeDateFormat { @@ -155,6 +160,11 @@ + (void)initializeUrlSessionConfiguration { urlSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; } ++ (void)initializeCarrier { + CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; + carrier = [networkInfo subscriberCellularProvider]; +} + + (void)updateUrlSessionConfiguration:(ADJConfig *)config { userAgent = config.userAgent; } @@ -1032,4 +1042,20 @@ + (BOOL)contains:(NSDictionary *)dictionary return [value isEqualToString:[readValue description]]; } ++ (NSString *)readMCC { + if (carrier == nil) { + return nil; + } + + return [carrier mobileCountryCode]; +} + ++ (NSString *)readMNC { + if (carrier == nil) { + return nil; + } + + return [carrier mobileNetworkCode]; +} + @end From b1c0b6bdcdfeb25467ddc9f1475f0cc53def4019 Mon Sep 17 00:00:00 2001 From: nonelse Date: Wed, 26 Jul 2017 15:37:59 +0200 Subject: [PATCH 15/74] Add connectivity type --- Adjust.xcodeproj/project.pbxproj | 24 ++ Adjust/ADJDeviceInfo.m | 4 +- Adjust/ADJPackageBuilder.m | 9 + Adjust/ADJReachability.h | 66 +++++ Adjust/ADJReachability.m | 247 ++++++++++++++++++ Adjust/ADJUtil.h | 1 + Adjust/ADJUtil.m | 17 ++ .../project.pbxproj | 6 + .../project.pbxproj | 6 + .../project.pbxproj | 6 + .../project.pbxproj | 6 + .../project.pbxproj | 6 + 12 files changed, 396 insertions(+), 2 deletions(-) create mode 100644 Adjust/ADJReachability.h create mode 100644 Adjust/ADJReachability.m diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index 8aa9d8264..a2af4fe63 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -23,6 +23,12 @@ /* Begin PBXBuildFile section */ 2067002A1F18BDC700B4FDE1 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9601C19C1A31DD7F00A9AE21 /* CoreTelephony.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + 6FCC85001F278CF300D6A0ED /* ADJReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FCC84F71F278CF300D6A0ED /* ADJReachability.m */; }; + 6FCC85011F278CF300D6A0ED /* ADJReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FCC84F81F278CF300D6A0ED /* ADJReachability.h */; }; + 6FCC85041F27945E00D6A0ED /* ADJReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FCC85021F27944600D6A0ED /* ADJReachability.h */; }; + 6FCC85051F27946100D6A0ED /* ADJReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FCC85031F27944600D6A0ED /* ADJReachability.m */; }; + 6FCC85081F27948C00D6A0ED /* ADJReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FCC85071F27948700D6A0ED /* ADJReachability.h */; }; + 6FCC85091F27949000D6A0ED /* ADJReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FCC85061F27948700D6A0ED /* ADJReachability.m */; }; 9601C1A01A31DD8900A9AE21 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9601C19C1A31DD7F00A9AE21 /* CoreTelephony.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 9601C1A31A31DE0D00A9AE21 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9601C1A11A31DE0300A9AE21 /* SystemConfiguration.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 9601CAE41C74B70600670879 /* ADJEventSuccess.h in Headers */ = {isa = PBXBuildFile; fileRef = 9601CAE21C74B70600670879 /* ADJEventSuccess.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -364,6 +370,12 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 6FCC84F71F278CF300D6A0ED /* ADJReachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJReachability.m; sourceTree = ""; }; + 6FCC84F81F278CF300D6A0ED /* ADJReachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJReachability.h; sourceTree = ""; }; + 6FCC85021F27944600D6A0ED /* ADJReachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADJReachability.h; sourceTree = ""; }; + 6FCC85031F27944600D6A0ED /* ADJReachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADJReachability.m; sourceTree = ""; }; + 6FCC85061F27948700D6A0ED /* ADJReachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADJReachability.m; sourceTree = ""; }; + 6FCC85071F27948700D6A0ED /* ADJReachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADJReachability.h; sourceTree = ""; }; 9601C19C1A31DD7F00A9AE21 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; 9601C1A11A31DE0300A9AE21 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 9601CAE21C74B70600670879 /* ADJEventSuccess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJEventSuccess.h; sourceTree = ""; }; @@ -850,6 +862,8 @@ 9DF9C8B21D6ED228008E362F /* ADJKeychain.m */, 96B6710E1D788EEC0090A023 /* ADJSessionParameters.h */, 96B6710F1D788EEC0090A023 /* ADJSessionParameters.m */, + 6FCC84F81F278CF300D6A0ED /* ADJReachability.h */, + 6FCC84F71F278CF300D6A0ED /* ADJReachability.m */, ); path = Adjust; sourceTree = ""; @@ -1047,6 +1061,8 @@ 9DF9C9071D6F3CA5008E362F /* ADJUtil.m */, 96B671121D788F4A0090A023 /* ADJSessionParameters.h */, 96B671131D788F4A0090A023 /* ADJSessionParameters.m */, + 6FCC85021F27944600D6A0ED /* ADJReachability.h */, + 6FCC85031F27944600D6A0ED /* ADJReachability.m */, 9DF9C9081D6F3CA5008E362F /* Info.plist */, ); path = Adjust; @@ -1145,6 +1161,8 @@ 9DFB06581D7470C0006D48FC /* ADJUtil.m */, 96B671161D788F7A0090A023 /* ADJSessionParameters.h */, 96B671171D788F7A0090A023 /* ADJSessionParameters.m */, + 6FCC85071F27948700D6A0ED /* ADJReachability.h */, + 6FCC85061F27948700D6A0ED /* ADJReachability.m */, 9DFB06591D7470C0006D48FC /* Info.plist */, ); path = Adjust; @@ -1177,6 +1195,7 @@ 96BCFBD11AC99246005A65C5 /* ADJAttribution.h in Headers */, 9601CAE81C74BAAE00670879 /* ADJEventFailure.h in Headers */, 9601CAE41C74B70600670879 /* ADJEventSuccess.h in Headers */, + 6FCC85011F278CF300D6A0ED /* ADJReachability.h in Headers */, 96BCFBD41AC99338005A65C5 /* NSData+ADJAdditions.h in Headers */, 968173871C3C2D36002AE1DE /* ADJSessionFailure.h in Headers */, 968173831C3C2D07002AE1DE /* ADJSessionSuccess.h in Headers */, @@ -1218,6 +1237,7 @@ 9DF9C9271D6F3CA5008E362F /* ADJEventSuccess.h in Headers */, 9DF9C9371D6F3CA5008E362F /* ADJSessionFailure.h in Headers */, 9DF9C9391D6F3CA5008E362F /* ADJSessionSuccess.h in Headers */, + 6FCC85041F27945E00D6A0ED /* ADJReachability.h in Headers */, 9DF9C9111D6F3CA5008E362F /* NSData+ADJAdditions.h in Headers */, 9DF9C9131D6F3CA5008E362F /* NSString+ADJAdditions.h in Headers */, 9DF9C9151D6F3CA5008E362F /* UIDevice+ADJAdditions.h in Headers */, @@ -1257,6 +1277,7 @@ 9DFB06781D7470C0006D48FC /* ADJEventSuccess.h in Headers */, 9DFB06881D7470C0006D48FC /* ADJSessionFailure.h in Headers */, 9DFB068A1D7470C0006D48FC /* ADJSessionSuccess.h in Headers */, + 6FCC85081F27948C00D6A0ED /* ADJReachability.h in Headers */, 9DFB06621D7470C0006D48FC /* NSData+ADJAdditions.h in Headers */, 9DFB06641D7470C0006D48FC /* NSString+ADJAdditions.h in Headers */, 9DFB06661D7470C0006D48FC /* UIDevice+ADJAdditions.h in Headers */, @@ -1650,6 +1671,7 @@ 96E5E39318BBB48A008E7B30 /* ADJLogger.m in Sources */, 96E5E39518BBB48A008E7B30 /* ADJPackageHandler.m in Sources */, 96E5E39418BBB48A008E7B30 /* ADJPackageBuilder.m in Sources */, + 6FCC85001F278CF300D6A0ED /* ADJReachability.m in Sources */, 96E5E39618BBB48A008E7B30 /* ADJRequestHandler.m in Sources */, 96E5E39918BBB48A008E7B30 /* ADJUtil.m in Sources */, 9609BC6A19EEA55800E02303 /* ADJEvent.m in Sources */, @@ -1732,6 +1754,7 @@ 9DF9C92C1D6F3CA5008E362F /* ADJLogger.m in Sources */, 9DF9C92E1D6F3CA5008E362F /* ADJPackageBuilder.m in Sources */, 9DF9C9301D6F3CA5008E362F /* ADJPackageHandler.m in Sources */, + 6FCC85051F27946100D6A0ED /* ADJReachability.m in Sources */, 9DF9C9321D6F3CA5008E362F /* ADJRequestHandler.m in Sources */, 9DF9C9461D6F3CA5008E362F /* ADJUtil.m in Sources */, 9DF9C9241D6F3CA5008E362F /* ADJEvent.m in Sources */, @@ -1770,6 +1793,7 @@ 9DFB067D1D7470C0006D48FC /* ADJLogger.m in Sources */, 9DFB067F1D7470C0006D48FC /* ADJPackageBuilder.m in Sources */, 9DFB06811D7470C0006D48FC /* ADJPackageHandler.m in Sources */, + 6FCC85091F27949000D6A0ED /* ADJReachability.m in Sources */, 9DFB06831D7470C0006D48FC /* ADJRequestHandler.m in Sources */, 9DFB06971D7470C0006D48FC /* ADJUtil.m in Sources */, 9DFB06751D7470C0006D48FC /* ADJEvent.m in Sources */, diff --git a/Adjust/ADJDeviceInfo.m b/Adjust/ADJDeviceInfo.m index e82e55e51..8fee2388f 100644 --- a/Adjust/ADJDeviceInfo.m +++ b/Adjust/ADJDeviceInfo.m @@ -14,8 +14,7 @@ #import "NSData+ADJAdditions.h" #import #import - - +#import "ADJReachability.h" @implementation ADJDeviceInfo @@ -75,6 +74,7 @@ - (void)injectInstallReceipt:(NSBundle *)bundle{ } @catch (NSException *exception) { } } + /* -(id)copyWithZone:(NSZone *)zone { diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index afb0eded0..662858738 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -252,6 +252,7 @@ - (void)injectDeviceInfo:(ADJDeviceInfo *)deviceInfo intoParameters:(NSMutableDi [ADJPackageBuilder parameters:parameters setString:deviceInfo.osBuild forKey:@"os_build"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMCC] forKey:@"mcc"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMNC] forKey:@"mnc"]; + [ADJPackageBuilder parameters:parameters setNumberInt:[ADJUtil readReachabilityFlags] forKey:@"ios_connectivity_type"]; } - (void)injectConfig:(ADJConfig *)adjustConfig intoParameters:(NSMutableDictionary *) parameters { @@ -404,4 +405,12 @@ + (void)parameters:(NSMutableDictionary *)parameters setNumber:(NSNumber *)value [ADJPackageBuilder parameters:parameters setString:numberString forKey:key]; } ++ (void)parameters:(NSMutableDictionary *)parameters setNumberInt:(NSNumber *)value forKey:(NSString *)key { + if (value == nil) { + return; + } + + [ADJPackageBuilder parameters:parameters setInt:[value intValue] forKey:key]; +} + @end diff --git a/Adjust/ADJReachability.h b/Adjust/ADJReachability.h new file mode 100644 index 000000000..6123c72f7 --- /dev/null +++ b/Adjust/ADJReachability.h @@ -0,0 +1,66 @@ +/* + Copyright (C) 2016 Apple Inc. All Rights Reserved. + See LICENSE.txt for this sample’s licensing information + + Abstract: + Basic demonstration of how to use the SystemConfiguration Reachablity APIs. + */ + +#import +#import +#import + + +typedef enum : NSInteger { + NotReachable = 0, + ReachableViaWiFi, + ReachableViaWWAN +} NetworkStatus; + +#pragma mark IPv6 Support +//Reachability fully support IPv6. For full details, see ReadMe.md. + + +extern NSString *kReachabilityChangedNotification; + + +@interface ADJReachability : NSObject + +/*! + * Use to check the reachability of a given host name. + */ ++ (instancetype)reachabilityWithHostName:(NSString *)hostName; + +/*! + * Use to check the reachability of a given IP address. + */ ++ (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress; + +/*! + * Checks whether the default route is available. Should be used by applications that do not connect to a particular host. + */ ++ (instancetype)reachabilityForInternetConnection; + + +#pragma mark reachabilityForLocalWiFi +//reachabilityForLocalWiFi has been removed from the sample. See ReadMe.md for more information. +//+ (instancetype)reachabilityForLocalWiFi; + +/*! + * Start listening for reachability notifications on the current run loop. + */ +- (BOOL)startNotifier; +- (void)stopNotifier; + +- (NetworkStatus)currentReachabilityStatus; + +/*! + * WWAN may be available, but not active until a connection has been established. WiFi may require a connection for VPN on Demand. + */ +- (BOOL)connectionRequired; + +- (NSNumber *)currentReachabilityFlags; + +@end + + diff --git a/Adjust/ADJReachability.m b/Adjust/ADJReachability.m new file mode 100644 index 000000000..a7d46881d --- /dev/null +++ b/Adjust/ADJReachability.m @@ -0,0 +1,247 @@ +/* + Copyright (C) 2016 Apple Inc. All Rights Reserved. + + Abstract: + Basic demonstration of how to use the SystemConfiguration Reachablity APIs. + */ + +#import +#import +#import +#import +#import + +#import + +#import "ADJReachability.h" + +#pragma mark IPv6 Support + +NSString *kReachabilityChangedNotification = @"kNetworkReachabilityChangedNotification"; + +#pragma mark - Supporting functions + +#define kShouldPrintReachabilityFlags 1 + +static void PrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment) +{ +#if kShouldPrintReachabilityFlags + + NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n", + (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', + (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', + + (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', + (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', + (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', + (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-', + comment + ); +#endif +} + + +static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) +{ +#pragma unused (target, flags) + NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback"); + NSCAssert([(__bridge NSObject*) info isKindOfClass: [ADJReachability class]], @"info was wrong class in ReachabilityCallback"); + + ADJReachability* noteObject = (__bridge ADJReachability *)info; + // Post a notification to notify the client that the network reachability changed. + [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject]; +} + + +#pragma mark - Reachability implementation + +@implementation ADJReachability +{ + SCNetworkReachabilityRef _reachabilityRef; +} + ++ (instancetype)reachabilityWithHostName:(NSString *)hostName +{ + ADJReachability* returnValue = NULL; + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]); + if (reachability != NULL) + { + returnValue= [[self alloc] init]; + if (returnValue != NULL) + { + returnValue->_reachabilityRef = reachability; + } + else { + CFRelease(reachability); + } + } + return returnValue; +} + + ++ (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress +{ + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, hostAddress); + + ADJReachability* returnValue = NULL; + + if (reachability != NULL) + { + returnValue = [[self alloc] init]; + if (returnValue != NULL) + { + returnValue->_reachabilityRef = reachability; + } + else { + CFRelease(reachability); + } + } + return returnValue; +} + + ++ (instancetype)reachabilityForInternetConnection +{ + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + + return [self reachabilityWithAddress: (const struct sockaddr *) &zeroAddress]; +} + + +#pragma mark - Start and stop notifier + +- (BOOL)startNotifier +{ + BOOL returnValue = NO; + SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; + + if (SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) + { + if (SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) + { + returnValue = YES; + } + } + + return returnValue; +} + + +- (void)stopNotifier +{ + if (_reachabilityRef != NULL) + { + SCNetworkReachabilityUnscheduleFromRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + } +} + + +- (void)dealloc +{ + [self stopNotifier]; + if (_reachabilityRef != NULL) + { + CFRelease(_reachabilityRef); + } +} + + +#pragma mark - Network Flag Handling + +- (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags +{ + PrintReachabilityFlags(flags, "networkStatusForFlags"); + if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) + { + // The target host is not reachable. + return NotReachable; + } + + NetworkStatus returnValue = NotReachable; + + if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) + { + /* + If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi... + */ + returnValue = ReachableViaWiFi; + } + + if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) + { + /* + ... and the connection is on-demand (or on-traffic) if the calling application is using the CFSocketStream or higher APIs... + */ + + if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) + { + /* + ... and no [user] intervention is needed... + */ + returnValue = ReachableViaWiFi; + } + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + /* + ... but WWAN connections are OK if the calling application is using the CFNetwork APIs. + */ + returnValue = ReachableViaWWAN; + } + + return returnValue; +} + + +- (BOOL)connectionRequired +{ + NSAssert(_reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef"); + SCNetworkReachabilityFlags flags; + + if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) + { + return (flags & kSCNetworkReachabilityFlagsConnectionRequired); + } + + return NO; +} + + +- (NetworkStatus)currentReachabilityStatus +{ + NSAssert(_reachabilityRef != NULL, @"currentNetworkStatus called with NULL SCNetworkReachabilityRef"); + NetworkStatus returnValue = NotReachable; + SCNetworkReachabilityFlags flags; + + if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) + { + returnValue = [self networkStatusForFlags:flags]; + } + + return returnValue; +} + +- (NSNumber *)currentReachabilityFlags +{ + if (_reachabilityRef == NULL) { + return nil; + } + SCNetworkReachabilityFlags flags; + + if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) + { + return [[NSNumber alloc] initWithUnsignedInt:flags]; + } else { + return [[NSNumber alloc] initWithUnsignedInt:0]; + } +} + +@end diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index fb80f63af..4d552c038 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -116,4 +116,5 @@ responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler + (NSString *)readMNC; ++ (NSNumber *)readReachabilityFlags; @end diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 195882ac6..847df256e 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -20,6 +20,7 @@ #import "NSString+ADJAdditions.h" #import #import +#import "ADJReachability.h" static const double kRequestTimeout = 60; // 60 seconds @@ -30,6 +31,7 @@ static NSRegularExpression *shortUniversalLinkRegex = nil; static NSURLSessionConfiguration *urlSessionConfiguration = nil; static CTCarrier *carrier = nil; +static ADJReachability *reachability = nil; static NSString *userAgent = nil; @@ -58,6 +60,7 @@ + (void)initialize { [self initializeOptionalRedirectRegex]; [self initializeUrlSessionConfiguration]; [self initializeCarrier]; + [self initializeReachability]; } + (void)teardown { @@ -68,6 +71,7 @@ + (void)teardown { shortUniversalLinkRegex = nil; urlSessionConfiguration = nil; carrier = nil; + reachability = nil; } + (void)initializeDateFormat { @@ -165,6 +169,11 @@ + (void)initializeCarrier { carrier = [networkInfo subscriberCellularProvider]; } ++ (void)initializeReachability { + reachability = [ADJReachability reachabilityForInternetConnection]; + [reachability startNotifier]; +} + + (void)updateUrlSessionConfiguration:(ADJConfig *)config { userAgent = config.userAgent; } @@ -1058,4 +1067,12 @@ + (NSString *)readMNC { return [carrier mobileNetworkCode]; } ++ (NSNumber *)readReachabilityFlags { + if (reachability == nil) { + return nil; + } + + return [reachability currentReachabilityFlags]; +} + @end diff --git a/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj b/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj index 6bc8d4836..1bbe3a7f9 100644 --- a/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 6FCC850F1F2794C600D6A0ED /* ADJReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FCC850E1F2794BE00D6A0ED /* ADJReachability.m */; }; 9D449E761E6EDC3D00E7E80B /* ADJActivityHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449E351E6EDC3D00E7E80B /* ADJActivityHandler.m */; }; 9D449E771E6EDC3D00E7E80B /* ADJActivityKind.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449E371E6EDC3D00E7E80B /* ADJActivityKind.m */; }; 9D449E781E6EDC3D00E7E80B /* ADJActivityPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449E391E6EDC3D00E7E80B /* ADJActivityPackage.m */; }; @@ -49,6 +50,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 6FCC850D1F2794BE00D6A0ED /* ADJReachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADJReachability.h; sourceTree = ""; }; + 6FCC850E1F2794BE00D6A0ED /* ADJReachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADJReachability.m; sourceTree = ""; }; 9D449E341E6EDC3D00E7E80B /* ADJActivityHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityHandler.h; sourceTree = ""; }; 9D449E351E6EDC3D00E7E80B /* ADJActivityHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityHandler.m; sourceTree = ""; }; 9D449E361E6EDC3D00E7E80B /* ADJActivityKind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityKind.h; sourceTree = ""; }; @@ -197,6 +200,8 @@ 9D449E721E6EDC3D00E7E80B /* Adjust.m */, 9D449E731E6EDC3D00E7E80B /* ADJUtil.h */, 9D449E741E6EDC3D00E7E80B /* ADJUtil.m */, + 6FCC850D1F2794BE00D6A0ED /* ADJReachability.h */, + 6FCC850E1F2794BE00D6A0ED /* ADJReachability.m */, 9D449E751E6EDC3D00E7E80B /* Info.plist */, ); name = Adjust; @@ -345,6 +350,7 @@ 9D449E7E1E6EDC3D00E7E80B /* ADJAttribution.m in Sources */, 9D449E831E6EDC3D00E7E80B /* ADJDeviceInfo.m in Sources */, 9D449E7F1E6EDC3D00E7E80B /* ADJAttributionHandler.m in Sources */, + 6FCC850F1F2794C600D6A0ED /* ADJReachability.m in Sources */, 9D449E891E6EDC3D00E7E80B /* ADJPackageBuilder.m in Sources */, 9D449E841E6EDC3D00E7E80B /* ADJEvent.m in Sources */, 9D449E951E6EDC3D00E7E80B /* ADJUtil.m in Sources */, diff --git a/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj b/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj index 011b6a455..a56618d8e 100644 --- a/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 6FCC85121F2794D900D6A0ED /* ADJReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FCC85111F2794D600D6A0ED /* ADJReachability.m */; }; 968595F11D0B2E630011CA2B /* AdjustBridgeRegister.m in Sources */ = {isa = PBXBuildFile; fileRef = 968595F01D0B2E630011CA2B /* AdjustBridgeRegister.m */; }; 9D1082A91CFDAF8E0050568B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D1082A81CFDAF8E0050568B /* main.m */; }; 9D1082AF1CFDAF8E0050568B /* UIWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D1082AE1CFDAF8E0050568B /* UIWebViewController.m */; }; @@ -64,6 +65,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 6FCC85101F2794D600D6A0ED /* ADJReachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADJReachability.h; sourceTree = ""; }; + 6FCC85111F2794D600D6A0ED /* ADJReachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADJReachability.m; sourceTree = ""; }; 968595EF1D0B2E630011CA2B /* AdjustBridgeRegister.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdjustBridgeRegister.h; sourceTree = ""; }; 968595F01D0B2E630011CA2B /* AdjustBridgeRegister.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdjustBridgeRegister.m; sourceTree = ""; }; 9D1082A41CFDAF8E0050568B /* AdjustExample-WebView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "AdjustExample-WebView.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -297,6 +300,8 @@ 9D449ED61E6EDD4100E7E80B /* Adjust.m */, 9D449ED71E6EDD4100E7E80B /* ADJUtil.h */, 9D449ED81E6EDD4100E7E80B /* ADJUtil.m */, + 6FCC85101F2794D600D6A0ED /* ADJReachability.h */, + 6FCC85111F2794D600D6A0ED /* ADJReachability.m */, 9D449ED91E6EDD4100E7E80B /* Info.plist */, ); name = Adjust; @@ -438,6 +443,7 @@ 9D449EE01E6EDD4100E7E80B /* UIDevice+ADJAdditions.m in Sources */, 9D449EEA1E6EDD4100E7E80B /* ADJEventSuccess.m in Sources */, 9D75F1961D07463800E5D222 /* WebViewJavascriptBridge.m in Sources */, + 6FCC85121F2794D900D6A0ED /* ADJReachability.m in Sources */, 9D75F1991D07463800E5D222 /* WKWebViewJavascriptBridge.m in Sources */, 9D10833D1CFDD8F00050568B /* WKWebViewController.m in Sources */, 9D449EE51E6EDD4100E7E80B /* ADJConfig.m in Sources */, diff --git a/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj b/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj index aa65ce68d..912580a15 100644 --- a/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 6FCC850C1F2794AB00D6A0ED /* ADJReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FCC850A1F2794A300D6A0ED /* ADJReachability.m */; }; 963909411BCBFCF300A2E8A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 963909401BCBFCF300A2E8A4 /* main.m */; }; 963909441BCBFCF300A2E8A4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 963909431BCBFCF300A2E8A4 /* AppDelegate.m */; }; 9639094A1BCBFCF300A2E8A4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 963909481BCBFCF300A2E8A4 /* Main.storyboard */; }; @@ -50,6 +51,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 6FCC850A1F2794A300D6A0ED /* ADJReachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADJReachability.m; sourceTree = ""; }; + 6FCC850B1F2794A300D6A0ED /* ADJReachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADJReachability.h; sourceTree = ""; }; 9639093C1BCBFCF300A2E8A4 /* AdjustExample-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "AdjustExample-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 963909401BCBFCF300A2E8A4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 963909421BCBFCF300A2E8A4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -261,6 +264,8 @@ 9D449E0D1E6ED88F00E7E80B /* ADJKeychain.m */, 9D449E0E1E6ED88F00E7E80B /* ADJSessionParameters.h */, 9D449E0F1E6ED88F00E7E80B /* ADJSessionParameters.m */, + 6FCC850B1F2794A300D6A0ED /* ADJReachability.h */, + 6FCC850A1F2794A300D6A0ED /* ADJReachability.m */, ); name = Adjust; path = ../../../Adjust; @@ -369,6 +374,7 @@ 9D449E1E1E6ED88F00E7E80B /* ADJPackageHandler.m in Sources */, 9D449E281E6ED88F00E7E80B /* ADJResponseData.m in Sources */, 9D449E301E6ED88F00E7E80B /* ADJKeychain.m in Sources */, + 6FCC850C1F2794AB00D6A0ED /* ADJReachability.m in Sources */, 9D449E131E6ED88F00E7E80B /* NSString+ADJAdditions.m in Sources */, 9D449E221E6ED88F00E7E80B /* ADJDeviceInfo.m in Sources */, 9D449E1C1E6ED88F00E7E80B /* ADJLogger.m in Sources */, diff --git a/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj b/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj index 7c684f203..9c072c7ac 100644 --- a/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 6FCC85181F27950000D6A0ED /* ADJReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FCC85171F2794F800D6A0ED /* ADJReachability.m */; }; 9D449FA31E6EE72000E7E80B /* ADJActivityHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449F621E6EE72000E7E80B /* ADJActivityHandler.m */; }; 9D449FA41E6EE72000E7E80B /* ADJActivityKind.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449F641E6EE72000E7E80B /* ADJActivityKind.m */; }; 9D449FA51E6EE72000E7E80B /* ADJActivityPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449F661E6EE72000E7E80B /* ADJActivityPackage.m */; }; @@ -104,6 +105,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 6FCC85161F2794F800D6A0ED /* ADJReachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADJReachability.h; sourceTree = ""; }; + 6FCC85171F2794F800D6A0ED /* ADJReachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADJReachability.m; sourceTree = ""; }; 9D449F611E6EE72000E7E80B /* ADJActivityHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityHandler.h; sourceTree = ""; }; 9D449F621E6EE72000E7E80B /* ADJActivityHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityHandler.m; sourceTree = ""; }; 9D449F631E6EE72000E7E80B /* ADJActivityKind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityKind.h; sourceTree = ""; }; @@ -282,6 +285,8 @@ 9D449F9F1E6EE72000E7E80B /* Adjust.m */, 9D449FA01E6EE72000E7E80B /* ADJUtil.h */, 9D449FA11E6EE72000E7E80B /* ADJUtil.m */, + 6FCC85161F2794F800D6A0ED /* ADJReachability.h */, + 6FCC85171F2794F800D6A0ED /* ADJReachability.m */, 9D449FA21E6EE72000E7E80B /* Info.plist */, ); name = Adjust; @@ -527,6 +532,7 @@ 9D449FB31E6EE72000E7E80B /* ADJEventSuccess.m in Sources */, 9D449FBF1E6EE72000E7E80B /* ADJTimerCycle.m in Sources */, 9D449FAB1E6EE72000E7E80B /* ADJAttribution.m in Sources */, + 6FCC85181F27950000D6A0ED /* ADJReachability.m in Sources */, 9D449FA61E6EE72000E7E80B /* ADJActivityState.m in Sources */, 9DF7ACB81CB4FF6400D3591F /* AdjustTrackingHelper.m in Sources */, 9DF7AC1F1CB4FEDB00D3591F /* ViewControllerWatch.m in Sources */, diff --git a/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj b/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj index ebfca8f89..ded3b065e 100644 --- a/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 6FCC85151F2794EC00D6A0ED /* ADJReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FCC85131F2794E800D6A0ED /* ADJReachability.m */; }; 963909B71BCC0D8300A2E8A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 963909B61BCC0D8300A2E8A4 /* main.m */; }; 963909BA1BCC0D8300A2E8A4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 963909B91BCC0D8300A2E8A4 /* AppDelegate.m */; }; 963909BD1BCC0D8300A2E8A4 /* ViewControllertvOS.m in Sources */ = {isa = PBXBuildFile; fileRef = 963909BC1BCC0D8300A2E8A4 /* ViewControllertvOS.m */; }; @@ -62,6 +63,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 6FCC85131F2794E800D6A0ED /* ADJReachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADJReachability.m; sourceTree = ""; }; + 6FCC85141F2794E800D6A0ED /* ADJReachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADJReachability.h; sourceTree = ""; }; 963909B21BCC0D8300A2E8A4 /* AdjustExample-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "AdjustExample-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 963909B61BCC0D8300A2E8A4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 963909B81BCC0D8300A2E8A4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -254,6 +257,8 @@ 9D449F3B1E6EE6C500E7E80B /* Adjust.m */, 9D449F3C1E6EE6C500E7E80B /* ADJUtil.h */, 9D449F3D1E6EE6C500E7E80B /* ADJUtil.m */, + 6FCC85141F2794E800D6A0ED /* ADJReachability.h */, + 6FCC85131F2794E800D6A0ED /* ADJReachability.m */, 9D449F3E1E6EE6C500E7E80B /* Info.plist */, ); name = Adjust; @@ -375,6 +380,7 @@ 9D449F4E1E6EE6C500E7E80B /* ADJEventFailure.m in Sources */, 9D449F461E6EE6C500E7E80B /* ADJAdjustFactory.m in Sources */, 9D449F3F1E6EE6C500E7E80B /* ADJActivityHandler.m in Sources */, + 6FCC85151F2794EC00D6A0ED /* ADJReachability.m in Sources */, 9D449F5C1E6EE6C500E7E80B /* ADJTimerOnce.m in Sources */, 9D449F401E6EE6C500E7E80B /* ADJActivityKind.m in Sources */, 9D449F481E6EE6C500E7E80B /* ADJAttributionHandler.m in Sources */, From ef43b256aadc3dfabb70964aa592dfff089f070e Mon Sep 17 00:00:00 2001 From: nonelse Date: Wed, 26 Jul 2017 17:29:36 +0200 Subject: [PATCH 16/74] Add network type --- Adjust/ADJPackageBuilder.m | 1 + Adjust/ADJUtil.h | 2 ++ Adjust/ADJUtil.m | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 662858738..2df4e7c45 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -252,6 +252,7 @@ - (void)injectDeviceInfo:(ADJDeviceInfo *)deviceInfo intoParameters:(NSMutableDi [ADJPackageBuilder parameters:parameters setString:deviceInfo.osBuild forKey:@"os_build"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMCC] forKey:@"mcc"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMNC] forKey:@"mnc"]; + [ADJPackageBuilder parameters:parameters setString:[ADJUtil readCurrentRadioAccessTechnology] forKey:@"ios_network_type"]; [ADJPackageBuilder parameters:parameters setNumberInt:[ADJUtil readReachabilityFlags] forKey:@"ios_connectivity_type"]; } diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index 4d552c038..50a51c6f8 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -117,4 +117,6 @@ responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler + (NSString *)readMNC; + (NSNumber *)readReachabilityFlags; + ++ (NSString *)readCurrentRadioAccessTechnology; @end diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 847df256e..0ee976756 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -30,6 +30,7 @@ static NSRegularExpression *optionalRedirectRegex = nil; static NSRegularExpression *shortUniversalLinkRegex = nil; static NSURLSessionConfiguration *urlSessionConfiguration = nil; +static CTTelephonyNetworkInfo *networkInfo = nil; static CTCarrier *carrier = nil; static ADJReachability *reachability = nil; @@ -59,7 +60,7 @@ + (void)initialize { [self initializeShortUniversalLinkRegex]; [self initializeOptionalRedirectRegex]; [self initializeUrlSessionConfiguration]; - [self initializeCarrier]; + [self initializeNetworkInfoAndCarrier]; [self initializeReachability]; } @@ -70,6 +71,7 @@ + (void)teardown { optionalRedirectRegex = nil; shortUniversalLinkRegex = nil; urlSessionConfiguration = nil; + networkInfo = nil; carrier = nil; reachability = nil; } @@ -164,8 +166,8 @@ + (void)initializeUrlSessionConfiguration { urlSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; } -+ (void)initializeCarrier { - CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; ++ (void)initializeNetworkInfoAndCarrier { + networkInfo = [[CTTelephonyNetworkInfo alloc] init]; carrier = [networkInfo subscriberCellularProvider]; } @@ -1075,4 +1077,11 @@ + (NSNumber *)readReachabilityFlags { return [reachability currentReachabilityFlags]; } ++ (NSString *)readCurrentRadioAccessTechnology { + if (networkInfo == nil) { + return nil; + } + return [networkInfo currentRadioAccessTechnology]; +} + @end From 9cfb378c670acacc2e5005fb442006716d8a66cf Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 27 Jul 2017 10:50:23 +0200 Subject: [PATCH 17/74] Set device known --- Adjust/ADJConfig.h | 5 +++++ Adjust/ADJConfig.m | 1 + Adjust/ADJPackageBuilder.m | 3 +++ 3 files changed, 9 insertions(+) diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index 700275f8e..f1769870e 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -150,6 +150,11 @@ */ @property (nonatomic, copy, nullable) NSString *userAgent; +/** + * @brief Set if the device is known. + */ +@property (nonatomic, assign) BOOL isDeviceKnown; + /** * @brief Get configuration object for the initialization of the Adjust SDK. * diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index 78f883c06..e4c903847 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -179,6 +179,7 @@ -(id)copyWithZone:(NSZone *)zone copy.sendInBackground = self.sendInBackground; copy.delayStart = self.delayStart; copy.userAgent = [self.userAgent copyWithZone:zone]; + copy.isDeviceKnown = self.isDeviceKnown; // adjust delegate not copied } diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 2df4e7c45..86f168a56 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -260,6 +260,9 @@ - (void)injectConfig:(ADJConfig *)adjustConfig intoParameters:(NSMutableDictiona [ADJPackageBuilder parameters:parameters setString:adjustConfig.appToken forKey:@"app_token"]; [ADJPackageBuilder parameters:parameters setString:adjustConfig.environment forKey:@"environment"]; [ADJPackageBuilder parameters:parameters setBool:adjustConfig.eventBufferingEnabled forKey:@"event_buffering_enabled"]; + if (adjustConfig.isDeviceKnown) { + [ADJPackageBuilder parameters:parameters setBool:adjustConfig.isDeviceKnown forKey:@"device_known"]; + } } - (void)injectActivityState:(ADJActivityState *)activityState intoParamters:(NSMutableDictionary *)parameters { From 973ba440dc90cd3997919583c0588d7d0b4eec53 Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 27 Jul 2017 15:42:46 +0200 Subject: [PATCH 18/74] Read attribution group with reflection --- Adjust/ADJKeychain.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adjust/ADJKeychain.m b/Adjust/ADJKeychain.m index 42639f027..2cffe7201 100644 --- a/Adjust/ADJKeychain.m +++ b/Adjust/ADJKeychain.m @@ -169,7 +169,7 @@ - (BOOL)wasWritingSuccessful:(NSString *)value forKeychainKey:(NSString *)key in NSString *writtenValue; writtenValue = [self valueForKeychainKeyV1:key service:service]; - + if ([writtenValue isEqualToString:value]) { return YES; } else { From 74028551a14ac92634b87cba59c8bb8e91b982b1 Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 27 Jul 2017 17:26:26 +0200 Subject: [PATCH 19/74] Rename log to string func --- Adjust/ADJLogger.h | 2 +- Adjust/ADJLogger.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJLogger.h b/Adjust/ADJLogger.h index 20be0d952..95bb7433a 100644 --- a/Adjust/ADJLogger.h +++ b/Adjust/ADJLogger.h @@ -79,6 +79,6 @@ typedef enum { * * @return Log level as ADJLogLevel enumeration. */ -+ (ADJLogLevel)LogLevelFromString:(nonnull NSString *)logLevelString; ++ (ADJLogLevel)logLevelFromString:(nonnull NSString *)logLevelString; @end diff --git a/Adjust/ADJLogger.m b/Adjust/ADJLogger.m index f31ad1ec1..3eb49ad4b 100644 --- a/Adjust/ADJLogger.m +++ b/Adjust/ADJLogger.m @@ -105,7 +105,7 @@ - (void)logLevel:(NSString *)logLevel format:(NSString *)format parameters:(va_l } } -+ (ADJLogLevel)LogLevelFromString:(NSString *)logLevelString { ++ (ADJLogLevel)logLevelFromString:(NSString *)logLevelString { if ([logLevelString isEqualToString:@"verbose"]) return ADJLogLevelVerbose; From 3d463f93222c89aeed0f777a55bfd24dda6661ac Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 27 Jul 2017 17:26:36 +0200 Subject: [PATCH 20/74] Add suppress to loglevel to string --- Adjust/ADJLogger.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Adjust/ADJLogger.m b/Adjust/ADJLogger.m index 3eb49ad4b..f0deef8ef 100644 --- a/Adjust/ADJLogger.m +++ b/Adjust/ADJLogger.m @@ -124,6 +124,9 @@ + (ADJLogLevel)logLevelFromString:(NSString *)logLevelString { if ([logLevelString isEqualToString:@"assert"]) return ADJLogLevelAssert; + if ([logLevelString isEqualToString:@"suppress"]) + return ADJLogLevelSuppress; + // default value if string does not match return ADJLogLevelInfo; } From af5c807b8307cd07ca0908189c85e0e9423cd01b Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 27 Jul 2017 17:27:38 +0200 Subject: [PATCH 21/74] Rename connectivity and network type --- Adjust/ADJPackageBuilder.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 86f168a56..b3c1b0e09 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -252,8 +252,8 @@ - (void)injectDeviceInfo:(ADJDeviceInfo *)deviceInfo intoParameters:(NSMutableDi [ADJPackageBuilder parameters:parameters setString:deviceInfo.osBuild forKey:@"os_build"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMCC] forKey:@"mcc"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMNC] forKey:@"mnc"]; - [ADJPackageBuilder parameters:parameters setString:[ADJUtil readCurrentRadioAccessTechnology] forKey:@"ios_network_type"]; - [ADJPackageBuilder parameters:parameters setNumberInt:[ADJUtil readReachabilityFlags] forKey:@"ios_connectivity_type"]; + [ADJPackageBuilder parameters:parameters setString:[ADJUtil readCurrentRadioAccessTechnology] forKey:@"network_type"]; + [ADJPackageBuilder parameters:parameters setNumberInt:[ADJUtil readReachabilityFlags] forKey:@"connectivity_type"]; } - (void)injectConfig:(ADJConfig *)adjustConfig intoParameters:(NSMutableDictionary *) parameters { From 561a5250468938ad47b9d50c5e61566c9815532f Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 27 Jul 2017 18:21:36 +0200 Subject: [PATCH 22/74] Inject session parameters to builder --- Adjust/ADJActivityHandler.m | 26 +++++++++++++++++--------- Adjust/ADJPackageBuilder.h | 8 +++----- Adjust/ADJPackageBuilder.m | 31 ++++++++++++++----------------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index a3cb100ee..4acf9004b 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -432,11 +432,12 @@ - (void)sendIad3ClickPackage:(ADJActivityHandler *)selfI initWithDeviceInfo:selfI.deviceInfo activityState:selfI.activityState config:selfI.adjustConfig + sessionParameters:self.sessionParameters createdAt:now]; clickBuilder.attributionDetails = attributionDetails; - ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad3" sessionParameters:selfI.sessionParameters]; + ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad3"]; [selfI.sdkClickHandler sendSdkClick:clickPackage]; } @@ -649,6 +650,7 @@ - (void)initI:(ADJActivityHandler *)selfI initWithDeviceInfo:selfI.deviceInfo activityState:selfI.activityState config:selfI.adjustConfig + sessionParameters:selfI.sessionParameters createdAt:now]; ADJActivityPackage *attributionPackage = [attributionBuilder buildAttributionPackage]; selfI.attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:selfI @@ -742,8 +744,9 @@ - (void)transferSessionPackageI:(ADJActivityHandler *)selfI initWithDeviceInfo:selfI.deviceInfo activityState:selfI.activityState config:selfI.adjustConfig + sessionParameters:selfI.sessionParameters createdAt:now]; - ADJActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage:selfI.sessionParameters isInDelay:[selfI.internalState isInDelayedStart]]; + ADJActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage:[selfI.internalState isInDelayedStart]]; [selfI.packageHandler addPackage:sessionPackage]; [selfI.packageHandler sendFirstPackage]; } @@ -795,8 +798,10 @@ - (void)eventI:(ADJActivityHandler *)selfI initWithDeviceInfo:selfI.deviceInfo activityState:selfI.activityState config:selfI.adjustConfig + sessionParameters:selfI.sessionParameters createdAt:now]; - ADJActivityPackage *eventPackage = [eventBuilder buildEventPackage:event sessionParameters:selfI.sessionParameters isInDelay:[selfI.internalState isInDelayedStart]]; + ADJActivityPackage *eventPackage = [eventBuilder buildEventPackage:event + isInDelay:[selfI.internalState isInDelayedStart]]; [selfI.packageHandler addPackage:eventPackage]; if (selfI.adjustConfig.eventBufferingEnabled) { @@ -1118,13 +1123,14 @@ - (void)appWillOpenUrlI:(ADJActivityHandler *)selfI initWithDeviceInfo:selfI.deviceInfo activityState:selfI.activityState config:selfI.adjustConfig + sessionParameters:selfI.sessionParameters createdAt:now]; clickBuilder.deeplinkParameters = adjustDeepLinks; clickBuilder.attribution = deeplinkAttribution; clickBuilder.clickTime = [NSDate date]; clickBuilder.deeplink = [url absoluteString]; - ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"deeplink" sessionParameters:selfI.sessionParameters]; + ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"deeplink"]; [selfI.sdkClickHandler sendSdkClick:clickPackage]; } @@ -1202,10 +1208,11 @@ - (void)setDeviceTokenI:(ADJActivityHandler *)selfI // send info package double now = [NSDate.date timeIntervalSince1970]; ADJPackageBuilder * infoBuilder = [[ADJPackageBuilder alloc] - initWithDeviceInfo:selfI.deviceInfo - activityState:selfI.activityState - config:selfI.adjustConfig - createdAt:now]; + initWithDeviceInfo:selfI.deviceInfo + activityState:selfI.activityState + config:selfI.adjustConfig + sessionParameters:selfI.sessionParameters + createdAt:now]; ADJActivityPackage * infoPackage = [infoBuilder buildInfoPackage:@"push"]; @@ -1238,12 +1245,13 @@ - (void)setIadDateI:(ADJActivityHandler *)selfI initWithDeviceInfo:selfI.deviceInfo activityState:selfI.activityState config:selfI.adjustConfig + sessionParameters:selfI.sessionParameters createdAt:now]; clickBuilder.purchaseTime = appPurchaseDate; clickBuilder.clickTime = iAdImpressionDate; - ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad" sessionParameters:selfI.sessionParameters]; + ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad"]; [selfI.sdkClickHandler sendSdkClick:clickPackage]; } diff --git a/Adjust/ADJPackageBuilder.h b/Adjust/ADJPackageBuilder.h index b4eab24cd..2f2ed2117 100644 --- a/Adjust/ADJPackageBuilder.h +++ b/Adjust/ADJPackageBuilder.h @@ -30,19 +30,17 @@ - (id)initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo activityState:(ADJActivityState *)activityState config:(ADJConfig *)adjustConfig + sessionParameters:(ADJSessionParameters *)sessionParameters createdAt:(double)createdAt; -- (ADJActivityPackage *)buildSessionPackage:(ADJSessionParameters *)sessionParameters - isInDelay:(BOOL)isInDelay; +- (ADJActivityPackage *)buildSessionPackage:(BOOL)isInDelay; - (ADJActivityPackage *)buildAttributionPackage; - (ADJActivityPackage *)buildEventPackage:(ADJEvent *)event - sessionParameters:(ADJSessionParameters *)sessionParameters isInDelay:(BOOL)isInDelay; -- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource - sessionParameters:(ADJSessionParameters *)sessionParameters; +- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource; - (ADJActivityPackage *)buildInfoPackage:(NSString *)infoSource; diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index b3c1b0e09..4bfbbb471 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -24,6 +24,8 @@ @interface ADJPackageBuilder() @property (nonatomic, copy) ADJActivityState *activityState; +@property (nonatomic, weak) ADJSessionParameters *sessionParameters; + @end @implementation ADJPackageBuilder @@ -33,6 +35,7 @@ @implementation ADJPackageBuilder - (id)initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo activityState:(ADJActivityState *)activityState config:(ADJConfig *)adjustConfig + sessionParameters:(ADJSessionParameters *)sessionParameters createdAt:(double)createdAt { self = [super init]; @@ -44,20 +47,16 @@ - (id)initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo self.deviceInfo = deviceInfo; self.adjustConfig = adjustConfig; self.activityState = activityState; + self.sessionParameters = sessionParameters; return self; } #pragma mark - Public methods -- (ADJActivityPackage *)buildSessionPackage:(ADJSessionParameters *)sessionParameters - isInDelay:(BOOL)isInDelay { +- (ADJActivityPackage *)buildSessionPackage:(BOOL)isInDelay { NSMutableDictionary *parameters; - if (!isInDelay) { - parameters = [self attributableParameters:sessionParameters]; - } else { - parameters = [self attributableParameters:nil]; - } + parameters = [self attributableParameters:isInDelay]; ADJActivityPackage *sessionPackage = [self defaultActivityPackage]; sessionPackage.path = @"/session"; @@ -69,7 +68,6 @@ - (ADJActivityPackage *)buildSessionPackage:(ADJSessionParameters *)sessionParam } - (ADJActivityPackage *)buildEventPackage:(ADJEvent *)event - sessionParameters:(ADJSessionParameters *)sessionParameters isInDelay:(BOOL)isInDelay { NSMutableDictionary *parameters = [self defaultParameters]; @@ -79,10 +77,10 @@ - (ADJActivityPackage *)buildEventPackage:(ADJEvent *)event [ADJPackageBuilder parameters:parameters setString:event.eventToken forKey:@"event_token"]; if (!isInDelay) { - NSDictionary *mergedCallbackParameters = [ADJUtil mergeParameters:sessionParameters.callbackParameters + NSDictionary *mergedCallbackParameters = [ADJUtil mergeParameters:self.sessionParameters.callbackParameters source:event.callbackParameters parameterName:@"Callback"]; - NSDictionary *mergedPartnerParameters = [ADJUtil mergeParameters:sessionParameters.partnerParameters + NSDictionary *mergedPartnerParameters = [ADJUtil mergeParameters:self.sessionParameters.partnerParameters source:event.partnerParameters parameterName:@"Partner"]; @@ -117,10 +115,9 @@ - (ADJActivityPackage *)buildEventPackage:(ADJEvent *)event return eventPackage; } -- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource - sessionParameters:(ADJSessionParameters *)sessionParameters +- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource; { - NSMutableDictionary *parameters = [self attributableParameters:sessionParameters]; + NSMutableDictionary *parameters = [self attributableParameters:NO]; [ADJPackageBuilder parameters:parameters setString:clickSource forKey:@"source"]; [ADJPackageBuilder parameters:parameters setDictionary:self.deeplinkParameters forKey:@"params"]; @@ -194,7 +191,7 @@ - (NSMutableDictionary *)idsParameters { return parameters; } -- (NSMutableDictionary *)attributableParameters:(ADJSessionParameters *)sessionParameters { +- (NSMutableDictionary *)attributableParameters:(BOOL)isInDelay { NSMutableDictionary *parameters = [self defaultParameters]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil getUpdateTime] forKey:@"app_updated_at"]; @@ -202,9 +199,9 @@ - (NSMutableDictionary *)attributableParameters:(ADJSessionParameters *)sessionP [ADJPackageBuilder parameters:parameters setDuration:self.activityState.lastInterval forKey:@"last_interval"]; [ADJPackageBuilder parameters:parameters setString:self.adjustConfig.defaultTracker forKey:@"default_tracker"]; - if (sessionParameters != nil) { - [ADJPackageBuilder parameters:parameters setDictionary:sessionParameters.callbackParameters forKey:@"callback_params"]; - [ADJPackageBuilder parameters:parameters setDictionary:sessionParameters.partnerParameters forKey:@"partner_params"]; + if (!isInDelay) { + [ADJPackageBuilder parameters:parameters setDictionary:self.sessionParameters.callbackParameters forKey:@"callback_params"]; + [ADJPackageBuilder parameters:parameters setDictionary:self.sessionParameters.partnerParameters forKey:@"partner_params"]; } return parameters; From 711dbbcc9e00c0d3891e3f2e74879c2b554fb8e8 Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 27 Jul 2017 18:02:48 +0200 Subject: [PATCH 23/74] Set external device id --- Adjust/ADJActivityHandler.m | 13 ++++++++++++- Adjust/ADJConfig.h | 6 ++++++ Adjust/ADJConfig.m | 1 + Adjust/ADJPackageBuilder.m | 10 ++++++++++ Adjust/ADJSessionParameters.h | 3 ++- Adjust/ADJSessionParameters.m | 18 ++++++++++++++++++ 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 4acf9004b..db0592ebf 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -26,6 +26,7 @@ static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAttributionFilename = @"AdjustIoAttribution"; +static NSString * const kSessionParametersFilename = @"AdjustSessionParameters"; static NSString * const kSessionCallbackParametersFilename = @"AdjustSessionCallbackParameters"; static NSString * const kSessionPartnerParametersFilename = @"AdjustSessionPartnerParameters"; static NSString * const kAdjustPrefix = @"adjust_"; @@ -589,7 +590,7 @@ - (void)initI:(ADJActivityHandler *)selfI selfI.deviceInfo = [ADJDeviceInfo deviceInfoWithSdkPrefix:selfI.adjustConfig.sdkPrefix]; // read files that are accessed only in Internal sections - selfI.sessionParameters = [[ADJSessionParameters alloc] init]; + [selfI readSessionParameters:selfI]; [selfI readSessionCallbackParametersI:selfI]; [selfI readSessionPartnerParametersI:selfI]; @@ -1392,6 +1393,16 @@ - (void)teardownAllSessionParametersS:(BOOL)deleteState { } } +- (void)readSessionParameters:(ADJActivityHandler *)selfI { + selfI.sessionParameters = [ADJUtil readObject:kSessionParametersFilename + objectName:@"Session parameters" + class:[ADJSessionParameters class]]; + + if (selfI.sessionParameters == nil) { + selfI.sessionParameters = [[ADJSessionParameters alloc] init]; + } +} + - (void)readSessionCallbackParametersI:(ADJActivityHandler *)selfI { selfI.sessionParameters.callbackParameters = [ADJUtil readObject:kSessionCallbackParametersFilename objectName:@"Session Callback parameters" diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index f1769870e..8ef218a31 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -155,6 +155,12 @@ */ @property (nonatomic, assign) BOOL isDeviceKnown; +/** + * @brief Set the external device id. + */ + +@property (nonatomic, copy, nullable) NSString *externalDeviceId; + /** * @brief Get configuration object for the initialization of the Adjust SDK. * diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index e4c903847..fa70232d6 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -180,6 +180,7 @@ -(id)copyWithZone:(NSZone *)zone copy.delayStart = self.delayStart; copy.userAgent = [self.userAgent copyWithZone:zone]; copy.isDeviceKnown = self.isDeviceKnown; + copy.externalDeviceId = [self.externalDeviceId copyWithZone:zone]; // adjust delegate not copied } diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 4bfbbb471..55820375b 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -213,6 +213,7 @@ - (NSMutableDictionary *)defaultParameters { [self injectDeviceInfo:self.deviceInfo intoParameters:parameters]; [self injectConfig:self.adjustConfig intoParameters:parameters]; [self injectActivityState:self.activityState intoParamters:parameters]; + [self injectSessionParameters:self.sessionParameters intoParamters:parameters]; [self injectCommonParameters:parameters]; return parameters; @@ -299,6 +300,15 @@ - (void)injectPushToken:(ADJActivityState *)activityState intoParamters:(NSMutab [ADJPackageBuilder parameters:parameters setString:activityState.deviceToken forKey:@"push_token"]; } +- (void)injectSessionParameters:(ADJSessionParameters *)sessionParameters + intoParamters:(NSMutableDictionary *)parameters { + if (sessionParameters == nil) { + return; + } + + [ADJPackageBuilder parameters:parameters setString:sessionParameters.externalDeviceId forKey:@"external_device_id"]; +} + - (NSString *)eventSuffix:(ADJEvent *)event { if (event.revenue == nil) { return [NSString stringWithFormat:@"'%@'", event.eventToken]; diff --git a/Adjust/ADJSessionParameters.h b/Adjust/ADJSessionParameters.h index 603a89d0d..554d8f15a 100644 --- a/Adjust/ADJSessionParameters.h +++ b/Adjust/ADJSessionParameters.h @@ -8,9 +8,10 @@ #import -@interface ADJSessionParameters : NSObject +@interface ADJSessionParameters : NSObject @property (nonatomic, strong) NSMutableDictionary* callbackParameters; @property (nonatomic, strong) NSMutableDictionary* partnerParameters; +@property (nonatomic, copy) NSString *externalDeviceId; @end diff --git a/Adjust/ADJSessionParameters.m b/Adjust/ADJSessionParameters.m index 1d1f928a1..c3fed658d 100644 --- a/Adjust/ADJSessionParameters.m +++ b/Adjust/ADJSessionParameters.m @@ -10,6 +10,24 @@ @implementation ADJSessionParameters +#pragma mark - NSCoding protocol methods +- (id)initWithCoder:(NSCoder *)decoder { + self = [super init]; + + if (self == nil) { + return nil; + } + + self.externalDeviceId = [decoder decodeObjectForKey:@"externalDeviceId"]; + + return self; +} + +- (void)encodeWithCoder:(NSCoder *)encoder { + + [encoder encodeObject:self.externalDeviceId forKey:@"externalDeviceId"]; +} + #pragma mark - NSCopying -(id)copyWithZone:(NSZone *)zone { From 0d477ecc96bd76173d07ee2a0224b6df49b50de8 Mon Sep 17 00:00:00 2001 From: uerceg Date: Tue, 1 Aug 2017 11:23:32 +0200 Subject: [PATCH 24/74] Adjust files migration --- Adjust/ADJActivityHandler.m | 8 +- Adjust/ADJPackageHandler.m | 34 ++------ Adjust/ADJUtil.h | 6 +- Adjust/ADJUtil.m | 160 +++++++++++++++++++++++++++++------- 4 files changed, 145 insertions(+), 63 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index db0592ebf..d27e495e5 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -1304,7 +1304,7 @@ - (void)writeActivityStateI:(ADJActivityHandler *)selfI if (selfI.activityState == nil) { return; } - [ADJUtil writeObject:selfI.activityState filename:kActivityStateFilename objectName:@"Activity state"]; + [ADJUtil writeObject:selfI.activityState fileName:kActivityStateFilename objectName:@"Activity state"]; } } @@ -1326,7 +1326,7 @@ - (void)writeAttributionI:(ADJActivityHandler *)selfI { if (selfI.attribution == nil) { return; } - [ADJUtil writeObject:selfI.attribution filename:kAttributionFilename objectName:@"Attribution"]; + [ADJUtil writeObject:selfI.attribution fileName:kAttributionFilename objectName:@"Attribution"]; } } @@ -1362,7 +1362,7 @@ - (void)writeSessionCallbackParametersI:(ADJActivityHandler *)selfI { return; } [ADJUtil writeObject:selfI.sessionParameters.callbackParameters - filename:kSessionCallbackParametersFilename + fileName:kSessionCallbackParametersFilename objectName:@"Session Callback parameters"]; } } @@ -1373,7 +1373,7 @@ - (void)writeSessionPartnerParametersI:(ADJActivityHandler *)selfI { return; } [ADJUtil writeObject:selfI.sessionParameters.partnerParameters - filename:kSessionPartnerParametersFilename + fileName:kSessionPartnerParametersFilename objectName:@"Session Partner parameters"]; } } diff --git a/Adjust/ADJPackageHandler.m b/Adjust/ADJPackageHandler.m index 779ceaf5b..b1cab4b97 100644 --- a/Adjust/ADJPackageHandler.m +++ b/Adjust/ADJPackageHandler.m @@ -238,25 +238,13 @@ - (void)updatePackagesI:(ADJPackageHandler *)selfI #pragma mark - private - (void)readPackageQueueI:(ADJPackageHandler *)selfI { - @try { - [NSKeyedUnarchiver setClass:[ADJActivityPackage class] forClassName:@"AIActivityPackage"]; - NSString *filename = selfI.packageQueueFilename; - id object = [NSKeyedUnarchiver unarchiveObjectWithFile:filename]; - if ([object isKindOfClass:[NSArray class]]) { - selfI.packageQueue = object; - [selfI.logger debug:@"Package handler read %d packages", selfI.packageQueue.count]; - return; - } else if (object == nil) { - [selfI.logger verbose:@"Package queue file not found"]; - } else { - [selfI.logger error:@"Failed to read package queue"]; - } - } @catch (NSException *exception) { - [selfI.logger error:@"Failed to read package queue (%@)", exception]; - } + id object = [ADJUtil readObject:selfI.packageQueueFilename objectName:@"Package queue" class:[NSArray class]]; - // start with a fresh package queue in case of any exception - selfI.packageQueue = [NSMutableArray array]; + if (object != nil) { + selfI.packageQueue = object; + } else { + selfI.packageQueue = [NSMutableArray array]; + } } - (void)writePackageQueueS:(ADJPackageHandler *)selfS { @@ -264,14 +252,8 @@ - (void)writePackageQueueS:(ADJPackageHandler *)selfS { if (selfS.packageQueue == nil) { return; } - NSString *filename = selfS.packageQueueFilename; - BOOL result = [NSKeyedArchiver archiveRootObject:selfS.packageQueue toFile:filename]; - if (result == YES) { - [ADJUtil excludeFromBackup:filename]; - [selfS.logger debug:@"Package handler wrote %d packages", selfS.packageQueue.count]; - } else { - [selfS.logger error:@"Failed to write package queue"]; - } + + [ADJUtil writeObject:selfS.packageQueue fileName:selfS.packageQueueFilename objectName:@"Package queue"]; } } diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index 50a51c6f8..a95039e44 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -21,7 +21,7 @@ typedef void (^selfInjectedBlock)(id); + (void)teardown; -+ (id)readObject:(NSString *)filename ++ (id)readObject:(NSString *)fileName objectName:(NSString *)objectName class:(Class)classToRead; @@ -34,7 +34,7 @@ typedef void (^selfInjectedBlock)(id); + (void)updateUrlSessionConfiguration:(ADJConfig *)config; + (void)writeObject:(id)object - filename:(NSString *)filename + fileName:(NSString *)fileName objectName:(NSString *)objectName; + (void)launchInMainThread:(NSObject *)receiver @@ -81,8 +81,6 @@ responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler + (NSString *)queryString:(NSDictionary *)parameters; -+ (NSString *)getFullFilename:(NSString *)baseFilename; - + (NSString *)convertDeviceToken:(NSData *)deviceToken; + (BOOL)isNull:(id)value; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 0ee976756..066dbd01e 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -288,53 +288,155 @@ + (NSDictionary *)buildJsonDict:(NSData *)jsonData return jsonDict; } -+ (NSString *)getFullFilename:(NSString *)baseFilename { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *path = [paths objectAtIndex:0]; - NSString *filename = [path stringByAppendingPathComponent:baseFilename]; - - return filename; -} - -+ (id)readObject:(NSString *)filename ++ (id)readObject:(NSString *)fileName objectName:(NSString *)objectName - class:(Class) classToRead { - id logger = [ADJAdjustFactory logger]; + class:(Class)classToRead { + // Try to read from Application Support directory first. + NSString *documentsFilePath = [ADJUtil getFilePathInDocumentsDir:fileName]; + NSString *appSupportFilePath = [ADJUtil getFilePathInAppSupportDir:fileName]; @try { - NSString *fullFilename = [ADJUtil getFullFilename:filename]; - id object = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFilename]; - - if ([object isKindOfClass:classToRead]) { - [logger debug:@"Read %@: %@", objectName, object]; - return object; - } else if (object == nil) { - [logger verbose:@"%@ file not found", objectName]; + id appSupportObject = [NSKeyedUnarchiver unarchiveObjectWithFile:appSupportFilePath]; + + if ([appSupportObject isKindOfClass:classToRead]) { + // Successfully read object from Application Support folder, return it. + + if ([appSupportObject isKindOfClass:[NSArray class]]) { + [[ADJAdjustFactory logger] debug:@"Package handler read %d packages", [appSupportObject count]]; + } else { + [[ADJAdjustFactory logger] debug:@"Read %@: %@", objectName, appSupportObject]; + } + + // Just in case check if old file exists in Documents folder and if yes, remove it. + [ADJUtil deleteFile:documentsFilePath]; + + return appSupportObject; + } else if (appSupportObject == nil) { + [[ADJAdjustFactory logger] verbose:@"%@ file not found", objectName]; } else { - [logger error:@"Failed to read %@ file", objectName]; + [[ADJAdjustFactory logger] error:@"Failed to read %@ file", objectName]; } - } @catch (NSException *ex ) { - [logger error:@"Failed to read %@ file (%@)", objectName, ex]; + } @catch (NSException *ex) { + [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", objectName, ex]; } + // If in here, for some reason, reading of file from Application Support folder failed. + // Let's check the Documents folder. + + @try { + id documentsObject = [NSKeyedUnarchiver unarchiveObjectWithFile:documentsFilePath]; + + if (documentsObject != nil) { + // Successfully read object from Documents folder. + + [[ADJAdjustFactory logger] debug:@"Read %@: %@", objectName, documentsObject]; + + // Do the file migration and retry. + [ADJUtil migrateFileFromPath:documentsFilePath toPath:appSupportFilePath]; + + return [ADJUtil readObject:fileName objectName:objectName class:classToRead]; + } else if (documentsObject == nil) { + [[ADJAdjustFactory logger] verbose:@"%@ file not found", objectName]; + } else { + [[ADJAdjustFactory logger] error:@"Failed to read %@ file", objectName]; + } + } @catch (NSException *ex) { + [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", objectName, ex]; + } + return nil; } + (void)writeObject:(id)object - filename:(NSString *)filename + fileName:(NSString *)fileName objectName:(NSString *)objectName { - id logger = [ADJAdjustFactory logger]; - NSString *fullFilename = [ADJUtil getFullFilename:filename]; - BOOL result = [NSKeyedArchiver archiveRootObject:object toFile:fullFilename]; + NSString *filePath = [ADJUtil getFilePathInAppSupportDir:fileName]; + + BOOL result = [NSKeyedArchiver archiveRootObject:object toFile:filePath]; if (result == YES) { - [ADJUtil excludeFromBackup:fullFilename]; - [logger debug:@"Wrote %@: %@", objectName, object]; + [ADJUtil excludeFromBackup:filePath]; + + if ([object isKindOfClass:[NSArray class]]) { + [[ADJAdjustFactory logger] debug:@"Package handler wrote %d packages", [object count]]; + } else { + [[ADJAdjustFactory logger] debug:@"Wrote %@: %@", objectName, object]; + } } else { - [logger error:@"Failed to write %@ file", objectName]; + [[ADJAdjustFactory logger] error:@"Failed to write %@ file", objectName]; } } ++ (BOOL)migrateFileFromPath:(NSString *)oldPath toPath:(NSString *)newPath { + NSError *errorCopy; + + [[NSFileManager defaultManager] copyItemAtPath:oldPath toPath:newPath error:&errorCopy]; + + if (errorCopy != nil) { + [[ADJAdjustFactory logger] error:@"Error while copying from %@ to %@", oldPath, newPath]; + [[ADJAdjustFactory logger] error:[errorCopy description]]; + + return NO; + } + + // Migration successful. + return YES; +} + ++ (NSString *)getFilePathInDocumentsDir:(NSString *)fileName { + // Documents directory exists by default inside app bundle, no need to check for it's presence. + + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *documentsDir = [paths objectAtIndex:0]; + NSString *filePath = [documentsDir stringByAppendingPathComponent:fileName]; + + return filePath; +} + ++ (NSString *)getFilePathInAppSupportDir:(NSString *)fileName { + // Application Support directory doesn't exist by default inside app bundle. + // All Adjust files are going to be stored in Adjust sub-directory inside Application Support directory. + + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); + NSString *appSupportDir = [paths firstObject]; + + if (![ADJUtil checkForDirectoryPresence:appSupportDir]) { + return nil; + } + + NSString *adjustDir = [appSupportDir stringByAppendingPathComponent:@"/Adjust"]; + + if (![ADJUtil checkForDirectoryPresence:adjustDir]) { + return nil; + } + + NSString *filePath = [adjustDir stringByAppendingPathComponent:fileName]; + + return filePath; +} + ++ (BOOL)checkForDirectoryPresence:(NSString *)path { + // Check for presence of directory first. + // If it doesn't exist, make one. + + if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { + [[ADJAdjustFactory logger] debug:@"%@ directory not present and will be created", path]; + + NSError *error; + + [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:&error]; + + if (error != nil) { + [[ADJAdjustFactory logger] error:@"Error while creating % directory", path]; + [[ADJAdjustFactory logger] error:[error description]]; + + return NO; + } + } + + return YES; +} + + (NSString *)queryString:(NSDictionary *)parameters { return [ADJUtil queryString:parameters queueSize:0]; } From e18958992d8887a1c0e30c15df670b0c823b8fec Mon Sep 17 00:00:00 2001 From: uerceg Date: Tue, 1 Aug 2017 11:48:04 +0200 Subject: [PATCH 25/74] Use path in deleteFile method --- Adjust/ADJUtil.m | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 066dbd01e..11ce47bf0 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -1011,33 +1011,22 @@ + (void)launchInQueue:(dispatch_queue_t)queue }); } -+ (NSString *)getFilename:(NSString *)filename { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *path = [paths objectAtIndex:0]; - NSString *filepath = [path stringByAppendingPathComponent:filename]; - - return filepath; -} - -+ (BOOL)deleteFile:(NSString *)filename { - NSString *filepath = [ADJUtil getFilename:filename]; - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSError *error = nil; - BOOL exists = [fileManager fileExistsAtPath:filepath]; ++ (BOOL)deleteFile:(NSString *)filePath { + NSError *error; - if (!exists) { - [ADJAdjustFactory.logger verbose:@"File %@ does not exist at path %@", filename, filepath]; + if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { + [[ADJAdjustFactory logger] verbose:@"File does not exist at path %@", filePath]; return YES; } - BOOL deleted = [fileManager removeItemAtPath:filepath error:&error]; + BOOL deleted = [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; if (!deleted) { - [ADJAdjustFactory.logger verbose:@"Unable to delete file %@ at path %@", filename, filepath]; + [[ADJAdjustFactory logger] verbose:@"Unable to delete file at path %@", filePath]; } if (error) { - [ADJAdjustFactory.logger error:@"Error (%@) deleting file %@", [error localizedDescription], filename]; + [[ADJAdjustFactory logger] error:@"Error while deleting file at path %@", filePath]; } return deleted; From 26daf14649315638352a295fa786518d0867d0bb Mon Sep 17 00:00:00 2001 From: uerceg Date: Tue, 1 Aug 2017 12:00:09 +0200 Subject: [PATCH 26/74] Send file name, not the path from ADJPackageHandler --- Adjust/ADJPackageHandler.m | 23 ++++++++--------------- Adjust/ADJUtil.m | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Adjust/ADJPackageHandler.m b/Adjust/ADJPackageHandler.m index b1cab4b97..e844f6a88 100644 --- a/Adjust/ADJPackageHandler.m +++ b/Adjust/ADJPackageHandler.m @@ -238,7 +238,7 @@ - (void)updatePackagesI:(ADJPackageHandler *)selfI #pragma mark - private - (void)readPackageQueueI:(ADJPackageHandler *)selfI { - id object = [ADJUtil readObject:selfI.packageQueueFilename objectName:@"Package queue" class:[NSArray class]]; + id object = [ADJUtil readObject:kPackageQueueFilename objectName:@"Package queue" class:[NSArray class]]; if (object != nil) { selfI.packageQueue = object; @@ -253,34 +253,27 @@ - (void)writePackageQueueS:(ADJPackageHandler *)selfS { return; } - [ADJUtil writeObject:selfS.packageQueue fileName:selfS.packageQueueFilename objectName:@"Package queue"]; + [ADJUtil writeObject:selfS.packageQueue fileName:kPackageQueueFilename objectName:@"Package queue"]; } } -- (void)teardownPackageQueueS:(BOOL)deleteState -{ +- (void)teardownPackageQueueS:(BOOL)deleteState { @synchronized ([ADJPackageHandler class]) { if (self.packageQueue == nil) { return; } + if (deleteState) { - [ADJUtil deleteFile:self.packageQueueFilename]; + [ADJUtil deleteFile:kPackageQueueFilename]; } - [self.packageQueue removeAllObjects]; + [self.packageQueue removeAllObjects]; self.packageQueue = nil; } } -- (NSString *)packageQueueFilename { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *path = [paths objectAtIndex:0]; - NSString *filename = [path stringByAppendingPathComponent:kPackageQueueFilename]; - return filename; -} - --(void)dealloc { - //cleanup code +- (void)dealloc { + // Cleanup code if (self.sendingSemaphore != nil) { dispatch_semaphore_signal(self.sendingSemaphore); } diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 11ce47bf0..88e47c6dc 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -1015,7 +1015,7 @@ + (BOOL)deleteFile:(NSString *)filePath { NSError *error; if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { - [[ADJAdjustFactory logger] verbose:@"File does not exist at path %@", filePath]; + // [[ADJAdjustFactory logger] verbose:@"File does not exist at path %@", filePath]; return YES; } From 1a6e05506748179554c820fec1913bf0b46b9deb Mon Sep 17 00:00:00 2001 From: uerceg Date: Tue, 1 Aug 2017 13:29:08 +0200 Subject: [PATCH 27/74] Return object read from old file after migration --- Adjust/ADJUtil.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 88e47c6dc..cb88360b0 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -331,10 +331,10 @@ + (id)readObject:(NSString *)fileName [[ADJAdjustFactory logger] debug:@"Read %@: %@", objectName, documentsObject]; - // Do the file migration and retry. + // Do the file migration. [ADJUtil migrateFileFromPath:documentsFilePath toPath:appSupportFilePath]; - return [ADJUtil readObject:fileName objectName:objectName class:classToRead]; + return documentsObject; } else if (documentsObject == nil) { [[ADJAdjustFactory logger] verbose:@"%@ file not found", objectName]; } else { From dca40a9453891c86f5e7609308047fb3a84e2303 Mon Sep 17 00:00:00 2001 From: uerceg Date: Tue, 1 Aug 2017 13:50:42 +0200 Subject: [PATCH 28/74] Print paths and check for NSArray in Documents folder as well --- Adjust/ADJUtil.m | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index cb88360b0..c01a4acfb 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -312,12 +312,12 @@ + (id)readObject:(NSString *)fileName return appSupportObject; } else if (appSupportObject == nil) { - [[ADJAdjustFactory logger] verbose:@"%@ file not found", objectName]; + [[ADJAdjustFactory logger] verbose:@"%@ file not found", appSupportFilePath]; } else { - [[ADJAdjustFactory logger] error:@"Failed to read %@ file", objectName]; + [[ADJAdjustFactory logger] error:@"Failed to read %@ file", appSupportFilePath]; } } @catch (NSException *ex) { - [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", objectName, ex]; + [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", appSupportFilePath, ex]; } // If in here, for some reason, reading of file from Application Support folder failed. @@ -329,19 +329,23 @@ + (id)readObject:(NSString *)fileName if (documentsObject != nil) { // Successfully read object from Documents folder. - [[ADJAdjustFactory logger] debug:@"Read %@: %@", objectName, documentsObject]; + if ([documentsObject isKindOfClass:[NSArray class]]) { + [[ADJAdjustFactory logger] debug:@"Package handler read %d packages", [documentsObject count]]; + } else { + [[ADJAdjustFactory logger] debug:@"Read %@: %@", objectName, documentsObject]; + } // Do the file migration. [ADJUtil migrateFileFromPath:documentsFilePath toPath:appSupportFilePath]; return documentsObject; } else if (documentsObject == nil) { - [[ADJAdjustFactory logger] verbose:@"%@ file not found", objectName]; + [[ADJAdjustFactory logger] verbose:@"%@ file not found", documentsFilePath]; } else { - [[ADJAdjustFactory logger] error:@"Failed to read %@ file", objectName]; + [[ADJAdjustFactory logger] error:@"Failed to read %@ file", documentsFilePath]; } } @catch (NSException *ex) { - [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", objectName, ex]; + [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", documentsFilePath, ex]; } return nil; From 780a21546e08a4e58472fb4968826239f5edf6f1 Mon Sep 17 00:00:00 2001 From: nonelse Date: Tue, 8 Aug 2017 13:15:52 +0200 Subject: [PATCH 29/74] Add auth header --- Adjust/ADJAdditions/NSString+ADJAdditions.h | 1 + Adjust/ADJAdditions/NSString+ADJAdditions.m | 12 ++ Adjust/ADJAttributionHandler.m | 7 ++ Adjust/ADJConfig.h | 13 ++ Adjust/ADJConfig.m | 12 ++ Adjust/ADJPackageBuilder.m | 1 + Adjust/ADJUtil.h | 5 + Adjust/ADJUtil.m | 127 +++++++++++++++++++- 8 files changed, 177 insertions(+), 1 deletion(-) diff --git a/Adjust/ADJAdditions/NSString+ADJAdditions.h b/Adjust/ADJAdditions/NSString+ADJAdditions.h index 6ec8a711a..6d1db9eb4 100644 --- a/Adjust/ADJAdditions/NSString+ADJAdditions.h +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.h @@ -9,6 +9,7 @@ @interface NSString(ADJAdditions) +- (NSString *)adjMd5; - (NSString *)adjSha1; - (NSString *)adjTrim; - (NSString *)adjUrlEncode; diff --git a/Adjust/ADJAdditions/NSString+ADJAdditions.m b/Adjust/ADJAdditions/NSString+ADJAdditions.m index 90cf1bdad..0da0d98b0 100644 --- a/Adjust/ADJAdditions/NSString+ADJAdditions.m +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.m @@ -43,6 +43,18 @@ - (NSString *)adjRemoveColons { return [self stringByReplacingOccurrencesOfString:@":" withString:@""]; } +- (NSString *)adjMd5 { + const char *cStr = [self UTF8String]; + unsigned char digest[16]; + CC_MD5(cStr, (CC_LONG)strlen(cStr), digest); + + NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; + for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { + [output appendFormat:@"%02x", digest[i]]; + } + return output; +} + - (NSString *)adjSha1 { NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding]; uint8_t digest[CC_SHA1_DIGEST_LENGTH]; diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 5f506f8b6..388929b65 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -215,12 +215,19 @@ - (void)waitRequestAttributionWithDelayI:(ADJAttributionHandler*)selfI #pragma mark - private - (NSMutableURLRequest *)requestI:(ADJAttributionHandler*)selfI { + NSString * appSecret = [ADJUtil extractAppSecret:selfI.attributionPackage]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[selfI urlI:selfI]]; request.timeoutInterval = kRequestTimeout; request.HTTPMethod = @"GET"; [request setValue:selfI.attributionPackage.clientSdk forHTTPHeaderField:@"Client-Sdk"]; + NSString * authHeader = [ADJUtil buildAuthorizationHeader:appSecret activityPackage:selfI.attributionPackage]; + if (authHeader != nil) { + [request setValue:authHeader forHTTPHeaderField:@"authHeader"]; + } + return request; } diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index 8ef218a31..342f95ac0 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -161,6 +161,19 @@ @property (nonatomic, copy, nullable) NSString *externalDeviceId; +/** + * @brief Adjust app secret. + */ +@property (nonatomic, copy, readonly, nonnull) NSString *appSecretS; + +/** + * @brief Adjust set app secret. + */ +- (void)setAppSecret:(NSUInteger)info1 + info2:(NSUInteger)info2 + info3:(NSUInteger)info3 + info4:(NSUInteger)info4; + /** * @brief Get configuration object for the initialization of the Adjust SDK. * diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index fa70232d6..2ef575df6 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -166,6 +166,17 @@ - (BOOL)isValid { return self.appToken != nil; } +- (void)setAppSecret:(NSUInteger)info1 + info2:(NSUInteger)info2 + info3:(NSUInteger)info3 + info4:(NSUInteger)info4 { + _appSecretS = [NSString stringWithFormat:@"%lu%lu%lu%lu", + (unsigned long)info1, + (unsigned long)info2, + (unsigned long)info3, + (unsigned long)info4]; +} + -(id)copyWithZone:(NSZone *)zone { ADJConfig* copy = [[[self class] allocWithZone:zone] init]; @@ -181,6 +192,7 @@ -(id)copyWithZone:(NSZone *)zone copy.userAgent = [self.userAgent copyWithZone:zone]; copy.isDeviceKnown = self.isDeviceKnown; copy.externalDeviceId = [self.externalDeviceId copyWithZone:zone]; + copy->_appSecretS = [self.appSecretS copyWithZone:zone]; // adjust delegate not copied } diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 55820375b..0235f843d 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -261,6 +261,7 @@ - (void)injectConfig:(ADJConfig *)adjustConfig intoParameters:(NSMutableDictiona if (adjustConfig.isDeviceKnown) { [ADJPackageBuilder parameters:parameters setBool:adjustConfig.isDeviceKnown forKey:@"device_known"]; } + [ADJPackageBuilder parameters:parameters setString:adjustConfig.appSecretS forKey:@"app_secret"]; } - (void)injectActivityState:(ADJActivityState *)activityState intoParamters:(NSMutableDictionary *)parameters { diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index a95039e44..b9aaa37d2 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -117,4 +117,9 @@ responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler + (NSNumber *)readReachabilityFlags; + (NSString *)readCurrentRadioAccessTechnology; + ++ (NSString *)extractAppSecret:(ADJActivityPackage *)activityPackage; + ++ (NSString *)buildAuthorizationHeader:(NSString *)appSecret + activityPackage:(ADJActivityPackage *)activityPackage; @end diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index c01a4acfb..6853069b3 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -504,9 +504,17 @@ + (void)sendPostRequest:(NSURL *)baseUrl prefixErrorMessage:(NSString *)prefixErrorMessage suffixErrorMessage:(NSString *)suffixErrorMessage activityPackage:(ADJActivityPackage *)activityPackage - responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { + responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler +{ + NSString * appSecret = [ADJUtil extractAppSecret:activityPackage]; + NSMutableURLRequest *request = [ADJUtil requestForPackage:activityPackage baseUrl:baseUrl queueSize:queueSize]; + NSString * authHeader = [ADJUtil buildAuthorizationHeader:appSecret activityPackage:activityPackage]; + if (authHeader != nil) { + [request setValue:authHeader forHTTPHeaderField:@"authHeader"]; + } + [ADJUtil sendRequest:request prefixErrorMessage:prefixErrorMessage suffixErrorMessage:suffixErrorMessage @@ -514,6 +522,17 @@ + (void)sendPostRequest:(NSURL *)baseUrl responseDataHandler:responseDataHandler]; } ++ (NSString *)extractAppSecret:(ADJActivityPackage *)activityPackage { + NSString * appSecret = [activityPackage.parameters objectForKey:@"app_secret"]; + if (appSecret == nil) { + return nil; + } + + [activityPackage.parameters removeObjectForKey:@"app_secret"]; + + return appSecret; +} + + (NSMutableURLRequest *)requestForPackage:(ADJActivityPackage *)activityPackage baseUrl:(NSURL *)baseUrl queueSize:(NSUInteger)queueSize { @@ -532,6 +551,112 @@ + (NSMutableURLRequest *)requestForPackage:(ADJActivityPackage *)activityPackage return request; } ++ (NSString *)buildAuthorizationHeader:(NSString *)appSecret + activityPackage:(ADJActivityPackage *)activityPackage { + if (appSecret == nil) { + return nil; + } + NSMutableDictionary * parameters = activityPackage.parameters; + NSString * clientSdk = activityPackage.clientSdk; + NSString * activityKindS = [ADJActivityKindUtil activityKindToString:activityPackage.activityKind]; + + + NSDictionary * signatureParameters = [ADJUtil buildSignatureParameters:parameters + appSecret:appSecret + clientSdk:clientSdk + activityKindS:activityKindS]; + + NSMutableString * fields = [[NSMutableString alloc] initWithCapacity:5]; + NSMutableString * clearSignature = [[NSMutableString alloc] initWithCapacity:5]; + + // signature part of header + for (NSDictionary * key in signatureParameters) { + [fields appendFormat:@"%@ ", key]; + + NSString * value = [signatureParameters objectForKey:key]; + [clearSignature appendString:value]; + } + + // algorithm part of header + NSString * algorithmHeader = @"md5"; + + NSString * signature = [clearSignature adjMd5]; + NSString * signatureHeader = [NSString stringWithFormat:@"signature=\"%@\"", signature]; + + // fields part of header + // Remove last empty space. + if (fields.length > 0) { + [fields deleteCharactersInRange:NSMakeRange(fields.length - 1, 1)]; + } + NSString * fieldsHeader = [NSString stringWithFormat:@"headers=\"%@\"", fields]; + + // putting it all together + NSString * authorizationHeader = [NSString stringWithFormat:@"Signature %@,%@,%@", signatureHeader, algorithmHeader, fieldsHeader]; + + return authorizationHeader; +} + ++ (NSDictionary *)buildSignatureParameters:(NSMutableDictionary *)parameters + appSecret:(NSString *)appSecret + clientSdk:(NSString *)clientSdk + activityKindS:(NSString *)activityKindS +{ + NSString * sdkVersionName = @"sdk_version"; + NSString * sdkVersionValue = clientSdk; + + NSString * appVersionName = @"app_version"; + NSString * appVersionValue = [parameters objectForKey:appVersionName]; + + NSString * activityKindName = @"activity_kind"; + NSString * activityKindValue = activityKindS; + + NSString * createdAtName = @"created_at"; + NSString * createdAtValue = [parameters objectForKey:createdAtName]; + + NSString * deviceIdentifierName = [ADJUtil getValidIdentifier:parameters]; + NSString * deviceIdentifierValue = [parameters objectForKey:deviceIdentifierName]; + + NSMutableDictionary * signatureParameters = [[NSMutableDictionary alloc] initWithCapacity:6]; + + [ADJUtil checkAndAddEntry:signatureParameters key:@"app_secret" value:appSecret]; + [ADJUtil checkAndAddEntry:signatureParameters key:sdkVersionName value:sdkVersionValue]; + [ADJUtil checkAndAddEntry:signatureParameters key:appVersionName value:appVersionValue]; + [ADJUtil checkAndAddEntry:signatureParameters key:createdAtName value:createdAtValue]; + [ADJUtil checkAndAddEntry:signatureParameters key:activityKindName value:activityKindValue]; + [ADJUtil checkAndAddEntry:signatureParameters key:deviceIdentifierName value:deviceIdentifierValue]; + + return signatureParameters; +} + ++ (void)checkAndAddEntry:(NSMutableDictionary *)parameters + key:(NSString *)key + value:(NSString *)value { + if (key == nil) { + return; + } + if (value == nil) { + return; + } + [parameters setObject:value forKey:key]; +} + ++ (NSString *)getValidIdentifier:(NSMutableDictionary *)parameters { + NSString * idfaName = @"idfa"; + NSString * persistentUUIDName = @"persistent_ios_uuid"; + NSString * uUIDName = @"ios_uuid"; + + if ([parameters objectForKey:idfaName] != nil) { + return idfaName; + } + if ([parameters objectForKey:persistentUUIDName] != nil) { + return persistentUUIDName; + } + if ([parameters objectForKey:uUIDName] != nil) { + return uUIDName; + } + return nil; +} + + (void)sendRequest:(NSMutableURLRequest *)request prefixErrorMessage:(NSString *)prefixErrorMessage activityPackage:(ADJActivityPackage *)activityPackage From 4f9a1301f6bbe722d2b4086db6013a1c23433a0e Mon Sep 17 00:00:00 2001 From: nonelse Date: Wed, 16 Aug 2017 16:15:09 +0200 Subject: [PATCH 30/74] Rename sdk click factory method --- Adjust/ADJActivityHandler.m | 6 +++--- Adjust/ADJAdjustFactory.h | 4 ++-- Adjust/ADJAdjustFactory.m | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index d27e495e5..e35a1fd12 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -659,9 +659,9 @@ - (void)initI:(ADJActivityHandler *)selfI startsSending:[selfI toSendI:selfI sdkClickHandlerOnly:NO]]; - selfI.sdkClickHandler = [ADJAdjustFactory sdkClickHandlerWithStartsPaused:selfI - startsSending:[selfI toSendI:selfI - sdkClickHandlerOnly:YES]]; + selfI.sdkClickHandler = [ADJAdjustFactory sdkClickHandlerForActivityHandler:selfI + startsSending:[selfI toSendI:selfI + sdkClickHandlerOnly:YES]]; [[UIDevice currentDevice] adjSetIad:selfI triesV3Left:kTryIadV3]; diff --git a/Adjust/ADJAdjustFactory.h b/Adjust/ADJAdjustFactory.h index 81c45381f..f134db80b 100644 --- a/Adjust/ADJAdjustFactory.h +++ b/Adjust/ADJAdjustFactory.h @@ -23,8 +23,8 @@ + (id)requestHandlerForPackageHandler:(id)packageHandler; + (id)activityHandlerWithConfig:(ADJConfig *)adjustConfig savedPreLaunch:(ADJSavedPreLaunch *)savedPreLaunch; -+ (id)sdkClickHandlerWithStartsPaused:(id)activityHandler - startsSending:(BOOL)startsSending; ++ (id)sdkClickHandlerForActivityHandler:(id)activityHandler + startsSending:(BOOL)startsSending; + (id)logger; + (double)sessionInterval; diff --git a/Adjust/ADJAdjustFactory.m b/Adjust/ADJAdjustFactory.m index 35c686bbd..9ba60bef5 100644 --- a/Adjust/ADJAdjustFactory.m +++ b/Adjust/ADJAdjustFactory.m @@ -119,8 +119,8 @@ + (ADJBackoffStrategy *)sdkClickHandlerBackoffStrategy { startsSending:startsSending]; } -+ (id)sdkClickHandlerWithStartsPaused:(id)activityHandler - startsSending:(BOOL)startsSending ++ (id)sdkClickHandlerForActivityHandler:(id)activityHandler + startsSending:(BOOL)startsSending { if (internalSdkClickHandler == nil) { return [ADJSdkClickHandler handlerWithActivityHandler:activityHandler startsSending:startsSending]; From a5e4c1faee9f4f7e135408c3706e597f7c155c20 Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 17 Aug 2017 11:06:17 +0200 Subject: [PATCH 31/74] Use sha256 --- Adjust/ADJAdditions/NSString+ADJAdditions.h | 1 + Adjust/ADJAdditions/NSString+ADJAdditions.m | 15 ++++++++++++++- Adjust/ADJUtil.m | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Adjust/ADJAdditions/NSString+ADJAdditions.h b/Adjust/ADJAdditions/NSString+ADJAdditions.h index 6d1db9eb4..f3a14dfa3 100644 --- a/Adjust/ADJAdditions/NSString+ADJAdditions.h +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.h @@ -11,6 +11,7 @@ - (NSString *)adjMd5; - (NSString *)adjSha1; +- (NSString *)adjSha256; - (NSString *)adjTrim; - (NSString *)adjUrlEncode; - (NSString *)adjUrlDecode; diff --git a/Adjust/ADJAdditions/NSString+ADJAdditions.m b/Adjust/ADJAdditions/NSString+ADJAdditions.m index 0da0d98b0..b14e6938d 100644 --- a/Adjust/ADJAdditions/NSString+ADJAdditions.m +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.m @@ -45,7 +45,7 @@ - (NSString *)adjRemoveColons { - (NSString *)adjMd5 { const char *cStr = [self UTF8String]; - unsigned char digest[16]; + unsigned char digest[CC_MD5_DIGEST_LENGTH]; CC_MD5(cStr, (CC_LONG)strlen(cStr), digest); NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; @@ -70,6 +70,19 @@ - (NSString *)adjSha1 { return output; } +- (NSString *)adjSha256 { + const char* str = [self UTF8String]; + unsigned char result[CC_SHA256_DIGEST_LENGTH]; + CC_SHA256(str, (CC_LONG)strlen(str), result); + + NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH*2]; + for(int i = 0; i Date: Thu, 17 Aug 2017 10:09:04 +0200 Subject: [PATCH 32/74] Adding ADJUserDefaults class --- Adjust/ADJUserDefaults.h | 23 +++++++++++++++ Adjust/ADJUserDefaults.m | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 Adjust/ADJUserDefaults.h create mode 100644 Adjust/ADJUserDefaults.m diff --git a/Adjust/ADJUserDefaults.h b/Adjust/ADJUserDefaults.h new file mode 100644 index 000000000..147822592 --- /dev/null +++ b/Adjust/ADJUserDefaults.h @@ -0,0 +1,23 @@ +// +// ADJUserDefaults.h +// Adjust +// +// Created by Uglješa Erceg on 16.08.17. +// Copyright © 2017 adjust GmbH. All rights reserved. +// + +#import + +@interface ADJUserDefaults : NSObject + ++ (void)savePushToken:(NSString *)pushToken; + ++ (NSString *)getPushToken; + ++ (void)removePushToken; + ++ (void)setInstallTracked; + ++ (BOOL)getInstallTracked; + +@end diff --git a/Adjust/ADJUserDefaults.m b/Adjust/ADJUserDefaults.m new file mode 100644 index 000000000..01dd28545 --- /dev/null +++ b/Adjust/ADJUserDefaults.m @@ -0,0 +1,64 @@ +// +// ADJUserDefaults.m +// Adjust +// +// Created by Uglješa Erceg on 16.08.17. +// Copyright © 2017 adjust GmbH. All rights reserved. +// + +#import "ADJUserDefaults.h" + +static NSString * const PREFS_KEY_PUSH_TOKEN = @"adj_push_token"; +static NSString * const PREFS_KEY_INSTALL_TRACKED = @"adj_install_tracked"; + +@implementation ADJUserDefaults + +#pragma mark - Object lifecycle methods + ++ (id)getInstance { + static ADJUserDefaults *defaultInstance = nil; + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{ + defaultInstance = [[self alloc] init]; + }); + + return defaultInstance; +} + +- (id)init { + self = [super init]; + + if (self == nil) { + return nil; + } + + return self; +} + +#pragma mark - Public methods + ++ (void)savePushToken:(NSString *)pushToken { + [[NSUserDefaults standardUserDefaults] setObject:pushToken forKey:PREFS_KEY_PUSH_TOKEN]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + ++ (NSString *)getPushToken { + return [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_KEY_PUSH_TOKEN]; +} + ++ (void)removePushToken { + [[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_PUSH_TOKEN]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + ++ (void)setInstallTracked { + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:PREFS_KEY_INSTALL_TRACKED]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + ++ (BOOL)getInstallTracked { + return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_KEY_INSTALL_TRACKED]; +} + +@end From ba5ae978c3a242cb798759d5ba33665176e60ce8 Mon Sep 17 00:00:00 2001 From: uerceg Date: Thu, 17 Aug 2017 10:10:55 +0200 Subject: [PATCH 33/74] Enable/disable logic update feat Adjust.m cleanup --- Adjust.xcodeproj/project.pbxproj | 8 ++ Adjust/ADJActivityHandler.m | 41 +++++--- Adjust/Adjust.h | 2 +- Adjust/Adjust.m | 161 ++++++++++++++++++------------- 4 files changed, 133 insertions(+), 79 deletions(-) diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index a2af4fe63..f65fb9e12 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -149,6 +149,8 @@ 9D7431F81EB9F9B700969F14 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9D7431F61EB9F9B700969F14 /* LaunchScreen.storyboard */; }; 9DB457B01D743704004D69E8 /* ADJBackoffStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF9C8DF1D6F3CA5008E362F /* ADJBackoffStrategy.m */; }; 9DB457B11D743704004D69E8 /* ADJSdkClickHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF9C8F71D6F3CA5008E362F /* ADJSdkClickHandler.m */; }; + 9DD0E9AE1F44690B00B2A759 /* ADJUserDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 9DD0E9AC1F44690B00B2A759 /* ADJUserDefaults.h */; }; + 9DD0E9AF1F44690B00B2A759 /* ADJUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD0E9AD1F44690B00B2A759 /* ADJUserDefaults.m */; }; 9DE7C8FD1AE688DA001556E5 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9DE7C8FC1AE688DA001556E5 /* UIKit.framework */; }; 9DF9C8B31D6ED228008E362F /* ADJKeychain.h in Headers */ = {isa = PBXBuildFile; fileRef = 9DF9C8B11D6ED228008E362F /* ADJKeychain.h */; }; 9DF9C8B41D6ED228008E362F /* ADJKeychain.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF9C8B21D6ED228008E362F /* ADJKeychain.m */; }; @@ -525,6 +527,8 @@ 9D75F1841D07460600E5D222 /* adjust_config.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = adjust_config.js; sourceTree = ""; }; 9D75F1851D07460600E5D222 /* adjust_event.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = adjust_event.js; sourceTree = ""; }; 9D75F1861D07460600E5D222 /* adjust.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = adjust.js; sourceTree = ""; }; + 9DD0E9AC1F44690B00B2A759 /* ADJUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUserDefaults.h; sourceTree = ""; }; + 9DD0E9AD1F44690B00B2A759 /* ADJUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserDefaults.m; sourceTree = ""; }; 9DE7C8FC1AE688DA001556E5 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 9DF9C8B11D6ED228008E362F /* ADJKeychain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJKeychain.h; sourceTree = ""; }; 9DF9C8B21D6ED228008E362F /* ADJKeychain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJKeychain.m; sourceTree = ""; }; @@ -864,6 +868,8 @@ 96B6710F1D788EEC0090A023 /* ADJSessionParameters.m */, 6FCC84F81F278CF300D6A0ED /* ADJReachability.h */, 6FCC84F71F278CF300D6A0ED /* ADJReachability.m */, + 9DD0E9AC1F44690B00B2A759 /* ADJUserDefaults.h */, + 9DD0E9AD1F44690B00B2A759 /* ADJUserDefaults.m */, ); path = Adjust; sourceTree = ""; @@ -1202,6 +1208,7 @@ 96BCFBD21AC99332005A65C5 /* NSString+ADJAdditions.h in Headers */, 96BCFBD31AC99336005A65C5 /* UIDevice+ADJAdditions.h in Headers */, 96BCFBD51AC9933E005A65C5 /* ADJActivityHandler.h in Headers */, + 9DD0E9AE1F44690B00B2A759 /* ADJUserDefaults.h in Headers */, 96BCFBD61AC99345005A65C5 /* ADJActivityKind.h in Headers */, 96BCFBD71AC99348005A65C5 /* ADJActivityPackage.h in Headers */, 96BCFBD81AC9934B005A65C5 /* ADJActivityState.h in Headers */, @@ -1691,6 +1698,7 @@ 96164D731CC8FA73009431AB /* ADJSdkClickHandler.m in Sources */, 9DF9C8B41D6ED228008E362F /* ADJKeychain.m in Sources */, 96B671111D788EEC0090A023 /* ADJSessionParameters.m in Sources */, + 9DD0E9AF1F44690B00B2A759 /* ADJUserDefaults.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index e35a1fd12..6431e8e87 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -21,6 +21,7 @@ #import "NSString+ADJAdditions.h" #import "ADJSdkClickHandler.h" #import "ADJSessionParameters.h" +#import "ADJUserDefaults.h" typedef void (^activityHandlerBlockI)(ADJActivityHandler * activityHandler); @@ -690,11 +691,11 @@ - (void)processSessionI:(ADJActivityHandler *)selfI { // very first session if (selfI.activityState == nil) { selfI.activityState = [[ADJActivityState alloc] init]; - selfI.activityState.sessionCount = 1; // this is the first session selfI.activityState.deviceToken = [ADJUtil convertDeviceToken:selfI.deviceTokenData]; // track the first session package only if it's enabled if ([selfI.internalState isEnabled]) { + selfI.activityState.sessionCount = 1; // this is the first session [selfI transferSessionPackageI:selfI now:now]; } @@ -715,12 +716,7 @@ - (void)processSessionI:(ADJActivityHandler *)selfI { // new session if (lastInterval > kSessionInterval) { - selfI.activityState.sessionCount++; - selfI.activityState.lastInterval = lastInterval; - - [selfI transferSessionPackageI:selfI now:now]; - [selfI.activityState resetSessionAttributes:now]; - [selfI writeActivityStateI:selfI]; + [self trackNewSessionI:now withActivityHandler:selfI]; return; } @@ -739,6 +735,17 @@ - (void)processSessionI:(ADJActivityHandler *)selfI { [selfI.logger verbose:@"Time span since last activity too short for a new subsession"]; } +- (void)trackNewSessionI:(double)now withActivityHandler:(ADJActivityHandler *)selfI { + double lastInterval = now - selfI.activityState.lastActivity; + + selfI.activityState.sessionCount++; + selfI.activityState.lastInterval = lastInterval; + + [selfI transferSessionPackageI:selfI now:now]; + [selfI.activityState resetSessionAttributes:now]; + [selfI writeActivityStateI:selfI]; +} + - (void)transferSessionPackageI:(ADJActivityHandler *)selfI now:(double)now { ADJPackageBuilder *sessionBuilder = [[ADJPackageBuilder alloc] @@ -851,6 +858,11 @@ - (void)launchSessionResponseTasksI:(ADJActivityHandler *)selfI BOOL toLaunchAttributionDelegate = [selfI updateAttributionI:selfI attribution:sessionResponseData.attribution]; + // mark install as tracked on success + if (sessionResponseData.success) { + [ADJUserDefaults setInstallTracked]; + } + // session success callback if (sessionResponseData.success && [selfI.adjustDelegate respondsToSelector:@selector(adjustSessionTrackingSucceeded:)]) @@ -977,16 +989,13 @@ - (BOOL)updateAttributionI:(ADJActivityHandler *)selfI return YES; } -- (void)setEnabledI:(ADJActivityHandler *)selfI - enabled:(BOOL)enabled -{ +- (void)setEnabledI:(ADJActivityHandler *)selfI enabled:(BOOL)enabled { // compare with the saved or internal state if (![selfI hasChangedStateI:selfI previousState:[selfI isEnabled] nextState:enabled trueMessage:@"Adjust already enabled" - falseMessage:@"Adjust already disabled"]) - { + falseMessage:@"Adjust already disabled"]) { return; } @@ -1002,6 +1011,14 @@ - (void)setEnabledI:(ADJActivityHandler *)selfI return; } + // Check if upon enabling install has been tracked. + if (enabled) { + if (![ADJUserDefaults getInstallTracked]) { + double now = [NSDate.date timeIntervalSince1970]; + [self trackNewSessionI:now withActivityHandler:selfI]; + } + } + // save new enabled state in activity state selfI.activityState.enabled = enabled; [selfI writeActivityStateI:selfI]; diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index d96ef5a88..2a2013032 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -193,7 +193,7 @@ extern NSString * __nonnull const ADJEnvironmentProduction; + (void)resetSessionPartnerParameters; /** - * Obtain singleton Adjust object + * Obtain singleton Adjust object. */ + (nullable id)getInstance; diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 02501220d..9a09c85c3 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -2,8 +2,8 @@ // Adjust.m // Adjust // -// Created by Christian Wellenbrock on 2012-07-23. -// Copyright (c) 2012-2014 adjust GmbH. All rights reserved. +// Created by Christian Wellenbrock (wellle) on 23rd July 2013. +// Copyright © 2012-2017 Adjust GmbH. All rights reserved. // #import "Adjust.h" @@ -14,7 +14,7 @@ #if !__has_feature(objc_arc) #error Adjust requires ARC -// see README for details +// See README for details: https://github.com/adjust/ios_sdk/blob/master/README.md #endif NSString * const ADJEnvironmentSandbox = @"sandbox"; @@ -23,14 +23,44 @@ @interface Adjust() @property (nonatomic, weak) id logger; + @property (nonatomic, strong) id activityHandler; + @property (nonatomic, strong) ADJSavedPreLaunch *savedPreLaunch; @end -#pragma mark - @implementation Adjust +#pragma mark - Object lifecycle methods + ++ (id)getInstance { + static Adjust *defaultInstance = nil; + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{ + defaultInstance = [[self alloc] init]; + }); + + return defaultInstance; +} + +- (id)init { + self = [super init]; + + if (self == nil) { + return nil; + } + + self.activityHandler = nil; + self.logger = [ADJAdjustFactory logger]; + self.savedPreLaunch = [[ADJSavedPreLaunch alloc] init]; + + return self; +} + +#pragma mark - Public static methods + + (void)appDidLaunch:(ADJConfig *)adjustConfig { [[Adjust getInstance] appDidLaunch:adjustConfig]; } @@ -48,7 +78,7 @@ + (void)trackSubsessionEnd { } + (void)setEnabled:(BOOL)enabled { - Adjust * instance = [Adjust getInstance]; + Adjust *instance = [Adjust getInstance]; [instance setEnabled:enabled]; } @@ -84,14 +114,12 @@ + (void)sendFirstPackages { [[Adjust getInstance] sendFirstPackages]; } -+ (void)addSessionCallbackParameter:(NSString *)key - value:(NSString *)value { ++ (void)addSessionCallbackParameter:(NSString *)key value:(NSString *)value { [[Adjust getInstance] addSessionCallbackParameter:key value:value]; } -+ (void)addSessionPartnerParameter:(NSString *)key - value:(NSString *)value { ++ (void)addSessionPartnerParameter:(NSString *)key value:(NSString *)value { [[Adjust getInstance] addSessionPartnerParameter:key value:value]; } @@ -120,26 +148,7 @@ + (NSString *)adid { return [[Adjust getInstance] adid]; } -+ (id)getInstance { - static Adjust *defaultInstance = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - defaultInstance = [[self alloc] init]; - }); - - return defaultInstance; -} - -- (id) init { - self = [super init]; - if (self == nil) return nil; - - self.activityHandler = nil; - self.logger = [ADJAdjustFactory logger]; - self.savedPreLaunch = [[ADJSavedPreLaunch alloc] init]; - - return self; -} +#pragma mark - Public instance methods - (void)appDidLaunch:(ADJConfig *)adjustConfig { if (self.activityHandler != nil) { @@ -148,42 +157,56 @@ - (void)appDidLaunch:(ADJConfig *)adjustConfig { } self.activityHandler = [ADJAdjustFactory activityHandlerWithConfig:adjustConfig - savedPreLaunch:self.savedPreLaunch]; + savedPreLaunch:self.savedPreLaunch]; } - (void)trackEvent:(ADJEvent *)event { - if (![self checkActivityHandler]) { return; } + if (![self checkActivityHandler]) { + return; + } + [self.activityHandler trackEvent:event]; } - (void)trackSubsessionStart { - if (![self checkActivityHandler]) { return; } + if (![self checkActivityHandler]) { + return; + } + [self.activityHandler applicationDidBecomeActive]; } - (void)trackSubsessionEnd { - if (![self checkActivityHandler]) { return; } + if (![self checkActivityHandler]) { + return; + } + [self.activityHandler applicationWillResignActive]; } - (void)setEnabled:(BOOL)enabled { - if (![self checkActivityHandler: enabled - trueMessage:@"enabled mode" - falseMessage:@"disabled mode"]) - { - self.savedPreLaunch.enabled = [NSNumber numberWithBool:enabled]; - } else { + self.savedPreLaunch.enabled = [NSNumber numberWithBool:enabled]; + + if ([self checkActivityHandler:enabled + trueMessage:@"enabled mode" + falseMessage:@"disabled mode"]) { [self.activityHandler setEnabled:enabled]; } } - (BOOL)isEnabled { - if (![self checkActivityHandler]) { return NO; } + if (![self checkActivityHandler]) { + return [self isInstanceEnabled]; + } + return [self.activityHandler isEnabled]; } - (void)appWillOpenUrl:(NSURL *)url { - if (![self checkActivityHandler]) { return; } + if (![self checkActivityHandler]) { + return; + } + [self.activityHandler appWillOpenUrl:url]; } @@ -198,8 +221,7 @@ - (void)setDeviceToken:(NSData *)deviceToken { - (void)setOfflineMode:(BOOL)enabled { if (![self checkActivityHandler:enabled trueMessage:@"offline mode" - falseMessage:@"online mode"]) - { + falseMessage:@"online mode"]) { self.savedPreLaunch.offline = enabled; } else { [self.activityHandler setOfflineMode:enabled]; @@ -215,13 +237,14 @@ - (NSURL *)convertUniversalLink:(NSURL *)url scheme:(NSString *)scheme { } - (void)sendFirstPackages { - if (![self checkActivityHandler]) { return; } + if (![self checkActivityHandler]) { + return; + } + [self.activityHandler sendFirstPackages]; } -- (void)addSessionCallbackParameter:(NSString *)key - value:(NSString *)value -{ +- (void)addSessionCallbackParameter:(NSString *)key value:(NSString *)value { if ([self checkActivityHandler:@"adding session callback parameter"]) { [self.activityHandler addSessionCallbackParameter:key value:value]; return; @@ -231,14 +254,12 @@ - (void)addSessionCallbackParameter:(NSString *)key self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler *activityHandler) { [activityHandler addSessionCallbackParameterI:activityHandler key:key value:value]; }]; } -- (void)addSessionPartnerParameter:(NSString *)key - value:(NSString *)value -{ +- (void)addSessionPartnerParameter:(NSString *)key value:(NSString *)value { if ([self checkActivityHandler:@"adding session partner parameter"]) { [self.activityHandler addSessionPartnerParameter:key value:value]; return; @@ -248,13 +269,12 @@ - (void)addSessionPartnerParameter:(NSString *)key self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler *activityHandler) { [activityHandler addSessionPartnerParameterI:activityHandler key:key value:value]; }]; } -- (void)removeSessionCallbackParameter:(NSString *)key -{ +- (void)removeSessionCallbackParameter:(NSString *)key { if ([self checkActivityHandler:@"removing session callback parameter"]) { [self.activityHandler removeSessionCallbackParameter:key]; return; @@ -264,7 +284,7 @@ - (void)removeSessionCallbackParameter:(NSString *)key self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler *activityHandler) { [activityHandler removeSessionCallbackParameterI:activityHandler key:key]; }]; } @@ -279,7 +299,7 @@ - (void)removeSessionPartnerParameter:(NSString *)key { self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler *activityHandler) { [activityHandler removeSessionPartnerParameterI:activityHandler key:key]; }]; } @@ -294,7 +314,7 @@ - (void)resetSessionCallbackParameters { self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler *activityHandler) { [activityHandler resetSessionCallbackParametersI:activityHandler]; }]; } @@ -309,18 +329,24 @@ - (void)resetSessionPartnerParameters { self.savedPreLaunch.preLaunchActionsArray = [[NSMutableArray alloc] init]; } - [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler * activityHandler){ + [self.savedPreLaunch.preLaunchActionsArray addObject:^(ADJActivityHandler *activityHandler) { [activityHandler resetSessionPartnerParametersI:activityHandler]; }]; } - (ADJAttribution *)attribution { - if (![self checkActivityHandler]) { return nil; } + if (![self checkActivityHandler]) { + return nil; + } + return [self.activityHandler attribution]; } - (NSString *)adid { - if (![self checkActivityHandler]) { return nil; } + if (![self checkActivityHandler]) { + return nil; + } + return [self.activityHandler adid]; } @@ -328,12 +354,13 @@ - (void)teardown:(BOOL)deleteState { if (self.activityHandler == nil) { [self.logger error:@"Adjust already down or not initialized"]; return; - } + } + [self.activityHandler teardown:deleteState]; self.activityHandler = nil; } -#pragma mark - private +#pragma mark - Private & helper methods - (BOOL)checkActivityHandler { return [self checkActivityHandler:nil]; @@ -341,8 +368,7 @@ - (BOOL)checkActivityHandler { - (BOOL)checkActivityHandler:(BOOL)status trueMessage:(NSString *)trueMessage - falseMessage:(NSString *)falseMessage -{ + falseMessage:(NSString *)falseMessage { if (status) { return [self checkActivityHandler:trueMessage]; } else { @@ -350,19 +376,22 @@ - (BOOL)checkActivityHandler:(BOOL)status } } -- (BOOL)checkActivityHandler:(NSString *)savedForLaunchWarningSuffixMessage -{ +- (BOOL)checkActivityHandler:(NSString *)savedForLaunchWarningSuffixMessage { if (self.activityHandler == nil) { if (savedForLaunchWarningSuffixMessage != nil) { [self.logger warn:@"Adjust not initialized, but %@ saved for launch", savedForLaunchWarningSuffixMessage]; } else { [self.logger error:@"Please initialize Adjust by calling 'appDidLaunch' before"]; } + return NO; } else { return YES; } +} +- (BOOL)isInstanceEnabled { + return self.savedPreLaunch.enabled == nil || self.savedPreLaunch.enabled; } @end From 0c17e2dc4bb2eb10c49a4a899fb09dfd2327bbef Mon Sep 17 00:00:00 2001 From: uerceg Date: Thu, 17 Aug 2017 11:23:37 +0200 Subject: [PATCH 34/74] AdjustBridge update and new version 4.9.1 --- AdjustBridge/AdjustBridge.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdjustBridge/AdjustBridge.m b/AdjustBridge/AdjustBridge.m index 21d7ef044..35d1fff0e 100644 --- a/AdjustBridge/AdjustBridge.m +++ b/AdjustBridge/AdjustBridge.m @@ -265,7 +265,7 @@ - (void)loadWebViewBridge { if ([adjustConfig isValid]) { // Log level if ([self isFieldValid:logLevel]) { - [adjustConfig setLogLevel:[ADJLogger LogLevelFromString:[logLevel lowercaseString]]]; + [adjustConfig setLogLevel:[ADJLogger logLevelFromString:[logLevel lowercaseString]]]; } // Sending in background From 05a43013b8d2a21569f7c716a820f135ebca1d97 Mon Sep 17 00:00:00 2001 From: uerceg Date: Thu, 17 Aug 2017 11:24:22 +0200 Subject: [PATCH 35/74] Example apps update but tvOS one --- .../AdjustExample-Swift.xcodeproj/project.pbxproj | 8 +++++++- .../project.pbxproj | 8 +++++++- .../AdjustExample-iOS.xcodeproj/project.pbxproj | 6 ++++++ .../AdjustExample-iWatch.xcodeproj/project.pbxproj | 14 +++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj b/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj index 1bbe3a7f9..53416dbd6 100644 --- a/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ 9D449E941E6EDC3D00E7E80B /* Adjust.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449E721E6EDC3D00E7E80B /* Adjust.m */; }; 9D449E951E6EDC3D00E7E80B /* ADJUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449E741E6EDC3D00E7E80B /* ADJUtil.m */; }; 9D449E961E6EDC3D00E7E80B /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9D449E751E6EDC3D00E7E80B /* Info.plist */; }; + 9DD0E9C11F45879A00B2A759 /* ADJUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD0E9C01F45879A00B2A759 /* ADJUserDefaults.m */; }; 9DF7A9C61CB4ECA600D3591F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DF7A9C51CB4ECA600D3591F /* AppDelegate.swift */; }; 9DF7A9C81CB4ECA600D3591F /* ViewControllerSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DF7A9C71CB4ECA600D3591F /* ViewControllerSwift.swift */; }; 9DF7A9CB1CB4ECA600D3591F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9DF7A9C91CB4ECA600D3591F /* Main.storyboard */; }; @@ -115,6 +116,8 @@ 9D449E731E6EDC3D00E7E80B /* ADJUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUtil.h; sourceTree = ""; }; 9D449E741E6EDC3D00E7E80B /* ADJUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUtil.m; sourceTree = ""; }; 9D449E751E6EDC3D00E7E80B /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 9DD0E9BF1F45879A00B2A759 /* ADJUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUserDefaults.h; sourceTree = ""; }; + 9DD0E9C01F45879A00B2A759 /* ADJUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserDefaults.m; sourceTree = ""; }; 9DF7A9C21CB4ECA600D3591F /* AdjustExample-Swift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "AdjustExample-Swift.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 9DF7A9C51CB4ECA600D3591F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 9DF7A9C71CB4ECA600D3591F /* ViewControllerSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewControllerSwift.swift; sourceTree = ""; }; @@ -143,6 +146,7 @@ 9D449E331E6EDC3D00E7E80B /* Adjust */ = { isa = PBXGroup; children = ( + 9D449E3C1E6EDC3D00E7E80B /* ADJAdditions */, 9D449E341E6EDC3D00E7E80B /* ADJActivityHandler.h */, 9D449E351E6EDC3D00E7E80B /* ADJActivityHandler.m */, 9D449E361E6EDC3D00E7E80B /* ADJActivityKind.h */, @@ -151,7 +155,6 @@ 9D449E391E6EDC3D00E7E80B /* ADJActivityPackage.m */, 9D449E3A1E6EDC3D00E7E80B /* ADJActivityState.h */, 9D449E3B1E6EDC3D00E7E80B /* ADJActivityState.m */, - 9D449E3C1E6EDC3D00E7E80B /* ADJAdditions */, 9D449E431E6EDC3D00E7E80B /* ADJAdjustFactory.h */, 9D449E441E6EDC3D00E7E80B /* ADJAdjustFactory.m */, 9D449E451E6EDC3D00E7E80B /* ADJAttribution.h */, @@ -202,6 +205,8 @@ 9D449E741E6EDC3D00E7E80B /* ADJUtil.m */, 6FCC850D1F2794BE00D6A0ED /* ADJReachability.h */, 6FCC850E1F2794BE00D6A0ED /* ADJReachability.m */, + 9DD0E9BF1F45879A00B2A759 /* ADJUserDefaults.h */, + 9DD0E9C01F45879A00B2A759 /* ADJUserDefaults.m */, 9D449E751E6EDC3D00E7E80B /* Info.plist */, ); name = Adjust; @@ -343,6 +348,7 @@ 9D449E8F1E6EDC3D00E7E80B /* ADJSessionParameters.m in Sources */, 9D449E901E6EDC3D00E7E80B /* ADJSessionSuccess.m in Sources */, 9D449E861E6EDC3D00E7E80B /* ADJEventSuccess.m in Sources */, + 9DD0E9C11F45879A00B2A759 /* ADJUserDefaults.m in Sources */, 9D449E761E6EDC3D00E7E80B /* ADJActivityHandler.m in Sources */, 9D449E8B1E6EDC3D00E7E80B /* ADJRequestHandler.m in Sources */, 9D449E8A1E6EDC3D00E7E80B /* ADJPackageHandler.m in Sources */, diff --git a/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj b/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj index a56618d8e..f579c0d1c 100644 --- a/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj @@ -62,6 +62,7 @@ 9D75F19C1D07463800E5D222 /* adjust_event.js in Resources */ = {isa = PBXBuildFile; fileRef = 9D75F1931D07463800E5D222 /* adjust_event.js */; }; 9D75F19D1D07463800E5D222 /* adjust_config.js in Resources */ = {isa = PBXBuildFile; fileRef = 9D75F1941D07463800E5D222 /* adjust_config.js */; }; 9D9A99DA1D0B699A0022FFCE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D9A99D91D0B699A0022FFCE /* AppDelegate.m */; }; + 9DD0E9C41F4587C600B2A759 /* ADJUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD0E9C31F4587C600B2A759 /* ADJUserDefaults.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -163,6 +164,8 @@ 9D75F1941D07463800E5D222 /* adjust_config.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = adjust_config.js; sourceTree = ""; }; 9D9A99D81D0B699A0022FFCE /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 9D9A99D91D0B699A0022FFCE /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 9DD0E9C21F4587C600B2A759 /* ADJUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUserDefaults.h; sourceTree = ""; }; + 9DD0E9C31F4587C600B2A759 /* ADJUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserDefaults.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -243,6 +246,7 @@ 9D449E971E6EDD4100E7E80B /* Adjust */ = { isa = PBXGroup; children = ( + 9D449EA01E6EDD4100E7E80B /* ADJAdditions */, 9D449E981E6EDD4100E7E80B /* ADJActivityHandler.h */, 9D449E991E6EDD4100E7E80B /* ADJActivityHandler.m */, 9D449E9A1E6EDD4100E7E80B /* ADJActivityKind.h */, @@ -251,7 +255,6 @@ 9D449E9D1E6EDD4100E7E80B /* ADJActivityPackage.m */, 9D449E9E1E6EDD4100E7E80B /* ADJActivityState.h */, 9D449E9F1E6EDD4100E7E80B /* ADJActivityState.m */, - 9D449EA01E6EDD4100E7E80B /* ADJAdditions */, 9D449EA71E6EDD4100E7E80B /* ADJAdjustFactory.h */, 9D449EA81E6EDD4100E7E80B /* ADJAdjustFactory.m */, 9D449EA91E6EDD4100E7E80B /* ADJAttribution.h */, @@ -302,6 +305,8 @@ 9D449ED81E6EDD4100E7E80B /* ADJUtil.m */, 6FCC85101F2794D600D6A0ED /* ADJReachability.h */, 6FCC85111F2794D600D6A0ED /* ADJReachability.m */, + 9DD0E9C21F4587C600B2A759 /* ADJUserDefaults.h */, + 9DD0E9C31F4587C600B2A759 /* ADJUserDefaults.m */, 9D449ED91E6EDD4100E7E80B /* Info.plist */, ); name = Adjust; @@ -443,6 +448,7 @@ 9D449EE01E6EDD4100E7E80B /* UIDevice+ADJAdditions.m in Sources */, 9D449EEA1E6EDD4100E7E80B /* ADJEventSuccess.m in Sources */, 9D75F1961D07463800E5D222 /* WebViewJavascriptBridge.m in Sources */, + 9DD0E9C41F4587C600B2A759 /* ADJUserDefaults.m in Sources */, 6FCC85121F2794D900D6A0ED /* ADJReachability.m in Sources */, 9D75F1991D07463800E5D222 /* WKWebViewJavascriptBridge.m in Sources */, 9D10833D1CFDD8F00050568B /* WKWebViewController.m in Sources */, diff --git a/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj b/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj index 912580a15..f4f23bd13 100644 --- a/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj @@ -48,6 +48,7 @@ 9D449E311E6ED88F00E7E80B /* ADJSessionParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449E0F1E6ED88F00E7E80B /* ADJSessionParameters.m */; }; 9DC95F261C104CEF00138E4B /* ViewControlleriOS.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DC95F251C104CEF00138E4B /* ViewControlleriOS.m */; }; 9DC95F2A1C10515300138E4B /* Constants.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DC95F291C10515300138E4B /* Constants.m */; }; + 9DD0E9BE1F457EF800B2A759 /* ADJUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD0E9BD1F457EF800B2A759 /* ADJUserDefaults.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -131,6 +132,8 @@ 9DC95F281C10515300138E4B /* Constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = ""; }; 9DC95F291C10515300138E4B /* Constants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Constants.m; sourceTree = ""; }; 9DCA5CF01DD5B6BE000296B2 /* AdjustExample-iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "AdjustExample-iOS.entitlements"; sourceTree = ""; }; + 9DD0E9BC1F457EF800B2A759 /* ADJUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUserDefaults.h; sourceTree = ""; }; + 9DD0E9BD1F457EF800B2A759 /* ADJUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserDefaults.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -266,6 +269,8 @@ 9D449E0F1E6ED88F00E7E80B /* ADJSessionParameters.m */, 6FCC850B1F2794A300D6A0ED /* ADJReachability.h */, 6FCC850A1F2794A300D6A0ED /* ADJReachability.m */, + 9DD0E9BC1F457EF800B2A759 /* ADJUserDefaults.h */, + 9DD0E9BD1F457EF800B2A759 /* ADJUserDefaults.m */, ); name = Adjust; path = ../../../Adjust; @@ -370,6 +375,7 @@ 9D449E141E6ED88F00E7E80B /* UIDevice+ADJAdditions.m in Sources */, 9D449E181E6ED88F00E7E80B /* ADJActivityKind.m in Sources */, 9D449E151E6ED88F00E7E80B /* NSData+ADJAdditions.m in Sources */, + 9DD0E9BE1F457EF800B2A759 /* ADJUserDefaults.m in Sources */, 9D449E191E6ED88F00E7E80B /* ADJActivityPackage.m in Sources */, 9D449E1E1E6ED88F00E7E80B /* ADJPackageHandler.m in Sources */, 9D449E281E6ED88F00E7E80B /* ADJResponseData.m in Sources */, diff --git a/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj b/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj index 9c072c7ac..46ab47b4e 100644 --- a/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ 9D449FC11E6EE72000E7E80B /* Adjust.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449F9F1E6EE72000E7E80B /* Adjust.m */; }; 9D449FC21E6EE72000E7E80B /* ADJUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449FA11E6EE72000E7E80B /* ADJUtil.m */; }; 9D449FC31E6EE72000E7E80B /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9D449FA21E6EE72000E7E80B /* Info.plist */; }; + 9DD0E9C71F45949600B2A759 /* ADJUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD0E9C61F45949600B2A759 /* ADJUserDefaults.m */; }; 9DF7AC191CB4FEDB00D3591F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF7AC181CB4FEDB00D3591F /* main.m */; }; 9DF7AC1C1CB4FEDB00D3591F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF7AC1B1CB4FEDB00D3591F /* AppDelegate.m */; }; 9DF7AC1F1CB4FEDB00D3591F /* ViewControllerWatch.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF7AC1E1CB4FEDB00D3591F /* ViewControllerWatch.m */; }; @@ -170,6 +171,8 @@ 9D449FA01E6EE72000E7E80B /* ADJUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUtil.h; sourceTree = ""; }; 9D449FA11E6EE72000E7E80B /* ADJUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUtil.m; sourceTree = ""; }; 9D449FA21E6EE72000E7E80B /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 9DD0E9C51F45949600B2A759 /* ADJUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUserDefaults.h; sourceTree = ""; }; + 9DD0E9C61F45949600B2A759 /* ADJUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserDefaults.m; sourceTree = ""; }; 9DF7AC141CB4FEDB00D3591F /* AdjustExample-iWatch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "AdjustExample-iWatch.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 9DF7AC181CB4FEDB00D3591F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 9DF7AC1A1CB4FEDB00D3591F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -228,6 +231,7 @@ 9D449F601E6EE72000E7E80B /* Adjust */ = { isa = PBXGroup; children = ( + 9D449F691E6EE72000E7E80B /* ADJAdditions */, 9D449F611E6EE72000E7E80B /* ADJActivityHandler.h */, 9D449F621E6EE72000E7E80B /* ADJActivityHandler.m */, 9D449F631E6EE72000E7E80B /* ADJActivityKind.h */, @@ -236,7 +240,6 @@ 9D449F661E6EE72000E7E80B /* ADJActivityPackage.m */, 9D449F671E6EE72000E7E80B /* ADJActivityState.h */, 9D449F681E6EE72000E7E80B /* ADJActivityState.m */, - 9D449F691E6EE72000E7E80B /* ADJAdditions */, 9D449F701E6EE72000E7E80B /* ADJAdjustFactory.h */, 9D449F711E6EE72000E7E80B /* ADJAdjustFactory.m */, 9D449F721E6EE72000E7E80B /* ADJAttribution.h */, @@ -287,6 +290,8 @@ 9D449FA11E6EE72000E7E80B /* ADJUtil.m */, 6FCC85161F2794F800D6A0ED /* ADJReachability.h */, 6FCC85171F2794F800D6A0ED /* ADJReachability.m */, + 9DD0E9C51F45949600B2A759 /* ADJUserDefaults.h */, + 9DD0E9C61F45949600B2A759 /* ADJUserDefaults.m */, 9D449FA21E6EE72000E7E80B /* Info.plist */, ); name = Adjust; @@ -464,9 +469,11 @@ }; 9DF7AC2A1CB4FEDB00D3591F = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = QGUGW9AUMK; }; 9DF7AC391CB4FEDB00D3591F = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = QGUGW9AUMK; }; }; }; @@ -560,6 +567,7 @@ 9D449FB51E6EE72000E7E80B /* ADJLogger.m in Sources */, 9D449FB91E6EE72000E7E80B /* ADJResponseData.m in Sources */, 9D449FB71E6EE72000E7E80B /* ADJPackageHandler.m in Sources */, + 9DD0E9C71F45949600B2A759 /* ADJUserDefaults.m in Sources */, 9D449FA71E6EE72000E7E80B /* NSData+ADJAdditions.m in Sources */, 9D449FC11E6EE72000E7E80B /* Adjust.m in Sources */, 9D449FA51E6EE72000E7E80B /* ADJActivityPackage.m in Sources */, @@ -711,6 +719,7 @@ 9DF7AC4B1CB4FEDB00D3591F /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + DEVELOPMENT_TEAM = QGUGW9AUMK; INFOPLIST_FILE = "AdjustExample-iWatch WatchKit Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; OTHER_LDFLAGS = "-ObjC"; @@ -726,6 +735,7 @@ 9DF7AC4C1CB4FEDB00D3591F /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + DEVELOPMENT_TEAM = QGUGW9AUMK; INFOPLIST_FILE = "AdjustExample-iWatch WatchKit Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; OTHER_LDFLAGS = "-ObjC"; @@ -742,6 +752,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = QGUGW9AUMK; IBSC_MODULE = AdjustExample_iWatch_WatchKit_Extension; INFOPLIST_FILE = "AdjustExample-iWatch WatchKit App/Info.plist"; OTHER_LDFLAGS = "-ObjC"; @@ -758,6 +769,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = QGUGW9AUMK; IBSC_MODULE = AdjustExample_iWatch_WatchKit_Extension; INFOPLIST_FILE = "AdjustExample-iWatch WatchKit App/Info.plist"; OTHER_LDFLAGS = "-ObjC"; From ede160e2efcc78fad9ca74533e9365dc0e45397e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uglje=C5=A1a=20Erceg?= Date: Thu, 17 Aug 2017 11:26:56 +0200 Subject: [PATCH 36/74] Adjust Web Bridge README link update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8955fe187..88b94a8bc 100644 --- a/README.md +++ b/README.md @@ -942,7 +942,7 @@ If you are seing any value in the dashboard other than what you expected to be t [attribution-data]: https://github.com/adjust/sdks/blob/master/doc/attribution-data.md [example-ios-objc]: http://github.com/adjust/ios_sdk/tree/master/examples/AdjustExample-iOS [example-ios-swift]: http://github.com/adjust/ios_sdk/tree/master/examples/AdjustExample-Swift -[ios-web-views-guide]: https://github.com/adjust/ios_sdk/tree/master/doc/web_views.md +[ios-web-views-guide]: doc/english/web_views.md [currency-conversion]: https://docs.adjust.com/en/event-tracking/#tracking-purchases-in-different-currencies [universal-links-guide]: https://docs.adjust.com/en/universal-links/ From 8d3edf8a1ebe709a7cd26ceb52736f952888c302 Mon Sep 17 00:00:00 2001 From: uerceg Date: Thu, 17 Aug 2017 12:07:17 +0200 Subject: [PATCH 37/74] Excluding CoreTelephony stuff from tvOS platform --- Adjust/ADJDeviceInfo.m | 7 +- Adjust/ADJPackageBuilder.m | 4 +- Adjust/ADJUtil.h | 15 +- Adjust/ADJUtil.m | 131 ++++++++++-------- .../project.pbxproj | 8 +- 5 files changed, 100 insertions(+), 65 deletions(-) diff --git a/Adjust/ADJDeviceInfo.m b/Adjust/ADJDeviceInfo.m index 8fee2388f..72253bac1 100644 --- a/Adjust/ADJDeviceInfo.m +++ b/Adjust/ADJDeviceInfo.m @@ -12,10 +12,13 @@ #import "ADJUtil.h" #import "ADJSystemProfile.h" #import "NSData+ADJAdditions.h" -#import -#import #import "ADJReachability.h" +#ifndef TARGET_OS_TV +#import +#import +#endif + @implementation ADJDeviceInfo + (ADJDeviceInfo *) deviceInfoWithSdkPrefix:(NSString *)sdkPrefix { diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 0235f843d..9c960f8d1 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -248,10 +248,12 @@ - (void)injectDeviceInfo:(ADJDeviceInfo *)deviceInfo intoParameters:(NSMutableDi [ADJPackageBuilder parameters:parameters setString:deviceInfo.cpuSubtype forKey:@"cpu_type"]; [ADJPackageBuilder parameters:parameters setString:deviceInfo.installReceiptBase64 forKey:@"install_receipt"]; [ADJPackageBuilder parameters:parameters setString:deviceInfo.osBuild forKey:@"os_build"]; + [ADJPackageBuilder parameters:parameters setNumberInt:[ADJUtil readReachabilityFlags] forKey:@"connectivity_type"]; +#ifndef TARGET_OS_TV [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMCC] forKey:@"mcc"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMNC] forKey:@"mnc"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readCurrentRadioAccessTechnology] forKey:@"network_type"]; - [ADJPackageBuilder parameters:parameters setNumberInt:[ADJUtil readReachabilityFlags] forKey:@"connectivity_type"]; +#endif } - (void)injectConfig:(ADJConfig *)adjustConfig intoParameters:(NSMutableDictionary *) parameters { diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index b9aaa37d2..c60324fa7 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -110,16 +110,19 @@ responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler + (NSTimeInterval)waitingTime:(NSInteger)retries backoffStrategy:(ADJBackoffStrategy *)backoffStrategy; -+ (NSString *)readMCC; - -+ (NSString *)readMNC; - + (NSNumber *)readReachabilityFlags; -+ (NSString *)readCurrentRadioAccessTechnology; - + (NSString *)extractAppSecret:(ADJActivityPackage *)activityPackage; + (NSString *)buildAuthorizationHeader:(NSString *)appSecret activityPackage:(ADJActivityPackage *)activityPackage; + +#ifndef TARGET_OS_TV ++ (NSString *)readMCC; + ++ (NSString *)readMNC; + ++ (NSString *)readCurrentRadioAccessTechnology; +#endif + @end diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index bbdc5757b..898b1d8f1 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -18,21 +18,27 @@ #import "ADJAdjustFactory.h" #import "UIDevice+ADJAdditions.h" #import "NSString+ADJAdditions.h" -#import -#import #import "ADJReachability.h" +#ifndef TARGET_OS_TV +#import +#import +#endif + static const double kRequestTimeout = 60; // 60 seconds static NSDateFormatter *dateFormat; static NSRegularExpression *universalLinkRegex = nil; static NSNumberFormatter *secondsNumberFormatter = nil; -static NSRegularExpression *optionalRedirectRegex = nil; +static NSRegularExpression *optionalRedirectRegex = nil; static NSRegularExpression *shortUniversalLinkRegex = nil; static NSURLSessionConfiguration *urlSessionConfiguration = nil; +static ADJReachability *reachability = nil; + +#ifndef TARGET_OS_TV static CTTelephonyNetworkInfo *networkInfo = nil; static CTCarrier *carrier = nil; -static ADJReachability *reachability = nil; +#endif static NSString *userAgent = nil; @@ -60,8 +66,10 @@ + (void)initialize { [self initializeShortUniversalLinkRegex]; [self initializeOptionalRedirectRegex]; [self initializeUrlSessionConfiguration]; - [self initializeNetworkInfoAndCarrier]; [self initializeReachability]; +#ifndef TARGET_OS_TV + [self initializeNetworkInfoAndCarrier]; +#endif } + (void)teardown { @@ -71,9 +79,12 @@ + (void)teardown { optionalRedirectRegex = nil; shortUniversalLinkRegex = nil; urlSessionConfiguration = nil; + reachability = nil; +#ifndef TARGET_OS_TV networkInfo = nil; carrier = nil; - reachability = nil; +#endif + } + (void)initializeDateFormat { @@ -166,10 +177,12 @@ + (void)initializeUrlSessionConfiguration { urlSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; } +#ifndef TARGET_OS_TV + (void)initializeNetworkInfoAndCarrier { networkInfo = [[CTTelephonyNetworkInfo alloc] init]; carrier = [networkInfo subscriberCellularProvider]; } +#endif + (void)initializeReachability { reachability = [ADJReachability reachabilityForInternetConnection]; @@ -504,13 +517,11 @@ + (void)sendPostRequest:(NSURL *)baseUrl prefixErrorMessage:(NSString *)prefixErrorMessage suffixErrorMessage:(NSString *)suffixErrorMessage activityPackage:(ADJActivityPackage *)activityPackage - responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler -{ - NSString * appSecret = [ADJUtil extractAppSecret:activityPackage]; - + responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { + NSString *appSecret = [ADJUtil extractAppSecret:activityPackage]; NSMutableURLRequest *request = [ADJUtil requestForPackage:activityPackage baseUrl:baseUrl queueSize:queueSize]; + NSString *authHeader = [ADJUtil buildAuthorizationHeader:appSecret activityPackage:activityPackage]; - NSString * authHeader = [ADJUtil buildAuthorizationHeader:appSecret activityPackage:activityPackage]; if (authHeader != nil) { [request setValue:authHeader forHTTPHeaderField:@"authHeader"]; } @@ -523,7 +534,8 @@ + (void)sendPostRequest:(NSURL *)baseUrl } + (NSString *)extractAppSecret:(ADJActivityPackage *)activityPackage { - NSString * appSecret = [activityPackage.parameters objectForKey:@"app_secret"]; + NSString *appSecret = [activityPackage.parameters objectForKey:@"app_secret"]; + if (appSecret == nil) { return nil; } @@ -552,46 +564,48 @@ + (NSMutableURLRequest *)requestForPackage:(ADJActivityPackage *)activityPackage } + (NSString *)buildAuthorizationHeader:(NSString *)appSecret - activityPackage:(ADJActivityPackage *)activityPackage { + activityPackage:(ADJActivityPackage *)activityPackage { if (appSecret == nil) { return nil; } - NSMutableDictionary * parameters = activityPackage.parameters; - NSString * clientSdk = activityPackage.clientSdk; - NSString * activityKindS = [ADJActivityKindUtil activityKindToString:activityPackage.activityKind]; + NSMutableDictionary *parameters = activityPackage.parameters; + NSString *clientSdk = activityPackage.clientSdk; + NSString *activityKindS = [ADJActivityKindUtil activityKindToString:activityPackage.activityKind]; - NSDictionary * signatureParameters = [ADJUtil buildSignatureParameters:parameters - appSecret:appSecret - clientSdk:clientSdk - activityKindS:activityKindS]; - NSMutableString * fields = [[NSMutableString alloc] initWithCapacity:5]; - NSMutableString * clearSignature = [[NSMutableString alloc] initWithCapacity:5]; + NSDictionary *signatureParameters = [ADJUtil buildSignatureParameters:parameters + appSecret:appSecret + clientSdk:clientSdk + activityKindS:activityKindS]; + + NSMutableString *fields = [[NSMutableString alloc] initWithCapacity:5]; + NSMutableString *clearSignature = [[NSMutableString alloc] initWithCapacity:5]; // signature part of header - for (NSDictionary * key in signatureParameters) { + for (NSDictionary *key in signatureParameters) { [fields appendFormat:@"%@ ", key]; - NSString * value = [signatureParameters objectForKey:key]; + NSString *value = [signatureParameters objectForKey:key]; [clearSignature appendString:value]; } // algorithm part of header - NSString * algorithmHeader = @"sha256"; + NSString *algorithmHeader = @"sha256"; - NSString * signature = [clearSignature adjSha256]; - NSString * signatureHeader = [NSString stringWithFormat:@"signature=\"%@\"", signature]; + NSString *signature = [clearSignature adjSha256]; + NSString *signatureHeader = [NSString stringWithFormat:@"signature=\"%@\"", signature]; // fields part of header // Remove last empty space. if (fields.length > 0) { [fields deleteCharactersInRange:NSMakeRange(fields.length - 1, 1)]; } - NSString * fieldsHeader = [NSString stringWithFormat:@"headers=\"%@\"", fields]; + + NSString *fieldsHeader = [NSString stringWithFormat:@"headers=\"%@\"", fields]; // putting it all together - NSString * authorizationHeader = [NSString stringWithFormat:@"Signature %@,%@,%@", signatureHeader, algorithmHeader, fieldsHeader]; + NSString *authorizationHeader = [NSString stringWithFormat:@"Signature %@,%@,%@", signatureHeader, algorithmHeader, fieldsHeader]; return authorizationHeader; } @@ -599,24 +613,23 @@ + (NSString *)buildAuthorizationHeader:(NSString *)appSecret + (NSDictionary *)buildSignatureParameters:(NSMutableDictionary *)parameters appSecret:(NSString *)appSecret clientSdk:(NSString *)clientSdk - activityKindS:(NSString *)activityKindS -{ - NSString * sdkVersionName = @"sdk_version"; - NSString * sdkVersionValue = clientSdk; + activityKindS:(NSString *)activityKindS { + NSString *sdkVersionName = @"sdk_version"; + NSString *sdkVersionValue = clientSdk; - NSString * appVersionName = @"app_version"; - NSString * appVersionValue = [parameters objectForKey:appVersionName]; + NSString *appVersionName = @"app_version"; + NSString *appVersionValue = [parameters objectForKey:appVersionName]; - NSString * activityKindName = @"activity_kind"; - NSString * activityKindValue = activityKindS; + NSString *activityKindName = @"activity_kind"; + NSString *activityKindValue = activityKindS; - NSString * createdAtName = @"created_at"; - NSString * createdAtValue = [parameters objectForKey:createdAtName]; + NSString *createdAtName = @"created_at"; + NSString *createdAtValue = [parameters objectForKey:createdAtName]; - NSString * deviceIdentifierName = [ADJUtil getValidIdentifier:parameters]; - NSString * deviceIdentifierValue = [parameters objectForKey:deviceIdentifierName]; + NSString *deviceIdentifierName = [ADJUtil getValidIdentifier:parameters]; + NSString *deviceIdentifierValue = [parameters objectForKey:deviceIdentifierName]; - NSMutableDictionary * signatureParameters = [[NSMutableDictionary alloc] initWithCapacity:6]; + NSMutableDictionary *signatureParameters = [[NSMutableDictionary alloc] initWithCapacity:6]; [ADJUtil checkAndAddEntry:signatureParameters key:@"app_secret" value:appSecret]; [ADJUtil checkAndAddEntry:signatureParameters key:sdkVersionName value:sdkVersionValue]; @@ -634,26 +647,31 @@ + (void)checkAndAddEntry:(NSMutableDictionary *)parameters if (key == nil) { return; } + if (value == nil) { return; } + [parameters setObject:value forKey:key]; } + (NSString *)getValidIdentifier:(NSMutableDictionary *)parameters { - NSString * idfaName = @"idfa"; - NSString * persistentUUIDName = @"persistent_ios_uuid"; - NSString * uUIDName = @"ios_uuid"; + NSString *idfaName = @"idfa"; + NSString *persistentUUIDName = @"persistent_ios_uuid"; + NSString *uuidName = @"ios_uuid"; if ([parameters objectForKey:idfaName] != nil) { return idfaName; } + if ([parameters objectForKey:persistentUUIDName] != nil) { return persistentUUIDName; } - if ([parameters objectForKey:uUIDName] != nil) { - return uUIDName; + + if ([parameters objectForKey:uuidName] != nil) { + return uuidName; } + return nil; } @@ -1273,35 +1291,38 @@ + (BOOL)contains:(NSDictionary *)dictionary return [value isEqualToString:[readValue description]]; } -+ (NSString *)readMCC { - if (carrier == nil) { ++ (NSNumber *)readReachabilityFlags { + if (reachability == nil) { return nil; } - return [carrier mobileCountryCode]; + return [reachability currentReachabilityFlags]; } -+ (NSString *)readMNC { +#ifndef TARGET_OS_TV ++ (NSString *)readMCC { if (carrier == nil) { return nil; } - return [carrier mobileNetworkCode]; + return [carrier mobileCountryCode]; } -+ (NSNumber *)readReachabilityFlags { - if (reachability == nil) { ++ (NSString *)readMNC { + if (carrier == nil) { return nil; } - return [reachability currentReachabilityFlags]; + return [carrier mobileNetworkCode]; } + (NSString *)readCurrentRadioAccessTechnology { if (networkInfo == nil) { return nil; } + return [networkInfo currentRadioAccessTechnology]; } +#endif @end diff --git a/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj b/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj index ded3b065e..d03649c4d 100644 --- a/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj @@ -47,6 +47,7 @@ 9D449F5E1E6EE6C500E7E80B /* ADJUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D449F3D1E6EE6C500E7E80B /* ADJUtil.m */; }; 9D449F5F1E6EE6C500E7E80B /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9D449F3E1E6EE6C500E7E80B /* Info.plist */; }; 9DC95F2F1C10596500138E4B /* Constants.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DC95F2E1C10596500138E4B /* Constants.m */; }; + 9DD0E9CF1F459ECE00B2A759 /* ADJUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD0E9CE1F459ECE00B2A759 /* ADJUserDefaults.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -140,6 +141,8 @@ 9D449F3E1E6EE6C500E7E80B /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 9DC95F2D1C10596500138E4B /* Constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = ""; }; 9DC95F2E1C10596500138E4B /* Constants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Constants.m; sourceTree = ""; }; + 9DD0E9CD1F459ECE00B2A759 /* ADJUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUserDefaults.h; sourceTree = ""; }; + 9DD0E9CE1F459ECE00B2A759 /* ADJUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserDefaults.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -200,6 +203,7 @@ 9D449EFC1E6EE6C400E7E80B /* Adjust */ = { isa = PBXGroup; children = ( + 9D449F051E6EE6C500E7E80B /* ADJAdditions */, 9D449EFD1E6EE6C400E7E80B /* ADJActivityHandler.h */, 9D449EFE1E6EE6C500E7E80B /* ADJActivityHandler.m */, 9D449EFF1E6EE6C500E7E80B /* ADJActivityKind.h */, @@ -208,7 +212,6 @@ 9D449F021E6EE6C500E7E80B /* ADJActivityPackage.m */, 9D449F031E6EE6C500E7E80B /* ADJActivityState.h */, 9D449F041E6EE6C500E7E80B /* ADJActivityState.m */, - 9D449F051E6EE6C500E7E80B /* ADJAdditions */, 9D449F0C1E6EE6C500E7E80B /* ADJAdjustFactory.h */, 9D449F0D1E6EE6C500E7E80B /* ADJAdjustFactory.m */, 9D449F0E1E6EE6C500E7E80B /* ADJAttribution.h */, @@ -259,6 +262,8 @@ 9D449F3D1E6EE6C500E7E80B /* ADJUtil.m */, 6FCC85141F2794E800D6A0ED /* ADJReachability.h */, 6FCC85131F2794E800D6A0ED /* ADJReachability.m */, + 9DD0E9CD1F459ECE00B2A759 /* ADJUserDefaults.h */, + 9DD0E9CE1F459ECE00B2A759 /* ADJUserDefaults.m */, 9D449F3E1E6EE6C500E7E80B /* Info.plist */, ); name = Adjust; @@ -376,6 +381,7 @@ 963909BA1BCC0D8300A2E8A4 /* AppDelegate.m in Sources */, 9D449F4A1E6EE6C500E7E80B /* ADJConfig.m in Sources */, 9D449F571E6EE6C500E7E80B /* ADJSessionFailure.m in Sources */, + 9DD0E9CF1F459ECE00B2A759 /* ADJUserDefaults.m in Sources */, 9D449F5E1E6EE6C500E7E80B /* ADJUtil.m in Sources */, 9D449F4E1E6EE6C500E7E80B /* ADJEventFailure.m in Sources */, 9D449F461E6EE6C500E7E80B /* ADJAdjustFactory.m in Sources */, From f0610100095f197ec82571e2f4141b6121cd3b13 Mon Sep 17 00:00:00 2001 From: uerceg Date: Thu, 17 Aug 2017 12:12:52 +0200 Subject: [PATCH 38/74] Macro check change --- Adjust/ADJDeviceInfo.m | 2 +- Adjust/ADJPackageBuilder.m | 2 +- Adjust/ADJUtil.h | 2 +- Adjust/ADJUtil.m | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Adjust/ADJDeviceInfo.m b/Adjust/ADJDeviceInfo.m index 72253bac1..3284eadac 100644 --- a/Adjust/ADJDeviceInfo.m +++ b/Adjust/ADJDeviceInfo.m @@ -14,7 +14,7 @@ #import "NSData+ADJAdditions.h" #import "ADJReachability.h" -#ifndef TARGET_OS_TV +#if !TARGET_OS_TV #import #import #endif diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 9c960f8d1..4a49694a9 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -249,7 +249,7 @@ - (void)injectDeviceInfo:(ADJDeviceInfo *)deviceInfo intoParameters:(NSMutableDi [ADJPackageBuilder parameters:parameters setString:deviceInfo.installReceiptBase64 forKey:@"install_receipt"]; [ADJPackageBuilder parameters:parameters setString:deviceInfo.osBuild forKey:@"os_build"]; [ADJPackageBuilder parameters:parameters setNumberInt:[ADJUtil readReachabilityFlags] forKey:@"connectivity_type"]; -#ifndef TARGET_OS_TV +#if !TARGET_OS_TV [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMCC] forKey:@"mcc"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readMNC] forKey:@"mnc"]; [ADJPackageBuilder parameters:parameters setString:[ADJUtil readCurrentRadioAccessTechnology] forKey:@"network_type"]; diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index c60324fa7..b19101a9e 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -117,7 +117,7 @@ responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler + (NSString *)buildAuthorizationHeader:(NSString *)appSecret activityPackage:(ADJActivityPackage *)activityPackage; -#ifndef TARGET_OS_TV +#if !TARGET_OS_TV + (NSString *)readMCC; + (NSString *)readMNC; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 898b1d8f1..57c38552f 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -20,7 +20,7 @@ #import "NSString+ADJAdditions.h" #import "ADJReachability.h" -#ifndef TARGET_OS_TV +#if !TARGET_OS_TV #import #import #endif @@ -35,7 +35,7 @@ static NSURLSessionConfiguration *urlSessionConfiguration = nil; static ADJReachability *reachability = nil; -#ifndef TARGET_OS_TV +#if !TARGET_OS_TV static CTTelephonyNetworkInfo *networkInfo = nil; static CTCarrier *carrier = nil; #endif @@ -67,7 +67,7 @@ + (void)initialize { [self initializeOptionalRedirectRegex]; [self initializeUrlSessionConfiguration]; [self initializeReachability]; -#ifndef TARGET_OS_TV +#if !TARGET_OS_TV [self initializeNetworkInfoAndCarrier]; #endif } @@ -80,7 +80,7 @@ + (void)teardown { shortUniversalLinkRegex = nil; urlSessionConfiguration = nil; reachability = nil; -#ifndef TARGET_OS_TV +#if !TARGET_OS_TV networkInfo = nil; carrier = nil; #endif @@ -177,7 +177,7 @@ + (void)initializeUrlSessionConfiguration { urlSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; } -#ifndef TARGET_OS_TV +#if !TARGET_OS_TV + (void)initializeNetworkInfoAndCarrier { networkInfo = [[CTTelephonyNetworkInfo alloc] init]; carrier = [networkInfo subscriberCellularProvider]; @@ -1299,7 +1299,7 @@ + (NSNumber *)readReachabilityFlags { return [reachability currentReachabilityFlags]; } -#ifndef TARGET_OS_TV +#if !TARGET_OS_TV + (NSString *)readMCC { if (carrier == nil) { return nil; From 499c521164022704faf4d3f8655cb151b9077982 Mon Sep 17 00:00:00 2001 From: uerceg Date: Mon, 21 Aug 2017 23:20:39 +0200 Subject: [PATCH 39/74] Improved push token handling --- Adjust/ADJActivityHandler.m | 61 ++++++++++++++++++++++++++----------- Adjust/ADJUserDefaults.h | 6 ++-- Adjust/ADJUserDefaults.m | 10 ++++-- Adjust/Adjust.m | 13 +++++--- 4 files changed, 64 insertions(+), 26 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 6431e8e87..b625fd8df 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -167,13 +167,8 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig }]; } - // enabled by default - if (self.activityState == nil) { - self.internalState.enabled = YES; - } else { - self.internalState.enabled = self.activityState.enabled; - } - + // check if SDK is enabled/disabled + self.internalState.enabled = savedPreLaunch.enabled != nil ? [savedPreLaunch.enabled boolValue] : YES; // reads offline mode from pre launch self.internalState.offline = savedPreLaunch.offline; // in the background by default @@ -193,7 +188,11 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig } // does not have the session response by default self.internalState.sessionResponseProcessed = NO; - self.deviceTokenData = savedPreLaunch.deviceTokenData; + + // self.deviceTokenData = savedPreLaunch.deviceTokenData; + if (self.activityState != nil) { + [self setDeviceToken:[ADJUserDefaults getPushToken]]; + } self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); [ADJUtil launchInQueue:self.internalQueue @@ -560,6 +559,10 @@ - (void)teardown:(BOOL)deleteState [self teardownAttributionS:deleteState]; [self teardownAllSessionParametersS:deleteState]; + if (deleteState) { + [ADJUserDefaults clearAdjustStuff]; + } + [ADJUtil teardown]; self.internalQueue = nil; @@ -608,6 +611,12 @@ - (void)initI:(ADJActivityHandler *)selfI if (selfI.activityState != nil) { [selfI setDeviceToken:selfI.deviceTokenData]; } + } else { + if (selfI.activityState != nil) { + NSData *deviceToken = [ADJUserDefaults getPushToken]; + + [selfI setDeviceToken:deviceToken]; + } } selfI.foregroundTimer = [ADJTimerCycle timerWithBlock:^{ @@ -691,7 +700,9 @@ - (void)processSessionI:(ADJActivityHandler *)selfI { // very first session if (selfI.activityState == nil) { selfI.activityState = [[ADJActivityState alloc] init]; - selfI.activityState.deviceToken = [ADJUtil convertDeviceToken:selfI.deviceTokenData]; + + // selfI.activityState.deviceToken = [ADJUtil convertDeviceToken:selfI.deviceTokenData]; + selfI.activityState.deviceToken = [ADJUtil convertDeviceToken:[ADJUserDefaults getPushToken]]; // track the first session package only if it's enabled if ([selfI.internalState isEnabled]) { @@ -702,7 +713,10 @@ - (void)processSessionI:(ADJActivityHandler *)selfI { [selfI.activityState resetSessionAttributes:now]; selfI.activityState.enabled = [selfI.internalState isEnabled]; selfI.activityState.updatePackages = [selfI.internalState itHasToUpdatePackages]; + [selfI writeActivityStateI:selfI]; + [ADJUserDefaults removePushToken]; + return; } @@ -1017,6 +1031,12 @@ - (void)setEnabledI:(ADJActivityHandler *)selfI enabled:(BOOL)enabled { double now = [NSDate.date timeIntervalSince1970]; [self trackNewSessionI:now withActivityHandler:selfI]; } + + NSData *deviceToken = [ADJUserDefaults getPushToken]; + + if (deviceToken != nil && ![selfI.activityState.deviceToken isEqualToString:[ADJUtil convertDeviceToken:deviceToken]]) { + [self setDeviceToken:deviceToken]; + } } // save new enabled state in activity state @@ -1225,17 +1245,24 @@ - (void)setDeviceTokenI:(ADJActivityHandler *)selfI // send info package double now = [NSDate.date timeIntervalSince1970]; - ADJPackageBuilder * infoBuilder = [[ADJPackageBuilder alloc] - initWithDeviceInfo:selfI.deviceInfo - activityState:selfI.activityState - config:selfI.adjustConfig - sessionParameters:selfI.sessionParameters - createdAt:now]; + ADJPackageBuilder *infoBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:selfI.deviceInfo + activityState:selfI.activityState + config:selfI.adjustConfig + sessionParameters:selfI.sessionParameters + createdAt:now]; - ADJActivityPackage * infoPackage = [infoBuilder buildInfoPackage:@"push"]; + ADJActivityPackage *infoPackage = [infoBuilder buildInfoPackage:@"push"]; [selfI.packageHandler addPackage:infoPackage]; - [selfI.packageHandler sendFirstPackage]; + + // if push token was cached, remove it + [ADJUserDefaults removePushToken]; + + if (selfI.adjustConfig.eventBufferingEnabled) { + [selfI.logger info:@"Buffered info %@", infoPackage.suffix]; + } else { + [selfI.packageHandler sendFirstPackage]; + } } - (void)setIadDateI:(ADJActivityHandler *)selfI diff --git a/Adjust/ADJUserDefaults.h b/Adjust/ADJUserDefaults.h index 147822592..0c66531e5 100644 --- a/Adjust/ADJUserDefaults.h +++ b/Adjust/ADJUserDefaults.h @@ -10,9 +10,11 @@ @interface ADJUserDefaults : NSObject -+ (void)savePushToken:(NSString *)pushToken; ++ (void)savePushToken:(NSData *)pushToken; -+ (NSString *)getPushToken; ++ (NSData *)getPushToken; + ++ (void)clearAdjustStuff; + (void)removePushToken; diff --git a/Adjust/ADJUserDefaults.m b/Adjust/ADJUserDefaults.m index 01dd28545..fb0cb4425 100644 --- a/Adjust/ADJUserDefaults.m +++ b/Adjust/ADJUserDefaults.m @@ -38,12 +38,12 @@ - (id)init { #pragma mark - Public methods -+ (void)savePushToken:(NSString *)pushToken { ++ (void)savePushToken:(NSData *)pushToken { [[NSUserDefaults standardUserDefaults] setObject:pushToken forKey:PREFS_KEY_PUSH_TOKEN]; [[NSUserDefaults standardUserDefaults] synchronize]; } -+ (NSString *)getPushToken { ++ (NSData *)getPushToken { return [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_KEY_PUSH_TOKEN]; } @@ -61,4 +61,10 @@ + (BOOL)getInstallTracked { return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_KEY_INSTALL_TRACKED]; } ++ (void)clearAdjustStuff { + [[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_PUSH_TOKEN]; + [[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_INSTALL_TRACKED]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + @end diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 9a09c85c3..750b937df 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -9,6 +9,7 @@ #import "Adjust.h" #import "ADJUtil.h" #import "ADJLogger.h" +#import "ADJUserDefaults.h" #import "ADJAdjustFactory.h" #import "ADJActivityHandler.h" @@ -207,14 +208,16 @@ - (void)appWillOpenUrl:(NSURL *)url { return; } - [self.activityHandler appWillOpenUrl:url]; + [self.activityHandler appWillOpenUrl:url]; } - (void)setDeviceToken:(NSData *)deviceToken { - if (![self checkActivityHandler:@"device token"]) { - self.savedPreLaunch.deviceTokenData = deviceToken; - } else { - [self.activityHandler setDeviceToken:deviceToken]; + [ADJUserDefaults savePushToken:deviceToken]; + + if ([self checkActivityHandler:@"device token"]) { + if (self.activityHandler.isEnabled) { + [self.activityHandler setDeviceToken:deviceToken]; + } } } From 4d9015399723449f23e6a19aded181aa3bf536a8 Mon Sep 17 00:00:00 2001 From: uerceg Date: Mon, 21 Aug 2017 23:43:46 +0200 Subject: [PATCH 40/74] ADJUserDefaults cleanup --- Adjust/ADJUserDefaults.m | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/Adjust/ADJUserDefaults.m b/Adjust/ADJUserDefaults.m index fb0cb4425..103f159d4 100644 --- a/Adjust/ADJUserDefaults.m +++ b/Adjust/ADJUserDefaults.m @@ -13,29 +13,6 @@ @implementation ADJUserDefaults -#pragma mark - Object lifecycle methods - -+ (id)getInstance { - static ADJUserDefaults *defaultInstance = nil; - static dispatch_once_t onceToken; - - dispatch_once(&onceToken, ^{ - defaultInstance = [[self alloc] init]; - }); - - return defaultInstance; -} - -- (id)init { - self = [super init]; - - if (self == nil) { - return nil; - } - - return self; -} - #pragma mark - Public methods + (void)savePushToken:(NSData *)pushToken { From 44c2587d6b43d3d121fdbac1950adb0d1e5f8eae Mon Sep 17 00:00:00 2001 From: uerceg Date: Mon, 21 Aug 2017 23:45:07 +0200 Subject: [PATCH 41/74] Queue initialisation first and check enabled when trying to send sdk_info --- Adjust/ADJActivityHandler.m | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index b625fd8df..245490efb 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -189,11 +189,6 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig // does not have the session response by default self.internalState.sessionResponseProcessed = NO; - // self.deviceTokenData = savedPreLaunch.deviceTokenData; - if (self.activityState != nil) { - [self setDeviceToken:[ADJUserDefaults getPushToken]]; - } - self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); [ADJUtil launchInQueue:self.internalQueue selfInject:self @@ -202,6 +197,11 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig preLaunchActionsArray:savedPreLaunch.preLaunchActionsArray]; }]; + // self.deviceTokenData = savedPreLaunch.deviceTokenData; + if (self.activityState != nil) { + [self setDeviceToken:[ADJUserDefaults getPushToken]]; + } + [self addNotificationObserver]; return self; @@ -1229,6 +1229,10 @@ - (BOOL)trySetAttributionDeeplink:(ADJAttribution *)deeplinkAttribution - (void)setDeviceTokenI:(ADJActivityHandler *)selfI deviceToken:(NSData *)deviceToken { + if (![selfI isEnabledI:selfI]) { + return; + } + NSString *deviceTokenString = [ADJUtil convertDeviceToken:deviceToken]; if (deviceTokenString == nil) { From dcf3ef0f577871e4000fba597b0f27035ca50e5b Mon Sep 17 00:00:00 2001 From: nonelse Date: Tue, 22 Aug 2017 12:03:39 +0200 Subject: [PATCH 42/74] Fix auth header --- Adjust/ADJUtil.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 57c38552f..253ea6540 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -523,7 +523,7 @@ + (void)sendPostRequest:(NSURL *)baseUrl NSString *authHeader = [ADJUtil buildAuthorizationHeader:appSecret activityPackage:activityPackage]; if (authHeader != nil) { - [request setValue:authHeader forHTTPHeaderField:@"authHeader"]; + [request setValue:authHeader forHTTPHeaderField:@"Authorization"]; } [ADJUtil sendRequest:request @@ -591,11 +591,11 @@ + (NSString *)buildAuthorizationHeader:(NSString *)appSecret } // algorithm part of header - NSString *algorithmHeader = @"sha256"; - - NSString *signature = [clearSignature adjSha256]; - NSString *signatureHeader = [NSString stringWithFormat:@"signature=\"%@\"", signature]; + NSString * algorithm = @"sha256"; + NSString * signature = [clearSignature adjSha256]; + NSString * signatureHeader = [NSString stringWithFormat:@"signature=\"%@\"", signature]; + NSString * algorithmHeader = [NSString stringWithFormat:@"algorithm=\"%@\"", algorithm]; // fields part of header // Remove last empty space. if (fields.length > 0) { From 6b3f0e47351cb32bf9c8735d39f59cc1b7affe65 Mon Sep 17 00:00:00 2001 From: nonelse Date: Tue, 22 Aug 2017 14:11:37 +0200 Subject: [PATCH 43/74] Save and send external device id --- Adjust/ADJActivityHandler.m | 24 ++++++++++++++++++++++++ Adjust/ADJSessionParameters.m | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 245490efb..943329abe 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -675,6 +675,9 @@ - (void)initI:(ADJActivityHandler *)selfI [[UIDevice currentDevice] adjSetIad:selfI triesV3Left:kTryIadV3]; + [selfI setExternalDeviceIdI:selfI + externalDeviceId:selfI.adjustConfig.externalDeviceId]; + [selfI preLaunchActionsI:selfI preLaunchActionsArray:preLaunchActionsArray]; [selfI startI:selfI]; @@ -1426,6 +1429,17 @@ - (void)writeSessionPartnerParametersI:(ADJActivityHandler *)selfI { } } +- (void)writeSessionParametersI:(ADJActivityHandler *)selfI { + @synchronized ([ADJSessionParameters class]) { + if (selfI.sessionParameters == nil) { + return; + } + [ADJUtil writeObject:selfI.sessionParameters + fileName:kSessionParametersFilename + objectName:@"Session parameters"]; + } +} + - (void)teardownAllSessionParametersS:(BOOL)deleteState { @synchronized ([ADJSessionParameters class]) { if (self.sessionParameters == nil) { @@ -1805,6 +1819,16 @@ - (void)resetSessionPartnerParametersI:(ADJActivityHandler *)selfI { [selfI writeSessionPartnerParametersI:selfI]; } +- (void)setExternalDeviceIdI:(ADJActivityHandler *)selfI + externalDeviceId:(NSString *)externalDeviceId { + if (externalDeviceId == nil) { + return; + } + + selfI.sessionParameters.externalDeviceId = externalDeviceId; + [selfI writeSessionParametersI:selfI]; +} + - (void)preLaunchActionsI:(ADJActivityHandler *)selfI preLaunchActionsArray:(NSArray*)preLaunchActionsArray { diff --git a/Adjust/ADJSessionParameters.m b/Adjust/ADJSessionParameters.m index c3fed658d..70b093773 100644 --- a/Adjust/ADJSessionParameters.m +++ b/Adjust/ADJSessionParameters.m @@ -24,7 +24,6 @@ - (id)initWithCoder:(NSCoder *)decoder { } - (void)encodeWithCoder:(NSCoder *)encoder { - [encoder encodeObject:self.externalDeviceId forKey:@"externalDeviceId"]; } @@ -35,6 +34,7 @@ -(id)copyWithZone:(NSZone *)zone if (copy) { copy.callbackParameters = [self.callbackParameters copyWithZone:zone]; copy.partnerParameters = [self.partnerParameters copyWithZone:zone]; + copy.externalDeviceId = [self.externalDeviceId copyWithZone:zone]; } return copy; From 4b3c30aae126d58b0e029aaddd126d1e364fbb1f Mon Sep 17 00:00:00 2001 From: nonelse Date: Tue, 22 Aug 2017 16:49:48 +0200 Subject: [PATCH 44/74] Access radio tech with reflection --- Adjust/ADJUtil.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 253ea6540..9b7f081d4 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -1321,7 +1321,18 @@ + (NSString *)readCurrentRadioAccessTechnology { return nil; } - return [networkInfo currentRadioAccessTechnology]; + SEL radioTechSelector = NSSelectorFromString(@"currentRadioAccessTechnology"); + + if (![networkInfo respondsToSelector:radioTechSelector]) { + return nil; + } + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + id radioTech = [networkInfo performSelector:radioTechSelector]; +#pragma clang diagnostic pop + + return radioTech; } #endif From 634c78acda9f3c99afbdf880472b1d0829156deb Mon Sep 17 00:00:00 2001 From: uerceg Date: Wed, 23 Aug 2017 11:15:48 +0200 Subject: [PATCH 45/74] Don't use static NSDateFormatter instance --- Adjust/ADJUtil.m | 67 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 9b7f081d4..c761cca8a 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -27,7 +27,6 @@ static const double kRequestTimeout = 60; // 60 seconds -static NSDateFormatter *dateFormat; static NSRegularExpression *universalLinkRegex = nil; static NSNumberFormatter *secondsNumberFormatter = nil; static NSRegularExpression *optionalRedirectRegex = nil; @@ -60,7 +59,6 @@ + (void)initialize { return; } - [self initializeDateFormat]; [self initializeUniversalLinkRegex]; [self initializeSecondsNumberFormatter]; [self initializeShortUniversalLinkRegex]; @@ -73,7 +71,6 @@ + (void)initialize { } + (void)teardown { - dateFormat = nil; universalLinkRegex = nil; secondsNumberFormatter = nil; optionalRedirectRegex = nil; @@ -87,34 +84,6 @@ + (void)teardown { } -+ (void)initializeDateFormat { - dateFormat = [[NSDateFormatter alloc] init]; - - if ([NSCalendar instancesRespondToSelector:@selector(calendarWithIdentifier:)]) { - // http://stackoverflow.com/a/3339787 - NSString *calendarIdentifier; - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wtautological-pointer-compare" - if (&NSCalendarIdentifierGregorian != NULL) { -#pragma clang diagnostic pop - calendarIdentifier = NSCalendarIdentifierGregorian; - } else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - calendarIdentifier = NSGregorianCalendar; -#pragma clang diagnostic pop - } - - dateFormat.calendar = [NSCalendar calendarWithIdentifier:calendarIdentifier]; - } - - dateFormat.locale = [NSLocale systemLocale]; - [dateFormat setDateFormat:kDateFormat]; - -} - + (void)initializeUniversalLinkRegex { NSError *error = NULL; @@ -201,6 +170,35 @@ + (NSString *)clientSdk { return kClientSdk; } ++ (NSDateFormatter *)getDateFormatter { + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; + + if ([NSCalendar instancesRespondToSelector:@selector(calendarWithIdentifier:)]) { + // http://stackoverflow.com/a/3339787 + NSString *calendarIdentifier; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wtautological-pointer-compare" + if (&NSCalendarIdentifierGregorian != NULL) { +#pragma clang diagnostic pop + calendarIdentifier = NSCalendarIdentifierGregorian; + } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + calendarIdentifier = NSGregorianCalendar; +#pragma clang diagnostic pop + } + + dateFormatter.calendar = [NSCalendar calendarWithIdentifier:calendarIdentifier]; + } + + dateFormatter.locale = [NSLocale systemLocale]; + [dateFormatter setDateFormat:kDateFormat]; + + return dateFormatter; +} + // Inspired by https://gist.github.com/kevinbarrett/2002382 + (void)excludeFromBackup:(NSString *)path { NSURL *url = [NSURL fileURLWithPath:path]; @@ -250,10 +248,13 @@ + (NSString *)formatSeconds1970:(double)value { } + (NSString *)formatDate:(NSDate *)value { - if (dateFormat == nil) { + NSDateFormatter *dateFormatter = [ADJUtil getDateFormatter]; + + if (dateFormatter == nil) { return nil; } - return [dateFormat stringFromDate:value]; + + return [dateFormatter stringFromDate:value]; } + (void)saveJsonResponse:(NSData *)jsonData responseData:(ADJResponseData *)responseData { From 1f70f75ce94cc82d03b9a8bfbf43ada41aa291a4 Mon Sep 17 00:00:00 2001 From: uerceg Date: Wed, 23 Aug 2017 12:36:18 +0200 Subject: [PATCH 46/74] Atomic access to paused field --- Adjust/ADJAttributionHandler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 388929b65..d8bcb75af 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -23,7 +23,7 @@ @interface ADJAttributionHandler() @property (nonatomic, weak) id logger; @property (nonatomic, strong) ADJTimerOnce *attributionTimer; @property (nonatomic, strong) ADJActivityPackage * attributionPackage; -@property (nonatomic, assign) BOOL paused; +@property (atomic, assign) BOOL paused; @end From 61165318db25251ec96bcd3f1f90aedc12ef817c Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 24 Aug 2017 12:43:18 +0200 Subject: [PATCH 47/74] Remove iad v2 --- Adjust/ADJActivityHandler.h | 1 - Adjust/ADJActivityHandler.m | 46 --------------------- Adjust/ADJAdditions/UIDevice+ADJAdditions.m | 29 +++---------- 3 files changed, 5 insertions(+), 71 deletions(-) diff --git a/Adjust/ADJActivityHandler.h b/Adjust/ADJActivityHandler.h index e67eb388d..2d75ea28f 100644 --- a/Adjust/ADJActivityHandler.h +++ b/Adjust/ADJActivityHandler.h @@ -73,7 +73,6 @@ - (void)setAskingAttribution:(BOOL)askingAttribution; - (BOOL)updateAttributionI:(id)selfI attribution:(ADJAttribution *)attribution; -- (void)setIadDate:(NSDate*)iAdImpressionDate withPurchaseDate:(NSDate*)appPurchaseDate; - (void)setAttributionDetails:(NSDictionary *)attributionDetails error:(NSError *)error retriesLeft:(int)retriesLeft; diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 943329abe..9a47b583a 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -348,16 +348,6 @@ - (void)setDeviceToken:(NSData *)deviceToken { }]; } -- (void)setIadDate:(NSDate *)iAdImpressionDate - withPurchaseDate:(NSDate *)appPurchaseDate -{ - [ADJUtil launchInQueue:self.internalQueue - selfInject:self - block:^(ADJActivityHandler * selfI) { - [selfI setIadDateI:selfI iAdImpressionDate:iAdImpressionDate withPurchaseDate:appPurchaseDate]; - }]; -} - - (void)setAttributionDetails:(NSDictionary *)attributionDetails error:(NSError *)error retriesLeft:(int)retriesLeft @@ -1272,42 +1262,6 @@ - (void)setDeviceTokenI:(ADJActivityHandler *)selfI } } -- (void)setIadDateI:(ADJActivityHandler *)selfI - iAdImpressionDate:(NSDate *)iAdImpressionDate - withPurchaseDate:(NSDate *)appPurchaseDate -{ - if (iAdImpressionDate == nil) { - [selfI.logger debug:@"iAdImpressionDate not received"]; - return; - } - - if (![selfI isEnabledI:selfI]) { - return; - } - - [selfI.logger debug:@"iAdImpressionDate received: %@", iAdImpressionDate]; - - double now = [NSDate.date timeIntervalSince1970]; - if (selfI.activityState != nil) { - double lastInterval = now - selfI.activityState.lastActivity; - selfI.activityState.lastInterval = lastInterval; - } - - ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc] - initWithDeviceInfo:selfI.deviceInfo - activityState:selfI.activityState - config:selfI.adjustConfig - sessionParameters:selfI.sessionParameters - createdAt:now]; - - clickBuilder.purchaseTime = appPurchaseDate; - clickBuilder.clickTime = iAdImpressionDate; - - ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad"]; - [selfI.sdkClickHandler sendSdkClick:clickPackage]; -} - - #pragma mark - private - (BOOL)isEnabledI:(ADJActivityHandler *)selfI { diff --git a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m index 2a566a242..40a6f5e9e 100644 --- a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m +++ b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m @@ -168,10 +168,9 @@ - (void)adjSetIad:(ADJActivityHandler *)activityHandler return; } - // if no tries for iad v3 left -> iad v2 + // if no tries for iad v3 left, stop trying if (triesV3Left == 0) { - [logger warn:@"Reached limit number of retry for iAd v3. Trying iAd v2"]; - [self adjSetIadWithDates:activityHandler ADClientSharedClientInstance:ADClientSharedClientInstance]; + [logger warn:@"Reached limit number of retry for iAd v3"]; return; } @@ -179,10 +178,10 @@ - (void)adjSetIad:(ADJActivityHandler *)activityHandler ADClientSharedClientInstance:ADClientSharedClientInstance retriesLeft:(triesV3Left - 1)]; - // if iad v3 not available -> iad v2 + // if iad v3 not available if (!isIadV3Avaliable) { - [logger warn:@"iAd v3 not available. Trying iAd v2"]; - [self adjSetIadWithDates:activityHandler ADClientSharedClientInstance:ADClientSharedClientInstance]; + [logger warn:@"iAd v3 not available"]; + return; } #pragma clang diagnostic pop #endif @@ -209,22 +208,4 @@ - (BOOL)adjSetIadWithDetails:(ADJActivityHandler *)activityHandler return YES; } -- (BOOL)adjSetIadWithDates:(ADJActivityHandler *)activityHandler -ADClientSharedClientInstance:(id)ADClientSharedClientInstance -{ - SEL iadDateSelector = NSSelectorFromString(@"lookupAdConversionDetails:"); - - if (![ADClientSharedClientInstance respondsToSelector:iadDateSelector]) { - return NO; - } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Warc-performSelector-leaks" - [ADClientSharedClientInstance performSelector:iadDateSelector - withObject:^(NSDate *appPurchaseDate, NSDate *iAdImpressionDate) { - [activityHandler setIadDate:iAdImpressionDate withPurchaseDate:appPurchaseDate]; - }]; - -#pragma clang diagnostic pop - return YES; -} @end From 48ee8a4e56a7a73f6596b01d90e32615e2230b58 Mon Sep 17 00:00:00 2001 From: uerceg Date: Fri, 25 Aug 2017 11:33:19 +0200 Subject: [PATCH 48/74] File reading/migrating logs formatting --- Adjust/ADJUtil.m | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index c761cca8a..6edaa17b4 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -326,12 +326,15 @@ + (id)readObject:(NSString *)fileName return appSupportObject; } else if (appSupportObject == nil) { - [[ADJAdjustFactory logger] verbose:@"%@ file not found", appSupportFilePath]; + // [[ADJAdjustFactory logger] verbose:@"%@ file not found", appSupportFilePath]; + [[ADJAdjustFactory logger] verbose:@"%@ file not found in \"Application Support/Adjust\" folder", fileName]; } else { - [[ADJAdjustFactory logger] error:@"Failed to read %@ file", appSupportFilePath]; + // [[ADJAdjustFactory logger] error:@"Failed to read %@ file", appSupportFilePath]; + [[ADJAdjustFactory logger] error:@"Failed to read %@ file from \"Application Support/Adjust\" folder", fileName]; } } @catch (NSException *ex) { - [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", appSupportFilePath, ex]; + // [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", appSupportFilePath, ex]; + [[ADJAdjustFactory logger] error:@"Failed to read %@ file from \"Application Support/Adjust\" folder (%@)", fileName, ex]; } // If in here, for some reason, reading of file from Application Support folder failed. @@ -354,12 +357,15 @@ + (id)readObject:(NSString *)fileName return documentsObject; } else if (documentsObject == nil) { - [[ADJAdjustFactory logger] verbose:@"%@ file not found", documentsFilePath]; + // [[ADJAdjustFactory logger] verbose:@"%@ file not found", documentsFilePath]; + [[ADJAdjustFactory logger] verbose:@"%@ file not found in Documents folder", fileName]; } else { - [[ADJAdjustFactory logger] error:@"Failed to read %@ file", documentsFilePath]; + // [[ADJAdjustFactory logger] error:@"Failed to read %@ file", documentsFilePath]; + [[ADJAdjustFactory logger] error:@"Failed to read %@ file from Documents folder", fileName]; } } @catch (NSException *ex) { - [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", documentsFilePath, ex]; + // [[ADJAdjustFactory logger] error:@"Failed to read %@ file (%@)", documentsFilePath, ex]; + [[ADJAdjustFactory logger] error:@"Failed to read %@ file from Documents folder (%@)", fileName, ex]; } return nil; @@ -417,14 +423,15 @@ + (NSString *)getFilePathInAppSupportDir:(NSString *)fileName { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); NSString *appSupportDir = [paths firstObject]; + NSString *adjustDirName = @"Adjust"; - if (![ADJUtil checkForDirectoryPresence:appSupportDir]) { + if (![ADJUtil checkForDirectoryPresenceInPath:appSupportDir forFolder:[appSupportDir lastPathComponent]]) { return nil; } - NSString *adjustDir = [appSupportDir stringByAppendingPathComponent:@"/Adjust"]; + NSString *adjustDir = [appSupportDir stringByAppendingPathComponent:adjustDirName]; - if (![ADJUtil checkForDirectoryPresence:adjustDir]) { + if (![ADJUtil checkForDirectoryPresenceInPath:adjustDir forFolder:adjustDirName]) { return nil; } @@ -433,12 +440,12 @@ + (NSString *)getFilePathInAppSupportDir:(NSString *)fileName { return filePath; } -+ (BOOL)checkForDirectoryPresence:(NSString *)path { ++ (BOOL)checkForDirectoryPresenceInPath:(NSString *)path forFolder:(NSString *)folderName { // Check for presence of directory first. // If it doesn't exist, make one. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { - [[ADJAdjustFactory logger] debug:@"%@ directory not present and will be created", path]; + [[ADJAdjustFactory logger] debug:@"%@ directory not present and will be created", folderName]; NSError *error; From 4810de963494b73c453b5d388a78c6c2507a3566 Mon Sep 17 00:00:00 2001 From: uerceg Date: Fri, 25 Aug 2017 11:41:39 +0200 Subject: [PATCH 49/74] A bit more logging --- Adjust/ADJUtil.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 6edaa17b4..c91154774 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -353,6 +353,7 @@ + (id)readObject:(NSString *)fileName } // Do the file migration. + [[ADJAdjustFactory logger] verbose:@"Migrating %@ file from Documents to \"Application Support/Adjust\" folder", fileName]; [ADJUtil migrateFileFromPath:documentsFilePath toPath:appSupportFilePath]; return documentsObject; @@ -429,7 +430,7 @@ + (NSString *)getFilePathInAppSupportDir:(NSString *)fileName { return nil; } - NSString *adjustDir = [appSupportDir stringByAppendingPathComponent:adjustDirName]; + NSString *adjustDir = [appSupportDir stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@", adjustDirName]]; if (![ADJUtil checkForDirectoryPresenceInPath:adjustDir forFolder:adjustDirName]) { return nil; From 86806da5460b637cf81985a893c0f4afc4149ad2 Mon Sep 17 00:00:00 2001 From: uerceg Date: Mon, 28 Aug 2017 14:54:37 +0200 Subject: [PATCH 50/74] New version 4.12.0 --- Adjust.podspec | 4 ++-- Adjust/ADJUtil.m | 2 +- Adjust/Adjust.h | 6 +++--- AdjustTests/ADJPackageFields.m | 2 +- README.md | 4 ++-- VERSION | 2 +- doc/english/migrate.md | 2 +- doc/japanese/migrate_ja.md | 2 +- doc/migrate.md | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Adjust.podspec b/Adjust.podspec index 9cc7f9255..8707587d0 100644 --- a/Adjust.podspec +++ b/Adjust.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "Adjust" - s.version = "4.11.5" + s.version = "4.12.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.11.5" } + s.source = { :git => "https://github.com/adjust/ios_sdk.git", :tag => "v4.12.0" } s.ios.deployment_target = '6.0' s.tvos.deployment_target = '9.0' s.framework = 'SystemConfiguration' diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index c91154774..d38b185f8 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -41,7 +41,7 @@ static NSString *userAgent = nil; -static NSString * const kClientSdk = @"ios4.11.5"; +static NSString * const kClientSdk = @"ios4.12.0"; static NSString * const kDeeplinkParam = @"deep_link="; static NSString * const kSchemeDelimiter = @"://"; static NSString * const kDefaultScheme = @"AdjustUniversalScheme"; diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index 2a2013032..26d8bfd45 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -2,9 +2,9 @@ // Adjust.h // Adjust // -// V4.11.5 -// Created by Christian Wellenbrock on 2012-07-23. -// Copyright (c) 2012-2014 adjust GmbH. All rights reserved. +// V4.12.0 +// Created by Christian Wellenbrock (wellle) on 23rd July 2013. +// Copyright © 2012-2017 Adjust GmbH. All rights reserved. // #import "ADJEvent.h" diff --git a/AdjustTests/ADJPackageFields.m b/AdjustTests/ADJPackageFields.m index 848a93b7e..3e6fd6cd7 100644 --- a/AdjustTests/ADJPackageFields.m +++ b/AdjustTests/ADJPackageFields.m @@ -16,7 +16,7 @@ - (id) init { // default values self.appToken = @"qwerty123456"; - self.clientSdk = @"ios4.11.5"; + self.clientSdk = @"ios4.12.0"; self.suffix = @""; self.environment = @"sandbox"; diff --git a/README.md b/README.md index 88b94a8bc..4d1afbd1d 100644 --- a/README.md +++ b/README.md @@ -81,13 +81,13 @@ In the dialog `Choose options for adding these files` make sure to check the che If you're using [CocoaPods][cocoapods], you can add the following line to your `Podfile` and continue from [this step](#sdk-integrate): ```ruby -pod 'Adjust', '~> 4.11.5' +pod 'Adjust', '~> 4.12.0' ``` or: ```ruby -pod 'Adjust', :git => 'https://github.com/adjust/ios_sdk.git', :tag => 'v4.11.5' +pod 'Adjust', :git => 'https://github.com/adjust/ios_sdk.git', :tag => 'v4.12.0' ``` -- diff --git a/VERSION b/VERSION index ad2c17edd..815588ef1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.11.5 +4.12.0 diff --git a/doc/english/migrate.md b/doc/english/migrate.md index 69fe15654..589a8b7c4 100644 --- a/doc/english/migrate.md +++ b/doc/english/migrate.md @@ -1,4 +1,4 @@ -## Migrate your adjust SDK for iOS to v4.11.5 from v3.4.0 +## Migrate your adjust SDK for iOS to v4.12.0 from v3.4.0 ### Initial setup diff --git a/doc/japanese/migrate_ja.md b/doc/japanese/migrate_ja.md index e6e020a8a..d54dfa8eb 100644 --- a/doc/japanese/migrate_ja.md +++ b/doc/japanese/migrate_ja.md @@ -1,4 +1,4 @@ -## iOS用adjust SDKのv3.4.0からv.4.11.5への移行 +## iOS用adjust SDKのv3.4.0からv.4.12.0への移行 ### 初期設定 diff --git a/doc/migrate.md b/doc/migrate.md index 69fe15654..589a8b7c4 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -1,4 +1,4 @@ -## Migrate your adjust SDK for iOS to v4.11.5 from v3.4.0 +## Migrate your adjust SDK for iOS to v4.12.0 from v3.4.0 ### Initial setup From 11abb100c6b6142de63d48d75b88f9b139b43911 Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 7 Sep 2017 14:51:08 +0200 Subject: [PATCH 51/74] Change signature parameters --- Adjust/ADJUtil.m | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index d38b185f8..4243d882a 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -579,13 +579,11 @@ + (NSString *)buildAuthorizationHeader:(NSString *)appSecret } NSMutableDictionary *parameters = activityPackage.parameters; - NSString *clientSdk = activityPackage.clientSdk; NSString *activityKindS = [ADJActivityKindUtil activityKindToString:activityPackage.activityKind]; NSDictionary *signatureParameters = [ADJUtil buildSignatureParameters:parameters appSecret:appSecret - clientSdk:clientSdk activityKindS:activityKindS]; NSMutableString *fields = [[NSMutableString alloc] initWithCapacity:5]; @@ -616,19 +614,15 @@ + (NSString *)buildAuthorizationHeader:(NSString *)appSecret // putting it all together NSString *authorizationHeader = [NSString stringWithFormat:@"Signature %@,%@,%@", signatureHeader, algorithmHeader, fieldsHeader]; + [ADJAdjustFactory.logger debug:@"authorizationHeader %@", authorizationHeader]; + + return authorizationHeader; } + (NSDictionary *)buildSignatureParameters:(NSMutableDictionary *)parameters appSecret:(NSString *)appSecret - clientSdk:(NSString *)clientSdk activityKindS:(NSString *)activityKindS { - NSString *sdkVersionName = @"sdk_version"; - NSString *sdkVersionValue = clientSdk; - - NSString *appVersionName = @"app_version"; - NSString *appVersionValue = [parameters objectForKey:appVersionName]; - NSString *activityKindName = @"activity_kind"; NSString *activityKindValue = activityKindS; @@ -638,11 +632,9 @@ + (NSDictionary *)buildSignatureParameters:(NSMutableDictionary *)parameters NSString *deviceIdentifierName = [ADJUtil getValidIdentifier:parameters]; NSString *deviceIdentifierValue = [parameters objectForKey:deviceIdentifierName]; - NSMutableDictionary *signatureParameters = [[NSMutableDictionary alloc] initWithCapacity:6]; + NSMutableDictionary *signatureParameters = [[NSMutableDictionary alloc] initWithCapacity:4]; [ADJUtil checkAndAddEntry:signatureParameters key:@"app_secret" value:appSecret]; - [ADJUtil checkAndAddEntry:signatureParameters key:sdkVersionName value:sdkVersionValue]; - [ADJUtil checkAndAddEntry:signatureParameters key:appVersionName value:appVersionValue]; [ADJUtil checkAndAddEntry:signatureParameters key:createdAtName value:createdAtValue]; [ADJUtil checkAndAddEntry:signatureParameters key:activityKindName value:activityKindValue]; [ADJUtil checkAndAddEntry:signatureParameters key:deviceIdentifierName value:deviceIdentifierValue]; From 184d2d67e2d031c64e83b959ced3b3c4bfeed331 Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 7 Sep 2017 15:21:43 +0200 Subject: [PATCH 52/74] Refac file deletion --- Adjust/ADJActivityHandler.m | 8 ++++---- Adjust/ADJPackageHandler.m | 2 +- Adjust/ADJUtil.h | 2 +- Adjust/ADJUtil.m | 14 ++++++++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 9a47b583a..322e20609 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -1320,7 +1320,7 @@ - (void)teardownActivityStateS:(BOOL)deleteState return; } if (deleteState) { - [ADJUtil deleteFile:kActivityStateFilename]; + [ADJUtil deleteFileWithName:kActivityStateFilename]; } self.activityState = nil; } @@ -1342,7 +1342,7 @@ - (void)teardownAttributionS:(BOOL)deleteState return; } if (deleteState) { - [ADJUtil deleteFile:kAttributionFilename]; + [ADJUtil deleteFileWithName:kAttributionFilename]; } self.attribution = nil; } @@ -1400,8 +1400,8 @@ - (void)teardownAllSessionParametersS:(BOOL)deleteState { return; } if (deleteState) { - [ADJUtil deleteFile:kSessionCallbackParametersFilename]; - [ADJUtil deleteFile:kSessionPartnerParametersFilename]; + [ADJUtil deleteFileWithName:kSessionCallbackParametersFilename]; + [ADJUtil deleteFileWithName:kSessionPartnerParametersFilename]; } [self.sessionParameters.callbackParameters removeAllObjects]; [self.sessionParameters.partnerParameters removeAllObjects]; diff --git a/Adjust/ADJPackageHandler.m b/Adjust/ADJPackageHandler.m index e844f6a88..47f21ee9c 100644 --- a/Adjust/ADJPackageHandler.m +++ b/Adjust/ADJPackageHandler.m @@ -264,7 +264,7 @@ - (void)teardownPackageQueueS:(BOOL)deleteState { } if (deleteState) { - [ADJUtil deleteFile:kPackageQueueFilename]; + [ADJUtil deleteFileWithName:kPackageQueueFilename]; } [self.packageQueue removeAllObjects]; diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index b19101a9e..ba767b17d 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -87,7 +87,7 @@ responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler + (BOOL)isNotNull:(id)value; -+ (BOOL)deleteFile:(NSString *)filename; ++ (BOOL)deleteFileWithName:(NSString *)filename; + (BOOL)checkAttributionDetails:(NSDictionary *)attributionDetails; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 4243d882a..8c4899dbf 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -322,7 +322,7 @@ + (id)readObject:(NSString *)fileName } // Just in case check if old file exists in Documents folder and if yes, remove it. - [ADJUtil deleteFile:documentsFilePath]; + [ADJUtil deleteFileInPath:documentsFilePath]; return appSupportObject; } else if (appSupportObject == nil) { @@ -1159,7 +1159,17 @@ + (void)launchInQueue:(dispatch_queue_t)queue }); } -+ (BOOL)deleteFile:(NSString *)filePath { ++ (BOOL)deleteFileWithName:(NSString *)fileName { + NSString *documentsFilePath = [ADJUtil getFilePathInDocumentsDir:fileName]; + NSString *appSupportFilePath = [ADJUtil getFilePathInAppSupportDir:fileName]; + + BOOL deletedDocumentsFilePath = [ADJUtil deleteFileInPath:documentsFilePath]; + BOOL deletedAppSupportFilePath = [ADJUtil deleteFileInPath:appSupportFilePath]; + + return deletedDocumentsFilePath || deletedAppSupportFilePath; +} + ++ (BOOL)deleteFileInPath:(NSString *)filePath { NSError *error; if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { From 50ee6186b028f34467b04063cb9e5dfa576ed057 Mon Sep 17 00:00:00 2001 From: nonelse Date: Wed, 13 Sep 2017 13:31:38 +0200 Subject: [PATCH 53/74] Remove external device id --- Adjust/ADJActivityHandler.m | 24 ------------------------ Adjust/ADJConfig.h | 6 ------ Adjust/ADJConfig.m | 1 - Adjust/ADJPackageBuilder.m | 10 ---------- Adjust/ADJSessionParameters.h | 3 +-- Adjust/ADJSessionParameters.m | 8 -------- 6 files changed, 1 insertion(+), 51 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 322e20609..7bbe1c4fb 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -665,9 +665,6 @@ - (void)initI:(ADJActivityHandler *)selfI [[UIDevice currentDevice] adjSetIad:selfI triesV3Left:kTryIadV3]; - [selfI setExternalDeviceIdI:selfI - externalDeviceId:selfI.adjustConfig.externalDeviceId]; - [selfI preLaunchActionsI:selfI preLaunchActionsArray:preLaunchActionsArray]; [selfI startI:selfI]; @@ -1383,17 +1380,6 @@ - (void)writeSessionPartnerParametersI:(ADJActivityHandler *)selfI { } } -- (void)writeSessionParametersI:(ADJActivityHandler *)selfI { - @synchronized ([ADJSessionParameters class]) { - if (selfI.sessionParameters == nil) { - return; - } - [ADJUtil writeObject:selfI.sessionParameters - fileName:kSessionParametersFilename - objectName:@"Session parameters"]; - } -} - - (void)teardownAllSessionParametersS:(BOOL)deleteState { @synchronized ([ADJSessionParameters class]) { if (self.sessionParameters == nil) { @@ -1773,16 +1759,6 @@ - (void)resetSessionPartnerParametersI:(ADJActivityHandler *)selfI { [selfI writeSessionPartnerParametersI:selfI]; } -- (void)setExternalDeviceIdI:(ADJActivityHandler *)selfI - externalDeviceId:(NSString *)externalDeviceId { - if (externalDeviceId == nil) { - return; - } - - selfI.sessionParameters.externalDeviceId = externalDeviceId; - [selfI writeSessionParametersI:selfI]; -} - - (void)preLaunchActionsI:(ADJActivityHandler *)selfI preLaunchActionsArray:(NSArray*)preLaunchActionsArray { diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index 342f95ac0..7500981e2 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -155,12 +155,6 @@ */ @property (nonatomic, assign) BOOL isDeviceKnown; -/** - * @brief Set the external device id. - */ - -@property (nonatomic, copy, nullable) NSString *externalDeviceId; - /** * @brief Adjust app secret. */ diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index 2ef575df6..7e6cad87c 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -191,7 +191,6 @@ -(id)copyWithZone:(NSZone *)zone copy.delayStart = self.delayStart; copy.userAgent = [self.userAgent copyWithZone:zone]; copy.isDeviceKnown = self.isDeviceKnown; - copy.externalDeviceId = [self.externalDeviceId copyWithZone:zone]; copy->_appSecretS = [self.appSecretS copyWithZone:zone]; // adjust delegate not copied } diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 4a49694a9..6f8f246a5 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -213,7 +213,6 @@ - (NSMutableDictionary *)defaultParameters { [self injectDeviceInfo:self.deviceInfo intoParameters:parameters]; [self injectConfig:self.adjustConfig intoParameters:parameters]; [self injectActivityState:self.activityState intoParamters:parameters]; - [self injectSessionParameters:self.sessionParameters intoParamters:parameters]; [self injectCommonParameters:parameters]; return parameters; @@ -303,15 +302,6 @@ - (void)injectPushToken:(ADJActivityState *)activityState intoParamters:(NSMutab [ADJPackageBuilder parameters:parameters setString:activityState.deviceToken forKey:@"push_token"]; } -- (void)injectSessionParameters:(ADJSessionParameters *)sessionParameters - intoParamters:(NSMutableDictionary *)parameters { - if (sessionParameters == nil) { - return; - } - - [ADJPackageBuilder parameters:parameters setString:sessionParameters.externalDeviceId forKey:@"external_device_id"]; -} - - (NSString *)eventSuffix:(ADJEvent *)event { if (event.revenue == nil) { return [NSString stringWithFormat:@"'%@'", event.eventToken]; diff --git a/Adjust/ADJSessionParameters.h b/Adjust/ADJSessionParameters.h index 554d8f15a..603a89d0d 100644 --- a/Adjust/ADJSessionParameters.h +++ b/Adjust/ADJSessionParameters.h @@ -8,10 +8,9 @@ #import -@interface ADJSessionParameters : NSObject +@interface ADJSessionParameters : NSObject @property (nonatomic, strong) NSMutableDictionary* callbackParameters; @property (nonatomic, strong) NSMutableDictionary* partnerParameters; -@property (nonatomic, copy) NSString *externalDeviceId; @end diff --git a/Adjust/ADJSessionParameters.m b/Adjust/ADJSessionParameters.m index 70b093773..1c9622ae8 100644 --- a/Adjust/ADJSessionParameters.m +++ b/Adjust/ADJSessionParameters.m @@ -10,7 +10,6 @@ @implementation ADJSessionParameters -#pragma mark - NSCoding protocol methods - (id)initWithCoder:(NSCoder *)decoder { self = [super init]; @@ -18,15 +17,9 @@ - (id)initWithCoder:(NSCoder *)decoder { return nil; } - self.externalDeviceId = [decoder decodeObjectForKey:@"externalDeviceId"]; - return self; } -- (void)encodeWithCoder:(NSCoder *)encoder { - [encoder encodeObject:self.externalDeviceId forKey:@"externalDeviceId"]; -} - #pragma mark - NSCopying -(id)copyWithZone:(NSZone *)zone { @@ -34,7 +27,6 @@ -(id)copyWithZone:(NSZone *)zone if (copy) { copy.callbackParameters = [self.callbackParameters copyWithZone:zone]; copy.partnerParameters = [self.partnerParameters copyWithZone:zone]; - copy.externalDeviceId = [self.externalDeviceId copyWithZone:zone]; } return copy; From 9de38c56fc7615478e1bcc23b1dc0e86c30990f1 Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 21 Sep 2017 17:11:59 +0200 Subject: [PATCH 54/74] Refac get request --- Adjust/ADJAttributionHandler.m | 44 +++--------- Adjust/ADJUtil.h | 17 ++--- Adjust/ADJUtil.m | 123 +++++++++++++++++++++------------ 3 files changed, 90 insertions(+), 94 deletions(-) diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index d8bcb75af..3a9edf5e2 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -184,15 +184,15 @@ - (void)requestAttributionI:(ADJAttributionHandler*)selfI { } [selfI.logger verbose:@"%@", selfI.attributionPackage.extendedString]; - [ADJUtil sendRequest:[selfI requestI:selfI] - prefixErrorMessage:@"Failed to get attribution" - activityPackage:selfI.attributionPackage - responseDataHandler:^(ADJResponseData * responseData) - { - if ([responseData isKindOfClass:[ADJAttributionResponseData class]]) { - [selfI checkAttributionResponse:(ADJAttributionResponseData*)responseData]; - } - }]; + [ADJUtil sendGetRequest:[NSURL URLWithString:ADJUtil.baseUrl] + prefixErrorMessage:@"Failed to get attribution" + activityPackage:selfI.attributionPackage + responseDataHandler:^(ADJResponseData * responseData) + { + if ([responseData isKindOfClass:[ADJAttributionResponseData class]]) { + [selfI checkAttributionResponse:(ADJAttributionResponseData*)responseData]; + } + }]; } - (void)waitRequestAttributionWithDelayI:(ADJAttributionHandler*)selfI @@ -214,32 +214,6 @@ - (void)waitRequestAttributionWithDelayI:(ADJAttributionHandler*)selfI #pragma mark - private -- (NSMutableURLRequest *)requestI:(ADJAttributionHandler*)selfI { - NSString * appSecret = [ADJUtil extractAppSecret:selfI.attributionPackage]; - - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[selfI urlI:selfI]]; - request.timeoutInterval = kRequestTimeout; - request.HTTPMethod = @"GET"; - - [request setValue:selfI.attributionPackage.clientSdk forHTTPHeaderField:@"Client-Sdk"]; - - NSString * authHeader = [ADJUtil buildAuthorizationHeader:appSecret activityPackage:selfI.attributionPackage]; - if (authHeader != nil) { - [request setValue:authHeader forHTTPHeaderField:@"authHeader"]; - } - - return request; -} - -- (NSURL *)urlI:(ADJAttributionHandler*)selfI { - NSString *parameters = [ADJUtil queryString:selfI.attributionPackage.parameters]; - NSString *relativePath = [NSString stringWithFormat:@"%@?%@", selfI.attributionPackage.path, parameters]; - NSURL *baseUrl = [NSURL URLWithString:ADJUtil.baseUrl]; - NSURL *url = [NSURL URLWithString:relativePath relativeToURL:baseUrl]; - - return url; -} - - (void)teardown { [ADJAdjustFactory.logger verbose:@"ADJAttributionHandler teardown"]; diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index ba767b17d..f1358867a 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -45,16 +45,10 @@ typedef void (^selfInjectedBlock)(id); selfInject:(id)selfInject block:(selfInjectedBlock)block; -+ (void)sendRequest:(NSMutableURLRequest *)request - prefixErrorMessage:(NSString *)prefixErrorMessage - activityPackage:(ADJActivityPackage *)activityPackage -responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler; - -+ (void)sendRequest:(NSMutableURLRequest *)request - prefixErrorMessage:(NSString *)prefixErrorMessage - suffixErrorMessage:(NSString *)suffixErrorMessage - activityPackage:(ADJActivityPackage *)activityPackage -responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler; ++ (void)sendGetRequest:(NSURL *)baseUrl + prefixErrorMessage:(NSString *)prefixErrorMessage + activityPackage:(ADJActivityPackage *)activityPackage + responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler; + (void)sendPostRequest:(NSURL *)baseUrl queueSize:(NSUInteger)queueSize @@ -114,9 +108,6 @@ responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler + (NSString *)extractAppSecret:(ADJActivityPackage *)activityPackage; -+ (NSString *)buildAuthorizationHeader:(NSString *)appSecret - activityPackage:(ADJActivityPackage *)activityPackage; - #if !TARGET_OS_TV + (NSString *)readMCC; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 8c4899dbf..cdc79b361 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -521,19 +521,38 @@ + (NSString *)formatErrorMessage:(NSString *)prefixErrorMessage } } ++ (void)sendGetRequest:(NSURL *)baseUrl + prefixErrorMessage:(NSString *)prefixErrorMessage + activityPackage:(ADJActivityPackage *)activityPackage + responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { + + NSMutableURLRequest *request = [ADJUtil requestForGetPackage:activityPackage baseUrl:baseUrl]; + + [ADJUtil sendRequest:request + prefixErrorMessage:prefixErrorMessage + activityPackage:activityPackage + responseDataHandler:responseDataHandler]; +} + ++ (void)sendRequest:(NSMutableURLRequest *)request + prefixErrorMessage:(NSString *)prefixErrorMessage + activityPackage:(ADJActivityPackage *)activityPackage +responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { + [ADJUtil sendRequest:request + prefixErrorMessage:prefixErrorMessage + suffixErrorMessage:nil + activityPackage:activityPackage + responseDataHandler:responseDataHandler]; +} + + (void)sendPostRequest:(NSURL *)baseUrl queueSize:(NSUInteger)queueSize prefixErrorMessage:(NSString *)prefixErrorMessage suffixErrorMessage:(NSString *)suffixErrorMessage activityPackage:(ADJActivityPackage *)activityPackage responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { - NSString *appSecret = [ADJUtil extractAppSecret:activityPackage]; - NSMutableURLRequest *request = [ADJUtil requestForPackage:activityPackage baseUrl:baseUrl queueSize:queueSize]; - NSString *authHeader = [ADJUtil buildAuthorizationHeader:appSecret activityPackage:activityPackage]; - if (authHeader != nil) { - [request setValue:authHeader forHTTPHeaderField:@"Authorization"]; - } + NSMutableURLRequest *request = [ADJUtil requestForPostPackage:activityPackage baseUrl:baseUrl queueSize:queueSize]; [ADJUtil sendRequest:request prefixErrorMessage:prefixErrorMessage @@ -542,6 +561,40 @@ + (void)sendPostRequest:(NSURL *)baseUrl responseDataHandler:responseDataHandler]; } ++ (void)sendRequest:(NSMutableURLRequest *)request + prefixErrorMessage:(NSString *)prefixErrorMessage + suffixErrorMessage:(NSString *)suffixErrorMessage + activityPackage:(ADJActivityPackage *)activityPackage +responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { + NSString *appSecret = [ADJUtil extractAppSecret:activityPackage]; + + NSString *authHeader = [ADJUtil buildAuthorizationHeader:appSecret + activityPackage:activityPackage]; + + if (authHeader != nil) { + [request setValue:authHeader forHTTPHeaderField:@"Authorization"]; + } + + if (userAgent != nil) { + [request setValue:userAgent forHTTPHeaderField:@"User-Agent"]; + } + + Class NSURLSessionClass = NSClassFromString(@"NSURLSession"); + if (NSURLSessionClass != nil) { + [ADJUtil sendNSURLSessionRequest:request + prefixErrorMessage:prefixErrorMessage + suffixErrorMessage:suffixErrorMessage + activityPackage:activityPackage + responseDataHandler:responseDataHandler]; + } else { + [ADJUtil sendNSURLConnectionRequest:request + prefixErrorMessage:prefixErrorMessage + suffixErrorMessage:suffixErrorMessage + activityPackage:activityPackage + responseDataHandler:responseDataHandler]; + } +} + + (NSString *)extractAppSecret:(ADJActivityPackage *)activityPackage { NSString *appSecret = [activityPackage.parameters objectForKey:@"app_secret"]; @@ -554,9 +607,24 @@ + (NSString *)extractAppSecret:(ADJActivityPackage *)activityPackage { return appSecret; } -+ (NSMutableURLRequest *)requestForPackage:(ADJActivityPackage *)activityPackage - baseUrl:(NSURL *)baseUrl - queueSize:(NSUInteger)queueSize { ++ (NSMutableURLRequest *)requestForGetPackage:(ADJActivityPackage *)activityPackage + baseUrl:(NSURL *)baseUrl{ + NSString *parameters = [ADJUtil queryString:activityPackage.parameters]; + NSString *relativePath = [NSString stringWithFormat:@"%@?%@", activityPackage.path, parameters]; + NSURL *url = [NSURL URLWithString:relativePath relativeToURL:baseUrl]; + + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + request.timeoutInterval = kRequestTimeout; + request.HTTPMethod = @"GET"; + + [request setValue:activityPackage.clientSdk forHTTPHeaderField:@"Client-Sdk"]; + + return request; +} + ++ (NSMutableURLRequest *)requestForPostPackage:(ADJActivityPackage *)activityPackage + baseUrl:(NSURL *)baseUrl + queueSize:(NSUInteger)queueSize { NSURL *url = [NSURL URLWithString:activityPackage.path relativeToURL:baseUrl]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; request.timeoutInterval = kRequestTimeout; @@ -676,43 +744,6 @@ + (NSString *)getValidIdentifier:(NSMutableDictionary *)parameters { return nil; } -+ (void)sendRequest:(NSMutableURLRequest *)request - prefixErrorMessage:(NSString *)prefixErrorMessage - activityPackage:(ADJActivityPackage *)activityPackage -responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { - [ADJUtil sendRequest:request - prefixErrorMessage:prefixErrorMessage - suffixErrorMessage:nil - activityPackage:activityPackage - responseDataHandler:responseDataHandler]; -} - -+ (void)sendRequest:(NSMutableURLRequest *)request - prefixErrorMessage:(NSString *)prefixErrorMessage - suffixErrorMessage:(NSString *)suffixErrorMessage - activityPackage:(ADJActivityPackage *)activityPackage -responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { - Class NSURLSessionClass = NSClassFromString(@"NSURLSession"); - - if (userAgent != nil) { - [request setValue:userAgent forHTTPHeaderField:@"User-Agent"]; - } - - if (NSURLSessionClass != nil) { - [ADJUtil sendNSURLSessionRequest:request - prefixErrorMessage:prefixErrorMessage - suffixErrorMessage:suffixErrorMessage - activityPackage:activityPackage - responseDataHandler:responseDataHandler]; - } else { - [ADJUtil sendNSURLConnectionRequest:request - prefixErrorMessage:prefixErrorMessage - suffixErrorMessage:suffixErrorMessage - activityPackage:activityPackage - responseDataHandler:responseDataHandler]; - } -} - + (void)sendNSURLSessionRequest:(NSMutableURLRequest *)request prefixErrorMessage:(NSString *)prefixErrorMessage suffixErrorMessage:(NSString *)suffixErrorMessage From 1f84045652aa18f4b71b26ce89e0f84c57a09613 Mon Sep 17 00:00:00 2001 From: nonelse Date: Thu, 21 Sep 2017 17:13:03 +0200 Subject: [PATCH 55/74] Add secret id --- Adjust/ADJConfig.h | 10 ++++++++-- Adjust/ADJConfig.m | 5 ++++- Adjust/ADJPackageBuilder.m | 1 + Adjust/ADJUtil.m | 20 +++++++++++++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index 7500981e2..066da6d4c 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -155,15 +155,21 @@ */ @property (nonatomic, assign) BOOL isDeviceKnown; +/** + * @brief Adjust app secret id. + */ +@property (nonatomic, copy, readonly, nullable) NSString *secretId; + /** * @brief Adjust app secret. */ -@property (nonatomic, copy, readonly, nonnull) NSString *appSecretS; +@property (nonatomic, copy, readonly, nullable) NSString *appSecretS; /** * @brief Adjust set app secret. */ -- (void)setAppSecret:(NSUInteger)info1 +- (void)setAppSecret:(NSUInteger)secretId + info1:(NSUInteger)info1 info2:(NSUInteger)info2 info3:(NSUInteger)info3 info4:(NSUInteger)info4; diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index 7e6cad87c..df0355ddd 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -166,10 +166,12 @@ - (BOOL)isValid { return self.appToken != nil; } -- (void)setAppSecret:(NSUInteger)info1 +- (void)setAppSecret:(NSUInteger)secretId + info1:(NSUInteger)info1 info2:(NSUInteger)info2 info3:(NSUInteger)info3 info4:(NSUInteger)info4 { + _secretId = [NSString stringWithFormat:@"%lu", secretId]; _appSecretS = [NSString stringWithFormat:@"%lu%lu%lu%lu", (unsigned long)info1, (unsigned long)info2, @@ -191,6 +193,7 @@ -(id)copyWithZone:(NSZone *)zone copy.delayStart = self.delayStart; copy.userAgent = [self.userAgent copyWithZone:zone]; copy.isDeviceKnown = self.isDeviceKnown; + copy->_secretId = [self.secretId copyWithZone:zone]; copy->_appSecretS = [self.appSecretS copyWithZone:zone]; // adjust delegate not copied } diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 6f8f246a5..060e376a2 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -262,6 +262,7 @@ - (void)injectConfig:(ADJConfig *)adjustConfig intoParameters:(NSMutableDictiona if (adjustConfig.isDeviceKnown) { [ADJPackageBuilder parameters:parameters setBool:adjustConfig.isDeviceKnown forKey:@"device_known"]; } + [ADJPackageBuilder parameters:parameters setString:adjustConfig.secretId forKey:@"secret_id"]; [ADJPackageBuilder parameters:parameters setString:adjustConfig.appSecretS forKey:@"app_secret"]; } diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index cdc79b361..1e2d8fb73 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -567,8 +567,11 @@ + (void)sendRequest:(NSMutableURLRequest *)request activityPackage:(ADJActivityPackage *)activityPackage responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { NSString *appSecret = [ADJUtil extractAppSecret:activityPackage]; + NSString *secretId = [ADJUtil extractSecretId:activityPackage]; + NSString *authHeader = [ADJUtil buildAuthorizationHeader:appSecret + secretId:secretId activityPackage:activityPackage]; if (authHeader != nil) { @@ -607,6 +610,18 @@ + (NSString *)extractAppSecret:(ADJActivityPackage *)activityPackage { return appSecret; } ++ (NSString *)extractSecretId:(ADJActivityPackage *)activityPackage { + NSString *appSecret = [activityPackage.parameters objectForKey:@"secret_id"]; + + if (appSecret == nil) { + return nil; + } + + [activityPackage.parameters removeObjectForKey:@"secret_id"]; + + return appSecret; +} + + (NSMutableURLRequest *)requestForGetPackage:(ADJActivityPackage *)activityPackage baseUrl:(NSURL *)baseUrl{ NSString *parameters = [ADJUtil queryString:activityPackage.parameters]; @@ -641,6 +656,7 @@ + (NSMutableURLRequest *)requestForPostPackage:(ADJActivityPackage *)activityPac } + (NSString *)buildAuthorizationHeader:(NSString *)appSecret + secretId:(NSString *)secretId activityPackage:(ADJActivityPackage *)activityPackage { if (appSecret == nil) { return nil; @@ -665,6 +681,8 @@ + (NSString *)buildAuthorizationHeader:(NSString *)appSecret [clearSignature appendString:value]; } + NSString * secretIdHeader = [NSString stringWithFormat:@"secret_id=\"%@\"", secretId]; + // algorithm part of header NSString * algorithm = @"sha256"; NSString * signature = [clearSignature adjSha256]; @@ -680,7 +698,7 @@ + (NSString *)buildAuthorizationHeader:(NSString *)appSecret NSString *fieldsHeader = [NSString stringWithFormat:@"headers=\"%@\"", fields]; // putting it all together - NSString *authorizationHeader = [NSString stringWithFormat:@"Signature %@,%@,%@", signatureHeader, algorithmHeader, fieldsHeader]; + NSString *authorizationHeader = [NSString stringWithFormat:@"Signature %@,%@,%@,%@", secretIdHeader, signatureHeader, algorithmHeader, fieldsHeader]; [ADJAdjustFactory.logger debug:@"authorizationHeader %@", authorizationHeader]; From 9446a6e07f2e836cf3c63217f5c06aa5a496a5fe Mon Sep 17 00:00:00 2001 From: uerceg Date: Wed, 27 Sep 2017 15:58:21 +0200 Subject: [PATCH 56/74] Rebase cleanup --- Adjust.xcodeproj/project.pbxproj | 8 ++++++++ Adjust/ADJAttributionHandler.m | 2 -- Adjust/ADJConfig.m | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index f65fb9e12..a263d5187 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -151,6 +151,10 @@ 9DB457B11D743704004D69E8 /* ADJSdkClickHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF9C8F71D6F3CA5008E362F /* ADJSdkClickHandler.m */; }; 9DD0E9AE1F44690B00B2A759 /* ADJUserDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 9DD0E9AC1F44690B00B2A759 /* ADJUserDefaults.h */; }; 9DD0E9AF1F44690B00B2A759 /* ADJUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD0E9AD1F44690B00B2A759 /* ADJUserDefaults.m */; }; + 9DDF243B1F7BE4A4001C1A70 /* ADJUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD0E9AD1F44690B00B2A759 /* ADJUserDefaults.m */; }; + 9DDF24431F7BE4BA001C1A70 /* ADJUserDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 9DD0E9AC1F44690B00B2A759 /* ADJUserDefaults.h */; }; + 9DDF24441F7BE4DF001C1A70 /* ADJUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD0E9AD1F44690B00B2A759 /* ADJUserDefaults.m */; }; + 9DDF24451F7BE4E7001C1A70 /* ADJUserDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 9DD0E9AC1F44690B00B2A759 /* ADJUserDefaults.h */; }; 9DE7C8FD1AE688DA001556E5 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9DE7C8FC1AE688DA001556E5 /* UIKit.framework */; }; 9DF9C8B31D6ED228008E362F /* ADJKeychain.h in Headers */ = {isa = PBXBuildFile; fileRef = 9DF9C8B11D6ED228008E362F /* ADJKeychain.h */; }; 9DF9C8B41D6ED228008E362F /* ADJKeychain.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF9C8B21D6ED228008E362F /* ADJKeychain.m */; }; @@ -1244,6 +1248,7 @@ 9DF9C9271D6F3CA5008E362F /* ADJEventSuccess.h in Headers */, 9DF9C9371D6F3CA5008E362F /* ADJSessionFailure.h in Headers */, 9DF9C9391D6F3CA5008E362F /* ADJSessionSuccess.h in Headers */, + 9DDF24431F7BE4BA001C1A70 /* ADJUserDefaults.h in Headers */, 6FCC85041F27945E00D6A0ED /* ADJReachability.h in Headers */, 9DF9C9111D6F3CA5008E362F /* NSData+ADJAdditions.h in Headers */, 9DF9C9131D6F3CA5008E362F /* NSString+ADJAdditions.h in Headers */, @@ -1284,6 +1289,7 @@ 9DFB06781D7470C0006D48FC /* ADJEventSuccess.h in Headers */, 9DFB06881D7470C0006D48FC /* ADJSessionFailure.h in Headers */, 9DFB068A1D7470C0006D48FC /* ADJSessionSuccess.h in Headers */, + 9DDF24451F7BE4E7001C1A70 /* ADJUserDefaults.h in Headers */, 6FCC85081F27948C00D6A0ED /* ADJReachability.h in Headers */, 9DFB06621D7470C0006D48FC /* NSData+ADJAdditions.h in Headers */, 9DFB06641D7470C0006D48FC /* NSString+ADJAdditions.h in Headers */, @@ -1750,6 +1756,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 9DDF243B1F7BE4A4001C1A70 /* ADJUserDefaults.m in Sources */, 9DF9C9121D6F3CA5008E362F /* NSData+ADJAdditions.m in Sources */, 9DF9C9141D6F3CA5008E362F /* NSString+ADJAdditions.m in Sources */, 9DF9C9161D6F3CA5008E362F /* UIDevice+ADJAdditions.m in Sources */, @@ -1789,6 +1796,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 9DDF24441F7BE4DF001C1A70 /* ADJUserDefaults.m in Sources */, 9DFB06631D7470C0006D48FC /* NSData+ADJAdditions.m in Sources */, 9DFB06651D7470C0006D48FC /* NSString+ADJAdditions.m in Sources */, 9DFB06671D7470C0006D48FC /* UIDevice+ADJAdditions.m in Sources */, diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 3a9edf5e2..1a9544c4f 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -27,8 +27,6 @@ @interface ADJAttributionHandler() @end -static const double kRequestTimeout = 60; // 60 seconds - @implementation ADJAttributionHandler + (id)handlerWithActivityHandler:(id)activityHandler diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index df0355ddd..0a28ab555 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -171,7 +171,7 @@ - (void)setAppSecret:(NSUInteger)secretId info2:(NSUInteger)info2 info3:(NSUInteger)info3 info4:(NSUInteger)info4 { - _secretId = [NSString stringWithFormat:@"%lu", secretId]; + _secretId = [NSString stringWithFormat:@"%lu", (unsigned long)secretId]; _appSecretS = [NSString stringWithFormat:@"%lu%lu%lu%lu", (unsigned long)info1, (unsigned long)info2, From 8453a8c425f6865de172d37a3e9f343702e58a66 Mon Sep 17 00:00:00 2001 From: nonelse Date: Tue, 26 Sep 2017 12:31:08 +0200 Subject: [PATCH 57/74] Update WebViewJavascriptBridge framework to 6.0.2 --- .../WKWebViewJavascriptBridge.h | 10 ++-- .../WKWebViewJavascriptBridge.m | 53 ++++++++++++----- .../WebViewJavascriptBridge.h | 19 +++++- .../WebViewJavascriptBridge.m | 58 ++++++++++++++----- .../WebViewJavascriptBridgeBase.h | 14 +++-- .../WebViewJavascriptBridgeBase.m | 57 ++++++++++-------- .../WebViewJavascriptBridge_JS.m | 38 ++++++++---- 7 files changed, 170 insertions(+), 79 deletions(-) diff --git a/AdjustBridge/WebViewJavascriptBridge/WKWebViewJavascriptBridge.h b/AdjustBridge/WebViewJavascriptBridge/WKWebViewJavascriptBridge.h index 99859f007..4e3404fc0 100644 --- a/AdjustBridge/WebViewJavascriptBridge/WKWebViewJavascriptBridge.h +++ b/AdjustBridge/WebViewJavascriptBridge/WKWebViewJavascriptBridge.h @@ -6,10 +6,10 @@ // #if (__MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 || __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_1) -#define supportsWKWebKit +#define supportsWKWebView #endif -#if defined(supportsWKWebKit ) +#if defined supportsWKWebView #import #import "WebViewJavascriptBridgeBase.h" @@ -21,12 +21,14 @@ + (void)enableLogging; - (void)registerHandler:(NSString*)handlerName handler:(WVJBHandler)handler; +- (void)removeHandler:(NSString*)handlerName; - (void)callHandler:(NSString*)handlerName; - (void)callHandler:(NSString*)handlerName data:(id)data; - (void)callHandler:(NSString*)handlerName data:(id)data responseCallback:(WVJBResponseCallback)responseCallback; - (void)reset; -- (void)setWebViewDelegate:(id)webViewDelegate; +- (void)setWebViewDelegate:(id)webViewDelegate; +- (void)disableJavscriptAlertBoxSafetyTimeout; @end -#endif \ No newline at end of file +#endif diff --git a/AdjustBridge/WebViewJavascriptBridge/WKWebViewJavascriptBridge.m b/AdjustBridge/WebViewJavascriptBridge/WKWebViewJavascriptBridge.m index 0fcf7e25c..3c6caba1e 100644 --- a/AdjustBridge/WebViewJavascriptBridge/WKWebViewJavascriptBridge.m +++ b/AdjustBridge/WebViewJavascriptBridge/WKWebViewJavascriptBridge.m @@ -8,11 +8,11 @@ #import "WKWebViewJavascriptBridge.h" -#if defined(supportsWKWebKit) +#if defined supportsWKWebView @implementation WKWebViewJavascriptBridge { - WKWebView* _webView; - id _webViewDelegate; + __weak WKWebView* _webView; + __weak id _webViewDelegate; long _uniqueId; WebViewJavascriptBridgeBase *_base; } @@ -53,6 +53,10 @@ - (void)registerHandler:(NSString *)handlerName handler:(WVJBHandler)handler { _base.messageHandlers[handlerName] = [handler copy]; } +- (void)removeHandler:(NSString *)handlerName { + [_base.messageHandlers removeObjectForKey:handlerName]; +} + - (void)reset { [_base reset]; } @@ -61,6 +65,10 @@ - (void)setWebViewDelegate:(id)webViewDelegate { _webViewDelegate = webViewDelegate; } +- (void)disableJavscriptAlertBoxSafetyTimeout { + [_base disableJavscriptAlertBoxSafetyTimeout]; +} + /* Internals ***********/ @@ -92,8 +100,7 @@ - (void)WKFlushMessageQueue { }]; } -- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation -{ +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { if (webView != _webView) { return; } __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; @@ -103,14 +110,35 @@ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat } -- (void)webView:(WKWebView *)webView -decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction -decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { +- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler { + if (webView != _webView) { return; } + + __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; + if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationResponse:decisionHandler:)]) { + [strongDelegate webView:webView decidePolicyForNavigationResponse:navigationResponse decisionHandler:decisionHandler]; + } + else { + decisionHandler(WKNavigationResponsePolicyAllow); + } +} + +- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler { + if (webView != _webView) { return; } + + __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; + if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didReceiveAuthenticationChallenge:completionHandler:)]) { + [strongDelegate webView:webView didReceiveAuthenticationChallenge:challenge completionHandler:completionHandler]; + } else { + completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); + } +} + +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { if (webView != _webView) { return; } NSURL *url = navigationAction.request.URL; __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; - if ([_base isCorrectProcotocolScheme:url]) { + if ([_base isWebViewJavascriptBridgeURL:url]) { if ([_base isBridgeLoadedURL:url]) { [_base injectJavascriptFile]; } else if ([_base isQueueMessageURL:url]) { @@ -136,9 +164,7 @@ - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation } -- (void)webView:(WKWebView *)webView -didFailNavigation:(WKNavigation *)navigation - withError:(NSError *)error { +- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error { if (webView != _webView) { return; } __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; @@ -156,8 +182,7 @@ - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation } } -- (NSString*) _evaluateJavascript:(NSString*)javascriptCommand -{ +- (NSString*) _evaluateJavascript:(NSString*)javascriptCommand { [_webView evaluateJavaScript:javascriptCommand completionHandler:nil]; return NULL; } diff --git a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.h b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.h index aff055312..1b64bb4e9 100755 --- a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.h +++ b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.h @@ -9,8 +9,15 @@ #import #import "WebViewJavascriptBridgeBase.h" +#if (__MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 || __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_1) +#define supportsWKWebView +#endif + +#if defined supportsWKWebView +#import +#endif + #if defined __MAC_OS_X_VERSION_MAX_ALLOWED - #import #define WVJB_PLATFORM_OSX #define WVJB_WEBVIEW_TYPE WebView #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject @@ -25,13 +32,19 @@ @interface WebViewJavascriptBridge : WVJB_WEBVIEW_DELEGATE_INTERFACE -+ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView; + ++ (instancetype)bridgeForWebView:(id)webView; ++ (instancetype)bridge:(id)webView; + + (void)enableLogging; + (void)setLogMaxLength:(int)length; - (void)registerHandler:(NSString*)handlerName handler:(WVJBHandler)handler; +- (void)removeHandler:(NSString*)handlerName; - (void)callHandler:(NSString*)handlerName; - (void)callHandler:(NSString*)handlerName data:(id)data; - (void)callHandler:(NSString*)handlerName data:(id)data responseCallback:(WVJBResponseCallback)responseCallback; -- (void)setWebViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate; +- (void)setWebViewDelegate:(id)webViewDelegate; +- (void)disableJavscriptAlertBoxSafetyTimeout; + @end diff --git a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.m b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.m index 20e88d4f9..e74a6e24e 100755 --- a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.m +++ b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.m @@ -8,6 +8,10 @@ #import "WebViewJavascriptBridge.h" +#if defined(supportsWKWebView) +#import "WKWebViewJavascriptBridge.h" +#endif + #if __has_feature(objc_arc_weak) #define WVJB_WEAK __weak #else @@ -24,13 +28,29 @@ @implementation WebViewJavascriptBridge { /* API *****/ -+ (void)enableLogging { [WebViewJavascriptBridgeBase enableLogging]; } -+ (void)setLogMaxLength:(int)length { [WebViewJavascriptBridgeBase setLogMaxLength:length]; } ++ (void)enableLogging { + [WebViewJavascriptBridgeBase enableLogging]; +} ++ (void)setLogMaxLength:(int)length { + [WebViewJavascriptBridgeBase setLogMaxLength:length]; +} -+ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView { - WebViewJavascriptBridge* bridge = [[self alloc] init]; - [bridge _platformSpecificSetup:webView]; - return bridge; ++ (instancetype)bridgeForWebView:(id)webView { + return [self bridge:webView]; +} ++ (instancetype)bridge:(id)webView { +#if defined supportsWKWebView + if ([webView isKindOfClass:[WKWebView class]]) { + return (WebViewJavascriptBridge*) [WKWebViewJavascriptBridge bridgeForWebView:webView]; + } +#endif + if ([webView isKindOfClass:[WVJB_WEBVIEW_TYPE class]]) { + WebViewJavascriptBridge* bridge = [[self alloc] init]; + [bridge _platformSpecificSetup:webView]; + return bridge; + } + [NSException raise:@"BadWebViewType" format:@"Unknown web view type."]; + return nil; } - (void)setWebViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate { @@ -61,6 +81,15 @@ - (void)registerHandler:(NSString *)handlerName handler:(WVJBHandler)handler { _base.messageHandlers[handlerName] = [handler copy]; } +- (void)removeHandler:(NSString *)handlerName { + [_base.messageHandlers removeObjectForKey:handlerName]; +} + +- (void)disableJavscriptAlertBoxSafetyTimeout { + [_base disableJavscriptAlertBoxSafetyTimeout]; +} + + /* Platform agnostic internals *****************************/ @@ -71,20 +100,17 @@ - (void)dealloc { _webViewDelegate = nil; } -- (NSString*) _evaluateJavascript:(NSString*)javascriptCommand -{ +- (NSString*) _evaluateJavascript:(NSString*)javascriptCommand { return [_webView stringByEvaluatingJavaScriptFromString:javascriptCommand]; } +#if defined WVJB_PLATFORM_OSX /* Platform specific internals: OSX **********************************/ -#if defined WVJB_PLATFORM_OSX - (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView { _webView = webView; - _webView.policyDelegate = self; - _base = [[WebViewJavascriptBridgeBase alloc] init]; _base.delegate = self; } @@ -93,12 +119,11 @@ - (void) _platformSpecificDealloc { _webView.policyDelegate = nil; } -- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener -{ +- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { if (webView != _webView) { return; } NSURL *url = [request URL]; - if ([_base isCorrectProcotocolScheme:url]) { + if ([_base isWebViewJavascriptBridgeURL:url]) { if ([_base isBridgeLoadedURL:url]) { [_base injectJavascriptFile]; } else if ([_base isQueueMessageURL:url]) { @@ -117,9 +142,9 @@ - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary +#elif defined WVJB_PLATFORM_IOS /* Platform specific internals: iOS **********************************/ -#elif defined WVJB_PLATFORM_IOS - (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView { _webView = webView; @@ -152,9 +177,10 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if (webView != _webView) { return YES; } + NSURL *url = [request URL]; __strong WVJB_WEBVIEW_DELEGATE_TYPE* strongDelegate = _webViewDelegate; - if ([_base isCorrectProcotocolScheme:url]) { + if ([_base isWebViewJavascriptBridgeURL:url]) { if ([_base isBridgeLoadedURL:url]) { [_base injectJavascriptFile]; } else if ([_base isQueueMessageURL:url]) { diff --git a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridgeBase.h b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridgeBase.h index 16b23c794..54d80acc6 100755 --- a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridgeBase.h +++ b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridgeBase.h @@ -7,9 +7,10 @@ #import -#define kCustomProtocolScheme @"wvjbscheme" -#define kQueueHasMessage @"__WVJB_QUEUE_MESSAGE__" -#define kBridgeLoaded @"__BRIDGE_LOADED__" +#define kOldProtocolScheme @"wvjbscheme" +#define kNewProtocolScheme @"https" +#define kQueueHasMessage @"__wvjb_queue_message__" +#define kBridgeLoaded @"__bridge_loaded__" typedef void (^WVJBResponseCallback)(id responseData); typedef void (^WVJBHandler)(id data, WVJBResponseCallback responseCallback); @@ -22,7 +23,7 @@ typedef NSDictionary WVJBMessage; @interface WebViewJavascriptBridgeBase : NSObject -@property (assign) id delegate; +@property (weak, nonatomic) id delegate; @property (strong, nonatomic) NSMutableArray* startupMessageQueue; @property (strong, nonatomic) NSMutableDictionary* responseCallbacks; @property (strong, nonatomic) NSMutableDictionary* messageHandlers; @@ -34,11 +35,12 @@ typedef NSDictionary WVJBMessage; - (void)sendData:(id)data responseCallback:(WVJBResponseCallback)responseCallback handlerName:(NSString*)handlerName; - (void)flushMessageQueue:(NSString *)messageQueueString; - (void)injectJavascriptFile; -- (BOOL)isCorrectProcotocolScheme:(NSURL*)url; +- (BOOL)isWebViewJavascriptBridgeURL:(NSURL*)url; - (BOOL)isQueueMessageURL:(NSURL*)urll; - (BOOL)isBridgeLoadedURL:(NSURL*)urll; - (void)logUnkownMessage:(NSURL*)url; - (NSString *)webViewJavascriptCheckCommand; - (NSString *)webViewJavascriptFetchQueyCommand; +- (void)disableJavscriptAlertBoxSafetyTimeout; -@end \ No newline at end of file +@end diff --git a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridgeBase.m b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridgeBase.m index f290a48dd..3ec26ed41 100755 --- a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridgeBase.m +++ b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridgeBase.m @@ -10,7 +10,7 @@ #import "WebViewJavascriptBridge_JS.h" @implementation WebViewJavascriptBridgeBase { - id _webViewDelegate; + __weak id _webViewDelegate; long _uniqueId; } @@ -20,13 +20,14 @@ @implementation WebViewJavascriptBridgeBase { + (void)enableLogging { logging = true; } + (void)setLogMaxLength:(int)length { logMaxLength = length;} --(id)init { - self = [super init]; - self.messageHandlers = [NSMutableDictionary dictionary]; - self.startupMessageQueue = [NSMutableArray array]; - self.responseCallbacks = [NSMutableDictionary dictionary]; - _uniqueId = 0; - return(self); +- (id)init { + if (self = [super init]) { + self.messageHandlers = [NSMutableDictionary dictionary]; + self.startupMessageQueue = [NSMutableArray array]; + self.responseCallbacks = [NSMutableDictionary dictionary]; + _uniqueId = 0; + } + return self; } - (void)dealloc { @@ -121,38 +122,44 @@ - (void)injectJavascriptFile { } } --(BOOL)isCorrectProcotocolScheme:(NSURL*)url { - if([[url scheme] isEqualToString:kCustomProtocolScheme]){ - return YES; - } else { +- (BOOL)isWebViewJavascriptBridgeURL:(NSURL*)url { + if (![self isSchemeMatch:url]) { return NO; } + return [self isBridgeLoadedURL:url] || [self isQueueMessageURL:url]; } --(BOOL)isQueueMessageURL:(NSURL*)url { - if([[url host] isEqualToString:kQueueHasMessage]){ - return YES; - } else { - return NO; - } +- (BOOL)isSchemeMatch:(NSURL*)url { + NSString* scheme = url.scheme.lowercaseString; + return [scheme isEqualToString:kNewProtocolScheme] || [scheme isEqualToString:kOldProtocolScheme]; +} + +- (BOOL)isQueueMessageURL:(NSURL*)url { + NSString* host = url.host.lowercaseString; + return [self isSchemeMatch:url] && [host isEqualToString:kQueueHasMessage]; } --(BOOL)isBridgeLoadedURL:(NSURL*)url { - return ([[url scheme] isEqualToString:kCustomProtocolScheme] && [[url host] isEqualToString:kBridgeLoaded]); +- (BOOL)isBridgeLoadedURL:(NSURL*)url { + NSString* host = url.host.lowercaseString; + return [self isSchemeMatch:url] && [host isEqualToString:kBridgeLoaded]; } --(void)logUnkownMessage:(NSURL*)url { - NSLog(@"WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@://%@", kCustomProtocolScheme, [url path]); +- (void)logUnkownMessage:(NSURL*)url { + NSLog(@"WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@", [url absoluteString]); } --(NSString *)webViewJavascriptCheckCommand { +- (NSString *)webViewJavascriptCheckCommand { return @"typeof WebViewJavascriptBridge == \'object\';"; } --(NSString *)webViewJavascriptFetchQueyCommand { +- (NSString *)webViewJavascriptFetchQueyCommand { return @"WebViewJavascriptBridge._fetchQueue();"; } +- (void)disableJavscriptAlertBoxSafetyTimeout { + [self sendData:nil responseCallback:nil handlerName:@"_disableJavascriptAlertBoxSafetyTimeout"]; +} + // Private // ------------------------------------------- @@ -211,4 +218,4 @@ - (void)_log:(NSString *)action json:(id)json { } } -@end \ No newline at end of file +@end diff --git a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge_JS.m b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge_JS.m index 3a494dd4d..670a552f1 100644 --- a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge_JS.m +++ b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge_JS.m @@ -19,9 +19,16 @@ if (window.WebViewJavascriptBridge) { return; } + + if (!window.onerror) { + window.onerror = function(msg, url, line) { + console.log("WebViewJavascriptBridge: ERROR:" + msg + "@" + url + ":" + line); + } + } window.WebViewJavascriptBridge = { registerHandler: registerHandler, callHandler: callHandler, + disableJavscriptAlertBoxSafetyTimeout: disableJavscriptAlertBoxSafetyTimeout, _fetchQueue: _fetchQueue, _handleMessageFromObjC: _handleMessageFromObjC }; @@ -30,11 +37,12 @@ var sendMessageQueue = []; var messageHandlers = {}; - var CUSTOM_PROTOCOL_SCHEME = 'wvjbscheme'; - var QUEUE_HAS_MESSAGE = '__WVJB_QUEUE_MESSAGE__'; + var CUSTOM_PROTOCOL_SCHEME = 'https'; + var QUEUE_HAS_MESSAGE = '__wvjb_queue_message__'; var responseCallbacks = {}; var uniqueId = 1; + var dispatchMessagesWithTimeoutSafety = true; function registerHandler(handlerName, handler) { messageHandlers[handlerName] = handler; @@ -47,6 +55,9 @@ function callHandler(handlerName, data, responseCallback) { } _doSend({ handlerName:handlerName, data:data }, responseCallback); } + function disableJavscriptAlertBoxSafetyTimeout() { + dispatchMessagesWithTimeoutSafety = false; + } function _doSend(message, responseCallback) { if (responseCallback) { @@ -65,7 +76,13 @@ function _fetchQueue() { } function _dispatchMessageFromObjC(messageJSON) { - setTimeout(function _timeoutDispatchMessageFromObjC() { + if (dispatchMessagesWithTimeoutSafety) { + setTimeout(_doDispatchMessageFromObjC); + } else { + _doDispatchMessageFromObjC(); + } + + function _doDispatchMessageFromObjC() { var message = JSON.parse(messageJSON); var messageHandler; var responseCallback; @@ -81,21 +98,18 @@ function _dispatchMessageFromObjC(messageJSON) { if (message.callbackId) { var callbackResponseId = message.callbackId; responseCallback = function(responseData) { - _doSend({ responseId:callbackResponseId, responseData:responseData }); + _doSend({ handlerName:message.handlerName, responseId:callbackResponseId, responseData:responseData }); }; } var handler = messageHandlers[message.handlerName]; - try { - handler(message.data, responseCallback); - } catch(exception) { - console.log("WebViewJavascriptBridge: WARNING: javascript handler threw.", message, exception); - } if (!handler) { console.log("WebViewJavascriptBridge: WARNING: no handler for message from ObjC:", message); + } else { + handler(message.data, responseCallback); } } - }); + } } function _handleMessageFromObjC(messageJSON) { @@ -107,6 +121,8 @@ function _handleMessageFromObjC(messageJSON) { messagingIframe.src = CUSTOM_PROTOCOL_SCHEME + '://' + QUEUE_HAS_MESSAGE; document.documentElement.appendChild(messagingIframe); + registerHandler("_disableJavascriptAlertBoxSafetyTimeout", disableJavscriptAlertBoxSafetyTimeout); + setTimeout(_callWVJBCallbacks, 0); function _callWVJBCallbacks() { var callbacks = window.WVJBCallbacks; @@ -120,4 +136,4 @@ function _callWVJBCallbacks() { #undef __wvjb_js_func__ return preprocessorJSCode; -}; \ No newline at end of file +}; From cfb80faf11a03b7b4678ff9b82619dc9d9e7521a Mon Sep 17 00:00:00 2001 From: nonelse Date: Tue, 26 Sep 2017 12:33:09 +0200 Subject: [PATCH 58/74] Remove unecessary bridge references --- AdjustBridge/AdjustBridgeRegister.h | 1 - AdjustBridge/AdjustBridgeRegister.m | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/AdjustBridge/AdjustBridgeRegister.h b/AdjustBridge/AdjustBridgeRegister.h index f1531109b..3e337adcf 100644 --- a/AdjustBridge/AdjustBridgeRegister.h +++ b/AdjustBridge/AdjustBridgeRegister.h @@ -8,7 +8,6 @@ #import #import "WebViewJavascriptBridge.h" -#import "WKWebViewJavascriptBridge.h" @protocol AdjustBridgeRegister diff --git a/AdjustBridge/AdjustBridgeRegister.m b/AdjustBridge/AdjustBridgeRegister.m index 06a52083a..b1abfc3b8 100644 --- a/AdjustBridge/AdjustBridgeRegister.m +++ b/AdjustBridge/AdjustBridgeRegister.m @@ -58,7 +58,7 @@ - (void)callHandler:(NSString *)handlerName data:(id)data { @interface AdjustWKBridgeRegister() -@property (nonatomic, strong) WKWebViewJavascriptBridge *wkBridge; +@property (nonatomic, strong) WebViewJavascriptBridge *wkBridge; @end @@ -75,7 +75,7 @@ - (id)initWithWKWebView:(WKWebView *)wkWebView { return nil; } - self.wkBridge = [WKWebViewJavascriptBridge bridgeForWebView:wkWebView]; + self.wkBridge = [WebViewJavascriptBridge bridgeForWebView:wkWebView]; return self; } From 558da1452b9c4b54691605213cde4a776595c1a6 Mon Sep 17 00:00:00 2001 From: nonelse Date: Tue, 26 Sep 2017 12:33:29 +0200 Subject: [PATCH 59/74] Update web view bridge example --- .../AdjustExample-WebView.html | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/examples/AdjustExample-WebView/AdjustExample-WebView/AdjustExample-WebView.html b/examples/AdjustExample-WebView/AdjustExample-WebView/AdjustExample-WebView.html index adb3e702f..4cc76c58a 100644 --- a/examples/AdjustExample-WebView/AdjustExample-WebView/AdjustExample-WebView.html +++ b/examples/AdjustExample-WebView/AdjustExample-WebView/AdjustExample-WebView.html @@ -16,21 +16,13 @@

Adjust Web View Demo

window.onerror = function(err) { } function setupWebViewJavascriptBridge(callback) { - if (window.WebViewJavascriptBridge) { - return callback(WebViewJavascriptBridge); - } - - if (window.WVJBCallbacks) { - return window.WVJBCallbacks.push(callback); - } - + if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); } + if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); } window.WVJBCallbacks = [callback]; - var WVJBIframe = document.createElement('iframe'); WVJBIframe.style.display = 'none'; - WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__'; + WVJBIframe.src = 'https://__bridge_loaded__'; document.documentElement.appendChild(WVJBIframe); - setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0) } From 362c06df7495dd1d8eba134822f1d90ee5beb604 Mon Sep 17 00:00:00 2001 From: nonelse Date: Tue, 26 Sep 2017 12:40:49 +0200 Subject: [PATCH 60/74] Webview bridge guide update --- doc/english/web_views.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/english/web_views.md b/doc/english/web_views.md index 41021c027..4be2be619 100644 --- a/doc/english/web_views.md +++ b/doc/english/web_views.md @@ -102,7 +102,7 @@ function setupWebViewJavascriptBridge(callback) { var WVJBIframe = document.createElement('iframe'); WVJBIframe.style.display = 'none'; - WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__'; + WVJBIframe.src = 'https://__bridge_loaded__'; document.documentElement.appendChild(WVJBIframe); setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0) @@ -113,6 +113,8 @@ setupWebViewJavascriptBridge(function(bridge) { }) ``` +Take notice that the line `WVJBIframe.src = 'https://__bridge_loaded__';` was changed in version 4.11.6 from `WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';` due to a change in the `WebViewJavascriptBridge` plugin. + ![][bridge_init_js] ### Basic setup From df5a995433c99244f85a077155dbbe43f5dca811 Mon Sep 17 00:00:00 2001 From: nonelse Date: Mon, 2 Oct 2017 11:50:15 +0200 Subject: [PATCH 61/74] Extract secret from package before request --- Adjust/ADJUtil.m | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 1e2d8fb73..c1d3ca200 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -526,21 +526,30 @@ + (void)sendGetRequest:(NSURL *)baseUrl activityPackage:(ADJActivityPackage *)activityPackage responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { + NSString *appSecret = [ADJUtil extractAppSecret:activityPackage]; + NSString *secretId = [ADJUtil extractSecretId:activityPackage]; + NSMutableURLRequest *request = [ADJUtil requestForGetPackage:activityPackage baseUrl:baseUrl]; [ADJUtil sendRequest:request prefixErrorMessage:prefixErrorMessage activityPackage:activityPackage + secretId:secretId + appSecret:appSecret responseDataHandler:responseDataHandler]; } + (void)sendRequest:(NSMutableURLRequest *)request prefixErrorMessage:(NSString *)prefixErrorMessage activityPackage:(ADJActivityPackage *)activityPackage + secretId:(NSString *)secretId + appSecret:(NSString *)appSecret responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { [ADJUtil sendRequest:request prefixErrorMessage:prefixErrorMessage suffixErrorMessage:nil + secretId:secretId + appSecret:appSecret activityPackage:activityPackage responseDataHandler:responseDataHandler]; } @@ -552,11 +561,16 @@ + (void)sendPostRequest:(NSURL *)baseUrl activityPackage:(ADJActivityPackage *)activityPackage responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { + NSString *appSecret = [ADJUtil extractAppSecret:activityPackage]; + NSString *secretId = [ADJUtil extractSecretId:activityPackage]; + NSMutableURLRequest *request = [ADJUtil requestForPostPackage:activityPackage baseUrl:baseUrl queueSize:queueSize]; [ADJUtil sendRequest:request prefixErrorMessage:prefixErrorMessage suffixErrorMessage:suffixErrorMessage + secretId:secretId + appSecret:appSecret activityPackage:activityPackage responseDataHandler:responseDataHandler]; } @@ -564,11 +578,10 @@ + (void)sendPostRequest:(NSURL *)baseUrl + (void)sendRequest:(NSMutableURLRequest *)request prefixErrorMessage:(NSString *)prefixErrorMessage suffixErrorMessage:(NSString *)suffixErrorMessage + secretId:(NSString *)secretId + appSecret:(NSString *)appSecret activityPackage:(ADJActivityPackage *)activityPackage responseDataHandler:(void (^)(ADJResponseData *responseData))responseDataHandler { - NSString *appSecret = [ADJUtil extractAppSecret:activityPackage]; - NSString *secretId = [ADJUtil extractSecretId:activityPackage]; - NSString *authHeader = [ADJUtil buildAuthorizationHeader:appSecret secretId:secretId From 88ae0365d0426a357f337f8af434fb57737a5d2f Mon Sep 17 00:00:00 2001 From: nonelse Date: Wed, 4 Oct 2017 14:45:29 +0200 Subject: [PATCH 62/74] Remove read session parameters --- Adjust/ADJActivityHandler.m | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 7bbe1c4fb..accae7e50 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -27,7 +27,6 @@ static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAttributionFilename = @"AdjustIoAttribution"; -static NSString * const kSessionParametersFilename = @"AdjustSessionParameters"; static NSString * const kSessionCallbackParametersFilename = @"AdjustSessionCallbackParameters"; static NSString * const kSessionPartnerParametersFilename = @"AdjustSessionPartnerParameters"; static NSString * const kAdjustPrefix = @"adjust_"; @@ -584,7 +583,7 @@ - (void)initI:(ADJActivityHandler *)selfI selfI.deviceInfo = [ADJDeviceInfo deviceInfoWithSdkPrefix:selfI.adjustConfig.sdkPrefix]; // read files that are accessed only in Internal sections - [selfI readSessionParameters:selfI]; + selfI.sessionParameters = [[ADJSessionParameters alloc] init]; [selfI readSessionCallbackParametersI:selfI]; [selfI readSessionPartnerParametersI:selfI]; @@ -1395,16 +1394,6 @@ - (void)teardownAllSessionParametersS:(BOOL)deleteState { } } -- (void)readSessionParameters:(ADJActivityHandler *)selfI { - selfI.sessionParameters = [ADJUtil readObject:kSessionParametersFilename - objectName:@"Session parameters" - class:[ADJSessionParameters class]]; - - if (selfI.sessionParameters == nil) { - selfI.sessionParameters = [[ADJSessionParameters alloc] init]; - } -} - - (void)readSessionCallbackParametersI:(ADJActivityHandler *)selfI { selfI.sessionParameters.callbackParameters = [ADJUtil readObject:kSessionCallbackParametersFilename objectName:@"Session Callback parameters" From 19efe4c86b5f777ac80e61142ca83aa547b2b4cb Mon Sep 17 00:00:00 2001 From: uerceg Date: Thu, 5 Oct 2017 11:41:18 +0200 Subject: [PATCH 63/74] Don't log authentication stuff --- Adjust/ADJActivityPackage.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Adjust/ADJActivityPackage.m b/Adjust/ADJActivityPackage.m index 23fa4e543..0fb097f47 100644 --- a/Adjust/ADJActivityPackage.m +++ b/Adjust/ADJActivityPackage.m @@ -15,6 +15,7 @@ @implementation ADJActivityPackage - (NSString *)extendedString { NSMutableString *builder = [NSMutableString string]; + NSArray *excludedKeys = @[@"secret_id", @"app_secret"]; [builder appendFormat:@"Path: %@\n", self.path]; [builder appendFormat:@"ClientSdk: %@\n", self.clientSdk]; @@ -26,7 +27,12 @@ - (NSString *)extendedString { [builder appendFormat:@"Parameters:"]; for (NSUInteger i = 0; i < keyCount; i++) { - NSString *key = (NSString*)[sortedKeys objectAtIndex:i]; + NSString *key = (NSString *)[sortedKeys objectAtIndex:i]; + + if ([excludedKeys containsObject:key]) { + continue; + } + NSString *value = [self.parameters objectForKey:key]; [builder appendFormat:@"\n\t\t%-22s %@", [key UTF8String], value]; From 59a2f10d8371623c881a7227bb91a65818655274 Mon Sep 17 00:00:00 2001 From: uerceg Date: Sat, 14 Oct 2017 11:43:50 +0700 Subject: [PATCH 64/74] Project updates with recommended warnings --- Adjust.xcodeproj/project.pbxproj | 14 +++++++++++++- .../xcshareddata/xcschemes/AdjustSdk.xcscheme | 4 +++- .../xcshareddata/xcschemes/AdjustSdkTv.xcscheme | 4 +++- .../AdjustExample-Swift.xcodeproj/project.pbxproj | 14 +++++++++++++- .../project.pbxproj | 14 +++++++++++++- .../AdjustExample-iOS.xcodeproj/project.pbxproj | 14 +++++++++++++- .../AdjustExample-iWatch.xcodeproj/project.pbxproj | 14 +++++++++++++- .../AdjustExample-tvOS.xcodeproj/project.pbxproj | 14 +++++++++++++- 8 files changed, 84 insertions(+), 8 deletions(-) diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index a263d5187..4ca04ea44 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -1435,7 +1435,7 @@ 9679920518BBAE2800394606 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "adjust GmbH"; TargetAttributes = { 9615158E1CD2CB2C0022D336 = { @@ -1926,14 +1926,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -1971,14 +1977,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/Adjust.xcodeproj/xcshareddata/xcschemes/AdjustSdk.xcscheme b/Adjust.xcodeproj/xcshareddata/xcschemes/AdjustSdk.xcscheme index ee69ec69d..34092201a 100644 --- a/Adjust.xcodeproj/xcshareddata/xcschemes/AdjustSdk.xcscheme +++ b/Adjust.xcodeproj/xcshareddata/xcschemes/AdjustSdk.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Release" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Adjust.xcodeproj/xcshareddata/xcschemes/AdjustSdkTv.xcscheme b/Adjust.xcodeproj/xcshareddata/xcschemes/AdjustSdkTv.xcscheme index fb99b3218..11211fec7 100644 --- a/Adjust.xcodeproj/xcshareddata/xcschemes/AdjustSdkTv.xcscheme +++ b/Adjust.xcodeproj/xcshareddata/xcschemes/AdjustSdkTv.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj b/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj index 53416dbd6..dd3b170be 100644 --- a/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-Swift/AdjustExample-Swift.xcodeproj/project.pbxproj @@ -294,7 +294,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0810; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "adjust GmbH"; TargetAttributes = { 9DF7A9C11CB4ECA600D3591F = { @@ -410,14 +410,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -457,14 +463,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj b/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj index f579c0d1c..de9b48353 100644 --- a/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-WebView/AdjustExample-WebView.xcodeproj/project.pbxproj @@ -383,7 +383,7 @@ 9D10829C1CFDAF8E0050568B /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "adjust GmbH"; TargetAttributes = { 9D1082A31CFDAF8E0050568B = { @@ -490,14 +490,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -537,14 +543,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj b/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj index f4f23bd13..b9202f81e 100644 --- a/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-iOS/AdjustExample-iOS.xcodeproj/project.pbxproj @@ -312,7 +312,7 @@ 963909341BCBFCF300A2E8A4 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0810; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = adjust; TargetAttributes = { 9639093B1BCBFCF300A2E8A4 = { @@ -433,14 +433,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -479,14 +485,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj b/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj index 46ab47b4e..5cf41c690 100644 --- a/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-iWatch/AdjustExample-iWatch.xcodeproj/project.pbxproj @@ -460,7 +460,7 @@ 9DF7AC0C1CB4FEDB00D3591F /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "adjust GmbH"; TargetAttributes = { 9DF7AC131CB4FEDB00D3591F = { @@ -637,14 +637,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -684,14 +690,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj b/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj index d03649c4d..1409e8221 100644 --- a/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj +++ b/examples/AdjustExample-tvOS/AdjustExample-tvOS.xcodeproj/project.pbxproj @@ -318,7 +318,7 @@ 963909AA1BCC0D8300A2E8A4 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0810; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = adjust; TargetAttributes = { 963909B11BCC0D8300A2E8A4 = { @@ -431,14 +431,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -477,14 +483,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; From 7f5077c10dee7f8b67be65f6a59d4a1bc83aeefd Mon Sep 17 00:00:00 2001 From: uerceg Date: Mon, 30 Oct 2017 10:44:47 +0100 Subject: [PATCH 65/74] Enable v3 -> v4 internal files migration --- Adjust/ADJPackageHandler.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Adjust/ADJPackageHandler.m b/Adjust/ADJPackageHandler.m index 47f21ee9c..d7e163cdb 100644 --- a/Adjust/ADJPackageHandler.m +++ b/Adjust/ADJPackageHandler.m @@ -238,6 +238,8 @@ - (void)updatePackagesI:(ADJPackageHandler *)selfI #pragma mark - private - (void)readPackageQueueI:(ADJPackageHandler *)selfI { + [NSKeyedUnarchiver setClass:[ADJActivityPackage class] forClassName:@"AIActivityPackage"]; + id object = [ADJUtil readObject:kPackageQueueFilename objectName:@"Package queue" class:[NSArray class]]; if (object != nil) { From 20595a5c26ee66f616dded112c6c8c49e710d007 Mon Sep 17 00:00:00 2001 From: Aleksandr Gusev Date: Sun, 29 Oct 2017 22:46:48 -0400 Subject: [PATCH 66/74] Fix potential deadlock when accessing a shared pasteboard from a background thread. --- Adjust/ADJAdditions/UIDevice+ADJAdditions.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m index 40a6f5e9e..a8296e988 100644 --- a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m +++ b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m @@ -102,8 +102,16 @@ - (NSString *)adjFbAttributionId { #if ADJUST_NO_UIPASTEBOARD || TARGET_OS_TV return @""; #else - NSString *result = [UIPasteboard pasteboardWithName:@"fb_app_attribution" create:NO].string; - if (result == nil) return @""; + __block NSString *result; + void(^resultRetrievalBlock)(void) = ^{ + result = [UIPasteboard pasteboardWithName:@"fb_app_attribution" create:NO].string; + if (result == nil) { + result = @""; + } + }; + [NSThread isMainThread] ? + resultRetrievalBlock() : + dispatch_sync(dispatch_get_main_queue(), resultRetrievalBlock); return result; #endif } From f7777468f16cad351b9bdfafbeab6680e76ef15a Mon Sep 17 00:00:00 2001 From: easteracrobat Date: Wed, 29 Nov 2017 11:25:12 +0100 Subject: [PATCH 67/74] current-install-to-current-attribution --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4d1afbd1d..d5ced9444 100644 --- a/README.md +++ b/README.md @@ -441,14 +441,14 @@ As the delegate callback is configured using the `ADJConfig` instance, you shoul The delegate function will be called after the SDK receives the final attribution data. Within the delegate function you have access to the `attribution` parameter. Here is a quick summary of its properties: -- `NSString trackerToken` the tracker token of the current install. -- `NSString trackerName` the tracker name of the current install. -- `NSString network` the network grouping level of the current install. -- `NSString campaign` the campaign grouping level of the current install. -- `NSString adgroup` the ad group grouping level of the current install. -- `NSString creative` the creative grouping level of the current install. -- `NSString clickLabel` the click label of the current install. -- `NSString adid` the unique device identifier provided by adjust. +- `NSString trackerToken` the tracker token of the current attribution. +- `NSString trackerName` the tracker name of the current attribution. +- `NSString network` the network grouping level of the current attribution. +- `NSString campaign` the campaign grouping level of the current attribution. +- `NSString adgroup` the ad group grouping level of the current attribution. +- `NSString creative` the creative grouping level of the current attribution. +- `NSString clickLabel` the click label of the current attribution. +- `NSString adid` the unique device identifier provided by attribution. If any value is unavailable, it will default to `nil`. From 1df6fa6e714937a452944ddc6116bde1f1382c56 Mon Sep 17 00:00:00 2001 From: uerceg Date: Sun, 3 Dec 2017 19:41:18 +0100 Subject: [PATCH 68/74] App secret variable rename --- Adjust/ADJConfig.h | 2 +- Adjust/ADJConfig.m | 4 ++-- Adjust/ADJPackageBuilder.m | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index 066da6d4c..c44c369e9 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -163,7 +163,7 @@ /** * @brief Adjust app secret. */ -@property (nonatomic, copy, readonly, nullable) NSString *appSecretS; +@property (nonatomic, copy, readonly, nullable) NSString *appSecret; /** * @brief Adjust set app secret. diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index 0a28ab555..592aeb246 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -172,7 +172,7 @@ - (void)setAppSecret:(NSUInteger)secretId info3:(NSUInteger)info3 info4:(NSUInteger)info4 { _secretId = [NSString stringWithFormat:@"%lu", (unsigned long)secretId]; - _appSecretS = [NSString stringWithFormat:@"%lu%lu%lu%lu", + _appSecret = [NSString stringWithFormat:@"%lu%lu%lu%lu", (unsigned long)info1, (unsigned long)info2, (unsigned long)info3, @@ -194,7 +194,7 @@ -(id)copyWithZone:(NSZone *)zone copy.userAgent = [self.userAgent copyWithZone:zone]; copy.isDeviceKnown = self.isDeviceKnown; copy->_secretId = [self.secretId copyWithZone:zone]; - copy->_appSecretS = [self.appSecretS copyWithZone:zone]; + copy->_appSecret = [self.appSecret copyWithZone:zone]; // adjust delegate not copied } diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 060e376a2..3c68bd080 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -263,7 +263,7 @@ - (void)injectConfig:(ADJConfig *)adjustConfig intoParameters:(NSMutableDictiona [ADJPackageBuilder parameters:parameters setBool:adjustConfig.isDeviceKnown forKey:@"device_known"]; } [ADJPackageBuilder parameters:parameters setString:adjustConfig.secretId forKey:@"secret_id"]; - [ADJPackageBuilder parameters:parameters setString:adjustConfig.appSecretS forKey:@"app_secret"]; + [ADJPackageBuilder parameters:parameters setString:adjustConfig.appSecret forKey:@"app_secret"]; } - (void)injectActivityState:(ADJActivityState *)activityState intoParamters:(NSMutableDictionary *)parameters { From bb679381bd52b9fb2ec2d69471c9ede0280ff662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uglje=C5=A1a=20Erceg?= Date: Mon, 11 Dec 2017 17:39:49 +0100 Subject: [PATCH 69/74] Update README.md Update README.md Update README.md --- README.md | 122 +++++++++++++++++++++--------------------------------- 1 file changed, 47 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index d5ced9444..e94191d7f 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,8 @@ If your app is an app which uses web views you would like to use adjust tracking * [Example apps](#example-apps) * [Basic integration](#basic-integration) - * [Get the SDK](#sdk-get) * [Add the SDK to your project](#sdk-add) - * [Add the AdSupport and iAd framework](#sdk-frameworks) + * [Add iOS frameworks](#sdk-frameworks) * [Integrate the SDK into your app](#sdk-integrate) * [Basic setup](#basic-setup) * [Adjust logging](#adjust-logging) @@ -62,21 +61,7 @@ There are example apps inside the [`examples` directory][examples] for [`iOS (Ob We will describe the steps to integrate the adjust SDK into your iOS project. We are going to assume that you are using Xcode for your iOS development. -### Get the SDK - -Download the latest adjust SDK version from our [releases page][releases]. Extract the archive into a directory of your choice. - -### Add the SDK to your project - -You can add the adjust SDK by adding all of it's source files direcly into your app. In Xcode's Project Navigator locate the `Supporting Files` group (or any other group of your choice). From Finder, drag the `Adjust` subdirectory into Xcode's `Supporting Files` group. - -![][drag] - -In the dialog `Choose options for adding these files` make sure to check the checkbox for `Copy items if needed` and select the radio button to `Create groups`. - -![][add] - --- +### Add the SDK to your project If you're using [CocoaPods][cocoapods], you can add the following line to your `Podfile` and continue from [this step](#sdk-integrate): @@ -90,7 +75,7 @@ or: pod 'Adjust', :git => 'https://github.com/adjust/ios_sdk.git', :tag => 'v4.12.0' ``` --- +--- If you're using [Carthage][carthage], you can add following line to your `Cartfile` and continue from [this step](#sdk-frameworks): @@ -99,39 +84,24 @@ If you're using [Carthage][carthage], you can add following line to your `Cartfi github "adjust/ios_sdk" ``` --- +--- You can also choose to integrate the adjust SDK by adding it to your project as a framework. On the [releases page][releases] you can find the following archives: * `AdjustSdkStatic.framework.zip` * `AdjustSdkDynamic.framework.zip` -* `AdjustSdkDynamicWithoutSimulator.framework.zip` * `AdjustSdkTv.framework.zip` Since the release of iOS 8, Apple has introduced dynamic frameworks (also known as embedded frameworks). If your app is targeting iOS 8 or higher, you can use the adjust SDK dynamic framework. Choose which framework you want to use – static or dynamic – and add it to your project. -If you want to use dynamic framework without architectures used for simulator (`x86_64` and `i386`), you can use SDK inside `AdjustSdkDynamicWithoutSimulator.framework.zip` archive. - If you are having `tvOS` app, you can use the adjust SDK with it as well with usage of our tvOS framework which you can extract from `AdjustSdkTv.framework.zip` archive. -If you have chosen one of these ways to integrate the adjust SDK, you may continue from [this step](#sdk-frameworks). If you want to add the adjust SDK by adding its source files to your project, you can continue from [this step](#sdk-get). - -### Add the AdSupport and iAd framework +### Add iOS frameworks -Select your project in the Project Navigator. In the left hand side of the main view, select your target. In the tab `Build Phases`, expand the group `Link Binary with Libraries`. On the bottom of that section click on the `+` button. Select the `AdSupport.framework` and click the `Add` button. Unless you are using tvOS, repeat the same steps to add the `iAd.framework`. Change the `Status` of both frameworks to `Optional`. - -![][framework] +Select your project in the Project Navigator. In the left hand side of the main view, select your target. In the tab `Build Phases`, expand the group `Link Binary with Libraries`. On the bottom of that section click on the `+` button. Select the `AdSupport.framework` and click the `Add` button. Unless you are using tvOS, repeat the same steps to add the `iAd.framework` and `CoreTelephony.framework`. Change the `Status` of frameworks to `Optional`. ### Integrate the SDK into your app -If you added the adjust SDK from the source, you should use the following import statement: - -```objc -#import "Adjust.h" -``` - --- - If you added the adjust SDK via a Pod repository, you should use one of the following import statements: ```objc @@ -144,7 +114,7 @@ or #import ``` --- +--- If you added the adjust SDK as a static/dynamic framework or via Carthage, you should use the following import statement: @@ -152,7 +122,7 @@ If you added the adjust SDK as a static/dynamic framework or via Carthage, you s #import ``` --- +--- If you are are using the adjust SDK with your tvOS app, you should use the following import statement: @@ -162,7 +132,7 @@ If you are are using the adjust SDK with your tvOS app, you should use the follo Next, we'll set up basic session tracking. -### Basic setup +### Basic setup In the Project Navigator, open the source file of your application delegate. Add the `import` statement at the top of the file, then add the following call to `Adjust` in the `didFinishLaunching` or `didFinishLaunchingWithOptions` method of your app delegate: @@ -199,7 +169,7 @@ NSString *environment = ADJEnvironmentProduction; We use this environment to distinguish between real traffic and test traffic from test devices. It is very important that you keep this value meaningful at all times! This is especially important if you are tracking revenue. -### Adjust logging +### Adjust logging You can increase or decrease the amount of logs that you see during testing by calling `setLogLevel:` on your `ADJConfig` instance with one of the following parameters: @@ -232,7 +202,7 @@ ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken [Adjust appDidLaunch:adjustConfig]; ``` -### Build your app +### Build your app Build and run your app. If the build succeeds, you should carefully read the SDK logs in the console. After the app launches for the first time, you should see the info log `Install tracked`. @@ -242,7 +212,7 @@ Build and run your app. If the build succeeds, you should carefully read the SDK Once you integrate the adjust SDK into your project, you can take advantage of the following features. -### Event tracking +### Event tracking You can use adjust to track events. Lets say you want to track every tap on a particular button. You would create a new event token in your [dashboard], which has an associated event token - looking something like `abc123`. In your button's `buttonDown` method you would then add the following lines to track the tap: @@ -255,7 +225,7 @@ When tapping the button you should now see `Event tracked` in the logs. The event instance can be used to configure the event further before tracking it: -### Revenue tracking +### Revenue tracking If your users can generate revenue by tapping on advertisements or making in-app purchases you can track those revenues with events. Lets say a tap is worth one Euro cent. You could then track the revenue event like this: @@ -298,11 +268,11 @@ If you want to track in-app purchases, please make sure to call `trackEvent` aft } ``` -### In-App Purchase verification +### In-App Purchase verification If you want to check the validity of In-App Purchases made in your app using Purchase Verification, adjust's server side receipt verification tool, then check out our iOS purchase SDK and read more about it [here][ios-purchase-verification]. -### Callback parameters +### Callback parameters You can register a callback URL for your events in your [dashboard]. We will send a GET request to that URL whenever the event is tracked. You can add callback parameters to that event by calling `addCallbackParameter` to the event before tracking it. We will then append these parameters to your callback URL. @@ -325,7 +295,7 @@ It should be mentioned that we support a variety of placeholders like `{idfa}` t You can read more about using URL callbacks, including a full list of available values, in our [callbacks guide][callbacks-guide]. -### Partner parameters +### Partner parameters You can also add parameters to be transmitted to network partners, which have been activated in youradjust dashboard. @@ -342,13 +312,13 @@ ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"]; You can read more about special partners and these integrations in our [guide to special partners][special-partners]. -### Session parameters +### Session parameters Some parameters are saved to be sent in every event and session of the adjust SDK. Once you have added any of these parameters, you don't need to add them every time, since they will be saved locally. If you add the same parameter twice, there will be no effect. If you want to send session parameters with the initial install event, they must be called before the Adjust SDK launches via `[Adjust appDidLaunch:]`. If you need to send them with an install, but can only obtain the needed values after launch, it's possible to [delay](#delay-start) the first launch of the adjust SDK to allow this behavior. -### Session callback parameters +### Session callback parameters The same callback parameters that are registered for [events](#callback-parameters) can be also saved to be sent in every event or session of the adjust SDK. @@ -372,7 +342,7 @@ If you wish to remove all key and values from the session callback parameters, y [Adjust resetSessionCallbackParameters]; ``` -### Session partner parameters +### Session partner parameters In the same way that there is [session callback parameters](#session-callback-parameters) that are sent every in event or session of the adjust SDK, there is also session partner parameters. @@ -398,7 +368,7 @@ If you wish to remove all key and values from the session partner parameters, yo [Adjust resetSessionPartnerParameters]; ``` -### Delay start +### Delay start Delaying the start of the adjust SDK allows your app some time to obtain session parameters, such as unique identifiers, to be send on install. @@ -412,7 +382,7 @@ In this case this will make the adjust SDK not send the initial install session **The maximum delay start time of the adjust SDK is 10 seconds**. -### Attribution callback +### Attribution callback You can register a delegate callback to be notified of tracker attribution changes. Due to the different sources considered for attribution, this information can not be provided synchronously. Follow these steps to implement the optional delegate protocol in your app delegate: @@ -452,7 +422,7 @@ The delegate function will be called after the SDK receives the final attributio If any value is unavailable, it will default to `nil`. -### Event and session callbacks +### Event and session callbacks You can register a delegate callback to be notified of successful and failed tracked events and/or sessions. The same optional protocol `AdjustDelegate` used for the [attribution callback](#attribution-callback) is used. @@ -501,7 +471,7 @@ And both event and session failed objects also contain: - `BOOL willRetry` indicates that there will be an attempt to resend the package at a later time. -### Disable tracking +### Disable tracking You can disable the adjust SDK from tracking any activities of the current device by calling `setEnabled` with parameter `NO`. **This setting is remembered between sessions**, but it can only be activated after the first session. @@ -511,7 +481,7 @@ You can disable the adjust SDK from tracking any activities of the current devic You can check if the adjust SDK is currently enabled by calling the function `isEnabled`. It is always possible to activate the adjust SDK by invoking `setEnabled` with the enabled parameter as `YES`. -### Offline mode +### Offline mode You can put the adjust SDK in offline mode to suspend transmission to our servers while retaining tracked data to be sent later. While in offline mode, all information is saved in a file, so be careful not to trigger too many events while in offline mode. @@ -525,7 +495,7 @@ Conversely, you can deactivate offline mode by calling `setOfflineMode` with `NO Unlike disabling tracking, this setting is **not remembered** bettween sessions. This means that the SDK is in online mode whenever it is started, even if the app was terminated in offline mode. -### Event buffering +### Event buffering If your app makes heavy use of event tracking, you might want to delay some HTTP requests in order to send them in one batch every minute. You can enable event buffering with your `ADJConfig` instance: @@ -535,7 +505,7 @@ If your app makes heavy use of event tracking, you might want to delay some HTTP If nothing is set, event buffering is **disabled by default**. -### Background tracking +### Background tracking The default behaviour of the adjust SDK is to pause sending HTTP requests while the app is in the background. You can change this in your `AdjustConfig` instance: @@ -545,11 +515,11 @@ The default behaviour of the adjust SDK is to pause sending HTTP requests while If nothing is set, sending in background is **disabled by default**. -### Device IDs +### Device IDs The adjust SDK offers you possibility to obtain some of the device identifiers. -### iOS Advertising Identifier +### iOS Advertising Identifier Certain services (such as Google Analytics) require you to coordinate device and client IDs in order to prevent duplicate reporting. @@ -579,7 +549,7 @@ ADJAttribution *attribution = [Adjust attribution]; **Note**: Information about current attribution is available after app installation has been tracked by the adjust backend and attribution callback has been initially triggered. From that moment on, adjust SDK has information about your user's attribution and you can access it with this method. So, **it is not possible** to access user's attribution value before the SDK has been initialised and attribution callback has been initially triggered. -### Push token +### Push token To send us the push notification token, add the following call to `Adjust` in the `didRegisterForRemoteNotificationsWithDeviceToken` of your app delegate: @@ -589,7 +559,9 @@ To send us the push notification token, add the following call to `Adjust` in th } ``` -### Pre-installed trackers +Push token is needed for uninstall tracking feature. + +### Pre-installed trackers If you want to use the Adjust SDK to recognize users that found your app pre-installed on their device, follow these steps. @@ -612,15 +584,15 @@ If you want to use the Adjust SDK to recognize users that found your app pre-ins Default tracker: 'abc123' ``` -### Deep linking +### Deep linking If you are using the adjust tracker URL with an option to deep link into your app from the URL, there is the possibility to get info about the deep link URL and its content. Hitting the URL can happen when the user has your app already installed (standard deep linking scenario) or if they don't have the app on their device (deferred deep linking scenario). Both of these scenarios are supported by the adjust SDK and in both cases the deep link URL will be provided to you after you app has been started after hitting the tracker URL. In order to use this feature in your app, you need to set it up properly. -### Standard deep linking scenario +### Standard deep linking scenario If your user already has the app installed and hits the tracker URL with deep link information in it, your application will be opened and the content of the deep link will be sent to your app so that you can parse it and decide what to do next. With introduction of iOS 9, Apple has changed the way how deep linking should be handled in the app. Depending on which scenario you want to use for your app (or if you want to use them both to support wide range of devices), you need to set up your app to handle one or both of the following scenarios. -### Deep linking on iOS 8 and earlier +### Deep linking on iOS 8 and earlier Deep linking on iOS 8 and earlier devices is being done with usage of a custom URL scheme setting. You need to pick a custom URL scheme name which your app will be in charge for opening. This scheme name will also be used in the adjust tracker URL as part of the `deep_link` parameter. In order to set this in your app, open your `Info.plist` file and add new `URL types` row to it. In there, as `URL identifier` write you app's bundle ID and under `URL schemes` add scheme name(s) which you want your app to handle. In the example below, we have chosen that our app should handle the `adjustExample` scheme name. @@ -642,7 +614,7 @@ After this has been set up, your app will be opened after you click the adjust t With this setup, you have successfully set up deep linking handling for iOS devices with iOS 8 and earlier versions. -### Deep linking on iOS 9 and later +### Deep linking on iOS 9 and later In order to set deep linking support for iOS 9 and later devices, you need to enable your app to handle Apple universal links. To find out more about universal links and how their setup looks like, you can check [here][universal-links]. @@ -692,7 +664,7 @@ We provide a helper function that allows you to convert a universal link to an o } ``` -### Deferred deep linking scenario +### Deferred deep linking scenario You can register a delegate callback to be notified before a deferred deep link is opened and decide if the adjust SDK will try to open it. The same optional protocol `AdjustDelegate` used for the [attribution callback](#attribution-callback) and for [event and session callbacks](#event-session-callbacks) is used. @@ -713,7 +685,7 @@ The callback function will be called after the SDK receives a deffered deep link If this callback is not implemented, **the adjust SDK will always try to open the deep link by default**. -### Reattribution via deep links +### Reattribution via deep links Adjust enables you to run re-engagement campaigns with usage of deep links. For more information on how to do that, please check our [official docs][reattribution-with-deeplinks]. @@ -753,9 +725,9 @@ The call to `appWillOpenUrl` should be done like this to support deep linking re } ``` -## Troubleshooting +## Troubleshooting -### Issues with delayed SDK initialisation +### Issues with delayed SDK initialisation As described in the [basic setup step](#basic-setup), we strongly advise you to initialise the adjust SDK in the `didFinishLaunching` or `didFinishLaunchingWithOptions` method of your app delegate. It is imperative to initialise the adjust SDK in as soon as possible so that you can use all the features of the SDK. @@ -809,17 +781,17 @@ For example: For all these reasons, please follow the instructions in this document and initialise the adjust SDK in the `didFinishLaunching` or `didFinishLaunchingWithOptions` method of your app delegate. -### I'm seeing "Adjust requires ARC" error +### I'm seeing "Adjust requires ARC" error If your build failed with the error `Adjust requires ARC`, it looks like your project is not using [ARC][arc]. In that case we recommend [transitioning your project][transition] so that it does use ARC. If you don't want to use ARC, you have to enable ARC for all source files of adjust in the target's Build Phases: Expand the `Compile Sources` group, select all adjust files and change the `Compiler Flags` to `-fobjc-arc` (Select all and press the `Return` key to change all at once). -### I'm seeing "[UIDevice adjTrackingEnabled]: unrecognized selector sent to instance" error +### I'm seeing "[UIDevice adjTrackingEnabled]: unrecognized selector sent to instance" error This error can occur when you are adding the adjust SDK framework to your app. The adjust SDK contains `categories` among it's source files and for this reason, if you have chosen this SDK integration approach, you need to add `-ObjC` flags to `Other Linker Flags` in your Xcode project settings. Adding this flag will fix this error. -### I'm seeing the "Session failed (Ignoring too frequent session.)" error +### I'm seeing the "Session failed (Ignoring too frequent session.)" error This error typically occurs when testing installs. Uninstalling and reinstalling the app is not enough to trigger a new install. The servers will determine that the SDK has lost its locally aggregated session data and ignore the erroneous message, given the information available on the servers about the device. @@ -843,7 +815,7 @@ http://app.adjust.com/forget_device?app_token={yourAppToken}&idfa={idfaValue} When the device is forgotten, the link just returns `Forgot device`. If the device was already forgotten or the values were incorrect, the link returns `Device not found`. -### I'm not seeing "Install tracked" in the logs +### I'm not seeing "Install tracked" in the logs If you want to simulate the installation scenario of your app on your test device, it is not enough if you just re-run the app from the Xcode on your test device. Re-running the app from the Xcode doesn't cause app data to be wiped out and all internal files that our SDK is keeping inside your app will still be there, so upon re-run, our SDK will see those files and think of your app was already installed (and that SDK was already launched in it) but just opened for another time rather than being opened for the first time. @@ -853,7 +825,7 @@ In order to run the app installation scenario, you need to do following: * Forget your test device from the adjust backend like explained in the issue [above](#forget-device) * Run your app from the Xcode on the test device and you will see log message "Install tracked" -### I'm seeing the "Unattributable SDK click ignored" message +### I'm seeing the "Unattributable SDK click ignored" message You may notice this message while testing your app in `sandbox` envoronment. It is related to some changes Apple introduced in `iAd.framework` version 3. With this, a user can be directed to your app from a click on iAd banner and this will cause our SDK to send an `sdk_click` package to the adjust backend informing it about the content of the clicked URL. For some reason, Apple decided that if the app was opened without clicking on iAd banner, they will artificially generate an iAd banner URL click with some random values. Our SDK won't be able to distinguish if the iAd banner click was genuine or artificially generated and will send an `sdk_click` package regardless to the adjust backend. If you have your log level set to `verbose` level, you will see this `sdk_click` package looking something like this: @@ -881,7 +853,7 @@ If for some reason this `sdk_click` would be accepted, it would mean that a user So, this message doesn't indicate any issue with your SDK integration but it's simply informing you that our backend has ignored this artificially created `sdk_click` which could have lead to your user being wrongly attributed/reattributed. -### I'm seeing incorrect revenue data in the adjust dashboard +### I'm seeing incorrect revenue data in the adjust dashboard The adjust SDK tracks what you tell it to track. If you are attaching revenue to your event, the number you write as an amount is the only amount which will reach the adjust backend and be displayed in the dashboard. Our SDK does not manipulate your amount value, nor does our backend. So, if you see wrong amount being tracked, it's because our SDK was told to track that amount. @@ -968,7 +940,7 @@ If you are seing any value in the dashboard other than what you expected to be t [associated-domains-applinks]: https://raw.github.com/adjust/sdks/master/Resources/ios/associated-domains-applinks.png [universal-links-dashboard-values]: https://raw.github.com/adjust/sdks/master/Resources/ios/universal-links-dashboard-values5.png -## License +## License The adjust SDK is licensed under the MIT License. From e2dc5ec34c96858f85f47ff712e981a14d761be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uglje=C5=A1a=20Erceg?= Date: Mon, 11 Dec 2017 17:54:58 +0100 Subject: [PATCH 70/74] Update CHANGELOG.md --- CHANGELOG.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 251eeec34..ec436d09a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ +### Version 4.12.0 (12th December 2017) +#### Added +- Added reading of MCC parameter. +- Added reading of MNC parameter. +- Added reading of network type. +- Added reading of connectivity type. + +#### Changed +- Improved push token handling. +- Migrated Adjust internal files from `Documents` to `Application Support` directory. +- Deprecated `iAd v2` handling. +- Updated `WebViewJavascriptBridge` to `6.0.2`. +- Updated instructions for iOS SDK web bridge integration. + +#### Fixed +- Fixed data race in `ADJAttributionHandler` (https://github.com/adjust/ios_sdk/issues/303) (thanks to @mindbrix). +- Fixed potential deadlock in shared access to `UIPasteboard` with Facebook SDK (https://github.com/adjust/ios_sdk/pull/310) (thanks to @sanekgusev). + +--- + ### Version 4.11.5 (21st September 2017) #### Fixed - Fixed `WKWebViewJavascriptBridge` bug (https://github.com/marcuswestin/WebViewJavascriptBridge/issues/267). From e276ad65a2ee00b2d3e43799979004f59694eacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uglje=C5=A1a=20Erceg?= Date: Mon, 11 Dec 2017 20:22:06 +0100 Subject: [PATCH 71/74] Update CHANGELOG.md --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec436d09a..66a0028ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ ### Version 4.12.0 (12th December 2017) #### Added -- Added reading of MCC parameter. -- Added reading of MNC parameter. +- Added reading of MCC. +- Added reading of MNC. - Added reading of network type. - Added reading of connectivity type. +- Added usage of app secret in authorization header. #### Changed - Improved push token handling. From 160ab21dc687d767ead1d10b6a4624ead6238e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uglje=C5=A1a=20Erceg?= Date: Tue, 12 Dec 2017 13:12:59 +0100 Subject: [PATCH 72/74] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e94191d7f..6cda82ff2 100644 --- a/README.md +++ b/README.md @@ -559,7 +559,7 @@ To send us the push notification token, add the following call to `Adjust` in th } ``` -Push token is needed for uninstall tracking feature. +Push token is used for Audience Builder and client callbacks and needed for the upcoming uninstall tracking feature. ### Pre-installed trackers From 43f2efd6a4d02c4f7b0e88ca4190eb79aac44573 Mon Sep 17 00:00:00 2001 From: easteracrobat Date: Tue, 12 Dec 2017 18:45:51 +0100 Subject: [PATCH 73/74] proofing --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6cda82ff2..5dd9f2d9a 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,13 @@ If you are having `tvOS` app, you can use the adjust SDK with it as well with us ### Add iOS frameworks -Select your project in the Project Navigator. In the left hand side of the main view, select your target. In the tab `Build Phases`, expand the group `Link Binary with Libraries`. On the bottom of that section click on the `+` button. Select the `AdSupport.framework` and click the `Add` button. Unless you are using tvOS, repeat the same steps to add the `iAd.framework` and `CoreTelephony.framework`. Change the `Status` of frameworks to `Optional`. +1. Select your project in the Project Navigator +2. In the left-hand side of the main view, select your target +3. In the `Build Phases` tab, expand the `Link Binary with Libraries` group +4. At the bottom of that section, select the `+` button +5. Select the `AdSupport.framework`, then the `Add` button +6. Unless you are using tvOS, repeat the same steps to add the `iAd.framework` and `CoreTelephony.framework` +7. Change the `Status` of the frameworks to `Optional`. ### Integrate the SDK into your app @@ -559,7 +565,7 @@ To send us the push notification token, add the following call to `Adjust` in th } ``` -Push token is used for Audience Builder and client callbacks and needed for the upcoming uninstall tracking feature. +Push tokens are used for the Adjust Audience Builder and client callbacks, and are required for the upcoming uninstall tracking feature. ### Pre-installed trackers From 7f5f12bbc9e1226a18fd92129642ee874f7d0617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uglje=C5=A1a=20Erceg?= Date: Wed, 13 Dec 2017 07:17:16 +0100 Subject: [PATCH 74/74] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66a0028ca..dddca05b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -### Version 4.12.0 (12th December 2017) +### Version 4.12.0 (13th December 2017) #### Added - Added reading of MCC. - Added reading of MNC.