2424#import " ADJUrlStrategy.h"
2525#import " ADJSKAdNetwork.h"
2626
27- NSString * const ADJiAdPackageKey = @" iad3" ;
2827NSString * const ADJAdServicesPackageKey = @" apple_ads" ;
2928
3029typedef void (^activityHandlerBlockI)(ADJActivityHandler * activityHandler);
4443static NSTimeInterval kBackgroundTimerInterval ;
4544static double kSessionInterval ;
4645static double kSubSessionInterval ;
47- static const int kiAdRetriesCount = 3 ;
4846static const int kAdServicesdRetriesCount = 1 ;
4947
5048@implementation ADJInternalState
@@ -86,7 +84,6 @@ @interface ADJActivityHandler()
8684@property (nonatomic , strong ) ADJActivityState *activityState;
8785@property (nonatomic , strong ) ADJTimerCycle *foregroundTimer;
8886@property (nonatomic , strong ) ADJTimerOnce *backgroundTimer;
89- @property (nonatomic , assign ) NSInteger iAdRetriesLeft;
9087@property (nonatomic , assign ) NSInteger adServicesRetriesLeft;
9188@property (nonatomic , strong ) ADJInternalState *internalState;
9289@property (nonatomic , strong ) ADJPackageParams *packageParams;
@@ -108,19 +105,6 @@ - (void)prepareDeeplinkI:(ADJActivityHandler *_Nullable)selfI
108105
109106@end
110107
111- // copy from ADClientError
112- typedef NS_ENUM (NSInteger , AdjADClientError) {
113- AdjADClientErrorUnknown = 0 ,
114- AdjADClientErrorTrackingRestrictedOrDenied = 1 ,
115- AdjADClientErrorMissingData = 2 ,
116- AdjADClientErrorCorruptResponse = 3 ,
117- AdjADClientErrorRequestClientError = 4 ,
118- AdjADClientErrorRequestServerError = 5 ,
119- AdjADClientErrorRequestNetworkError = 6 ,
120- AdjADClientErrorUnsupportedPlatform = 7 ,
121- AdjCustomErrorTimeout = 100 ,
122- };
123-
124108#pragma mark -
125109@implementation ADJActivityHandler
126110
@@ -147,9 +131,6 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig
147131 if (adjustConfig.allowIdfaReading == NO ) {
148132 [ADJAdjustFactory.logger warn: @" IDFA reading has been switched off" ];
149133 }
150- if (adjustConfig.allowiAdInfoReading == NO ) {
151- [ADJAdjustFactory.logger warn: @" iAd info reading has been switched off" ];
152- }
153134 if (adjustConfig.allowAdServicesInfoReading == NO ) {
154135 [ADJAdjustFactory.logger warn: @" AdServices info reading has been switched off" ];
155136 }
@@ -217,7 +198,6 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig
217198 // does not have the session response by default
218199 self.internalState .sessionResponseProcessed = NO ;
219200
220- self.iAdRetriesLeft = kiAdRetriesCount;
221201 self.adServicesRetriesLeft = kAdServicesdRetriesCount ;
222202
223203 self.trackingStatusManager = [[ADJTrackingStatusManager alloc ] initWithActivityHandler: self ];
@@ -438,154 +418,6 @@ - (void)setAdServicesAttributionToken:(NSString *)token
438418 }
439419}
440420
441- - (void )setAttributionDetails : (NSDictionary *)attributionDetails
442- error : (NSError *)error
443- {
444- if (![ADJUtil isNull: error]) {
445- [self .logger warn: @" Unable to read iAd details" ];
446-
447- if (self.iAdRetriesLeft < 0 ) {
448- [self .logger warn: @" Number of retries to get iAd information surpassed" ];
449- return ;
450- }
451-
452- switch (error.code ) {
453- // if first request was unsuccessful and ended up with one of the following error codes:
454- // apply following retry logic:
455- // - 1st retry after 5 seconds
456- // - 2nd retry after 2 seconds
457- // - 3rd retry after 2 seconds
458- case AdjADClientErrorUnknown:
459- case AdjADClientErrorMissingData:
460- case AdjADClientErrorCorruptResponse:
461- case AdjADClientErrorRequestClientError:
462- case AdjADClientErrorRequestServerError:
463- case AdjADClientErrorRequestNetworkError:
464- case AdjCustomErrorTimeout: {
465-
466- [self saveiAdErrorCode: error.code];
467-
468- int64_t iAdRetryDelay = 0 ;
469- switch (self.iAdRetriesLeft ) {
470- case 2 :
471- iAdRetryDelay = 5 * NSEC_PER_SEC;
472- break ;
473- default :
474- iAdRetryDelay = 2 * NSEC_PER_SEC;
475- break ;
476- }
477- self.iAdRetriesLeft = self.iAdRetriesLeft - 1 ;
478- dispatch_time_t retryTime = dispatch_time (DISPATCH_TIME_NOW, iAdRetryDelay);
479- dispatch_after (retryTime, dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
480- [self checkForiAdI: self ];
481- });
482- return ;
483- }
484- case AdjADClientErrorTrackingRestrictedOrDenied:
485- case AdjADClientErrorUnsupportedPlatform:
486- return ;
487- default :
488- return ;
489- }
490- }
491-
492- // check if it's a valid attribution details
493- if (![ADJUtil checkAttributionDetails: attributionDetails]) {
494- return ;
495- }
496-
497- // send immediately if there is no previous attribution details
498- if (self.activityState == nil ||
499- self.activityState .attributionDetails == nil )
500- {
501- // send immediately
502- [self sendIad3ClickPackage: self attributionDetails: attributionDetails];
503- // save in the background queue
504- [ADJUtil launchInQueue: self .internalQueue
505- selfInject: self
506- block: ^(ADJActivityHandler * selfI) {
507- [selfI saveAttributionDetailsI: selfI
508- attributionDetails: attributionDetails];
509-
510- }];
511- return ;
512- }
513-
514- // check if new updates previous written one
515- [ADJUtil launchInQueue: self .internalQueue
516- selfInject: self
517- block: ^(ADJActivityHandler * selfI) {
518- if ([attributionDetails isEqualToDictionary: selfI.activityState.attributionDetails]) {
519- return ;
520- }
521-
522- [selfI sendIad3ClickPackage: selfI attributionDetails: attributionDetails];
523-
524- // save new iAd details
525- [selfI saveAttributionDetailsI: selfI
526- attributionDetails: attributionDetails];
527- }];
528- }
529-
530- - (void )saveiAdErrorCode : (NSInteger )code {
531- NSString *codeKey;
532- switch (code) {
533- case AdjADClientErrorUnknown:
534- codeKey = @" AdjADClientErrorUnknown" ;
535- break ;
536- case AdjADClientErrorMissingData:
537- codeKey = @" AdjADClientErrorMissingData" ;
538- break ;
539- case AdjADClientErrorCorruptResponse:
540- codeKey = @" AdjADClientErrorCorruptResponse" ;
541- break ;
542- case AdjCustomErrorTimeout:
543- codeKey = @" AdjCustomErrorTimeout" ;
544- break ;
545- default :
546- codeKey = @" " ;
547- break ;
548- }
549-
550- if (![codeKey isEqualToString: @" " ]) {
551- [ADJUserDefaults saveiAdErrorKey: codeKey];
552- }
553- }
554-
555- - (void )sendIad3ClickPackage : (ADJActivityHandler *)selfI
556- attributionDetails : (NSDictionary *)attributionDetails
557- {
558- if (![selfI isEnabledI: selfI]) {
559- return ;
560- }
561-
562- if (ADJAdjustFactory.iAdFrameworkEnabled == NO ) {
563- [self .logger verbose: @" Sending iAd details to server suppressed." ];
564- return ;
565- }
566-
567- double now = [NSDate .date timeIntervalSince1970 ];
568- if (selfI.activityState != nil ) {
569- [ADJUtil launchSynchronisedWithObject: [ADJActivityState class ]
570- block: ^{
571- double lastInterval = now - selfI.activityState .lastActivity ;
572- selfI.activityState .lastInterval = lastInterval;
573- }];
574- }
575- ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc ]
576- initWithPackageParams: selfI.packageParams
577- activityState: selfI.activityState
578- config: selfI.adjustConfig
579- sessionParameters: self .sessionParameters
580- trackingStatusManager: self .trackingStatusManager
581- createdAt: now];
582-
583- clickBuilder.attributionDetails = attributionDetails;
584-
585- ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage: ADJiAdPackageKey];
586- [selfI.sdkClickHandler sendSdkClick: clickPackage];
587- }
588-
589421- (void )sendAdServicesClickPackage : (ADJActivityHandler *)selfI
590422 token : (NSString *)token
591423 errorCodeNumber : (NSNumber *)errorCodeNumber
@@ -622,17 +454,6 @@ - (void)sendAdServicesClickPackage:(ADJActivityHandler *)selfI
622454 [selfI.sdkClickHandler sendSdkClick: clickPackage];
623455}
624456
625- - (void )saveAttributionDetailsI : (ADJActivityHandler *)selfI
626- attributionDetails : (NSDictionary *)attributionDetails
627- {
628- // save new iAd details
629- [ADJUtil launchSynchronisedWithObject: [ADJActivityState class ]
630- block: ^{
631- selfI.activityState .attributionDetails = attributionDetails;
632- }];
633- [selfI writeAttributionI: selfI];
634- }
635-
636457- (void )setAskingAttribution : (BOOL )askingAttribution {
637458 [ADJUtil launchInQueue: self .internalQueue
638459 selfInject: self
@@ -1117,9 +938,6 @@ - (void)processSessionI:(ADJActivityHandler *)selfI {
1117938 selfI.activityState .updatePackages = [selfI.internalState itHasToUpdatePackages ];
1118939 }];
1119940
1120- if (selfI.adjustConfig .allowiAdInfoReading == YES ) {
1121- [selfI checkForiAdI: selfI];
1122- }
1123941 if (selfI.adjustConfig .allowAdServicesInfoReading == YES ) {
1124942 [selfI checkForAdServicesAttributionI: selfI];
1125943 }
@@ -1789,9 +1607,6 @@ - (void)setEnabledI:(ADJActivityHandler *)selfI enabled:(BOOL)enabled {
17891607 if (pushToken != nil && ![selfI.activityState.deviceToken isEqualToString: pushToken]) {
17901608 [self setPushToken: pushToken];
17911609 }
1792- if (selfI.adjustConfig .allowiAdInfoReading == YES ) {
1793- [selfI checkForiAdI: selfI];
1794- }
17951610 if (selfI.adjustConfig .allowAdServicesInfoReading == YES ) {
17961611 [selfI checkForAdServicesAttributionI: selfI];
17971612 }
@@ -1804,10 +1619,6 @@ - (void)setEnabledI:(ADJActivityHandler *)selfI enabled:(BOOL)enabled {
18041619 unPausingMessage: @" Resuming handlers due to SDK being enabled" ];
18051620}
18061621
1807- - (void )checkForiAdI : (ADJActivityHandler *)selfI {
1808- [ADJUtil checkForiAd: selfI queue: selfI.internalQueue];
1809- }
1810-
18111622- (BOOL )shouldFetchAdServicesI : (ADJActivityHandler *)selfI {
18121623 if (selfI.adjustConfig .allowAdServicesInfoReading == NO ) {
18131624 return NO ;
0 commit comments