Skip to content

Commit

Permalink
Merge pull request #498 from adjust/v4252
Browse files Browse the repository at this point in the history
Version 4.25.2
  • Loading branch information
uerceg authored Feb 1, 2021
2 parents e188d9c + 770eeeb commit 936af17
Show file tree
Hide file tree
Showing 25 changed files with 162 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Adjust.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "Adjust"
s.version = "4.25.1"
s.version = "4.25.2"
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" => "[email protected]" }
s.source = { :git => "https://github.com/adjust/ios_sdk.git", :tag => "v4.25.1" }
s.source = { :git => "https://github.com/adjust/ios_sdk.git", :tag => "v4.25.2" }
s.ios.deployment_target = '6.0'
s.tvos.deployment_target = '9.0'
s.framework = 'SystemConfiguration'
Expand Down
1 change: 1 addition & 0 deletions Adjust/ADJActivityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,4 @@
@end

extern NSString * const ADJiAdPackageKey;
extern NSString * const ADJAdServicesPackageKey;
46 changes: 27 additions & 19 deletions Adjust/ADJActivityHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,12 @@ - (void)setAdServicesAttributionToken:(NSString *)token
[self checkForAdServicesAttributionI:self];
});
} else {
[self sendAdServicesInfoPackage:self
[self sendAdServicesClickPackage:self
token:nil
errorCodeNumber:[NSNumber numberWithInteger:error.code]];
}
} else {
[self sendAdServicesInfoPackage:self
[self sendAdServicesClickPackage:self
token:token
errorCodeNumber:nil];
}
Expand Down Expand Up @@ -582,9 +582,9 @@ - (void)sendIad3ClickPackage:(ADJActivityHandler *)selfI
[selfI.sdkClickHandler sendSdkClick:clickPackage];
}

- (void)sendAdServicesInfoPackage:(ADJActivityHandler *)selfI
token:(NSString *)token
errorCodeNumber:(NSNumber *)errorCodeNumber
- (void)sendAdServicesClickPackage:(ADJActivityHandler *)selfI
token:(NSString *)token
errorCodeNumber:(NSNumber *)errorCodeNumber
{
if (![selfI isEnabledI:selfI]) {
return;
Expand All @@ -603,19 +603,19 @@ - (void)sendAdServicesInfoPackage:(ADJActivityHandler *)selfI
selfI.activityState.lastInterval = lastInterval;
}];
}
ADJPackageBuilder *infoBuilder = [[ADJPackageBuilder alloc]
ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc]
initWithDeviceInfo:selfI.deviceInfo
activityState:selfI.activityState
config:selfI.adjustConfig
sessionParameters:self.sessionParameters
trackingStatusManager:self.trackingStatusManager
createdAt:now];

ADJActivityPackage *infoPackage =
[infoBuilder buildInfoPackage:ADJAdServicesPackageKey
token:token
errorCodeNumber:errorCodeNumber];
[selfI.packageHandler addPackage:infoPackage];
ADJActivityPackage *clickPackage =
[clickBuilder buildClickPackage:ADJAdServicesPackageKey
token:token
errorCodeNumber:errorCodeNumber];
[selfI.sdkClickHandler sendSdkClick:clickPackage];
}

- (void)saveAttributionDetailsI:(ADJActivityHandler *)selfI
Expand Down Expand Up @@ -793,8 +793,7 @@ - (void)trackAttStatusUpdateI:(ADJActivityHandler *)selfI {
trackingStatusManager:self.trackingStatusManager
createdAt:now];

ADJActivityPackage *infoPackage = [infoBuilder buildInfoPackage:@"att"
token:nil errorCodeNumber:nil];
ADJActivityPackage *infoPackage = [infoBuilder buildInfoPackage:@"att"];
[selfI.packageHandler addPackage:infoPackage];

if (selfI.adjustConfig.eventBufferingEnabled) {
Expand Down Expand Up @@ -1721,10 +1720,21 @@ - (void)checkForiAdI:(ADJActivityHandler *)selfI {
[[UIDevice currentDevice] adjCheckForiAd:selfI queue:selfI.internalQueue];
}

- (BOOL)shouldFetchAdServicesI:(ADJActivityHandler *)selfI {
if (selfI.adjustConfig.allowAdServicesInfoReading == NO) {
return NO;
}

// Fetch if no attribution OR not sent to backend yet
return (selfI.attribution == nil || ![ADJUserDefaults getAdServicesTracked]);
}

- (void)checkForAdServicesAttributionI:(ADJActivityHandler *)selfI {
if (@available(iOS 14.3, tvOS 14.3, *)) {
if (selfI.adjustConfig.allowAdServicesInfoReading == YES && selfI.attribution == nil) {
[[UIDevice currentDevice] adjCheckForAdServicesAttribution:selfI];
if ([selfI shouldFetchAdServicesI:selfI]) {
NSError *error = nil;
NSString *token = [[UIDevice currentDevice] adjFetchAdServicesAttribution:&error];
[selfI setAdServicesAttributionToken:token error:error];
}
}
}
Expand Down Expand Up @@ -1948,8 +1958,7 @@ - (void)setDeviceTokenI:(ADJActivityHandler *)selfI
trackingStatusManager:self.trackingStatusManager
createdAt:now];

ADJActivityPackage *infoPackage = [infoBuilder buildInfoPackage:@"push"
token:nil errorCodeNumber:nil];
ADJActivityPackage *infoPackage = [infoBuilder buildInfoPackage:@"push"];

[selfI.packageHandler addPackage:infoPackage];

Expand Down Expand Up @@ -1998,8 +2007,7 @@ - (void)setPushTokenI:(ADJActivityHandler *)selfI
trackingStatusManager:self.trackingStatusManager
createdAt:now];

ADJActivityPackage *infoPackage = [infoBuilder buildInfoPackage:@"push"
token:nil errorCodeNumber:nil];
ADJActivityPackage *infoPackage = [infoBuilder buildInfoPackage:@"push"];
[selfI.packageHandler addPackage:infoPackage];

// if push token was cached, remove it
Expand Down
2 changes: 1 addition & 1 deletion Adjust/ADJAdditions/UIDevice+ADJAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- (NSString *)adjVendorId;
- (NSString *)adjDeviceId:(ADJDeviceInfo *)deviceInfo;
- (void)adjCheckForiAd:(ADJActivityHandler *)activityHandler queue:(dispatch_queue_t)queue;
- (void)adjCheckForAdServicesAttribution:(ADJActivityHandler *)activityHandler;
- (NSString *)adjFetchAdServicesAttribution:(NSError **)errorPtr;

- (void)requestTrackingAuthorizationWithCompletionHandler:(void (^)(NSUInteger status))completion;

Expand Down
33 changes: 19 additions & 14 deletions Adjust/ADJAdditions/UIDevice+ADJAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -362,27 +362,30 @@ - (void)adjCheckForiAd:(ADJActivityHandler *)activityHandler queue:(dispatch_que
#endif
}

- (void)adjCheckForAdServicesAttribution:(ADJActivityHandler *)activityHandler {
- (NSString *)adjFetchAdServicesAttribution:(NSError **)errorPtr {
id<ADJLogger> logger = [ADJAdjustFactory logger];

// [AAAttribution attributionTokenWithError:...]
Class attributionClass = NSClassFromString(@"AAAttribution");
if (attributionClass == nil) {
[logger warn:@"AdServices framework not found in user's app (AAAttribution not found)"];
[activityHandler setAdServicesAttributionToken:nil
error:[NSError errorWithDomain:@"com.adjust.sdk.adServices"
code:100
userInfo:@{@"Error reason": @"AdServices framework not found"}]];
return;

if (errorPtr) {
*errorPtr = [NSError errorWithDomain:@"com.adjust.sdk.adServices"
code:100
userInfo:@{@"Error reason": @"AdServices framework not found"}];
}
return nil;
}

SEL attributionTokenSelector = NSSelectorFromString(@"attributionTokenWithError:");
if (![attributionClass respondsToSelector:attributionTokenSelector]) {
[activityHandler setAdServicesAttributionToken:nil
error:[NSError errorWithDomain:@"com.adjust.sdk.adServices"
code:100
userInfo:@{@"Error reason": @"AdServices framework not found"}]];
return;
if (errorPtr) {
*errorPtr = [NSError errorWithDomain:@"com.adjust.sdk.adServices"
code:100
userInfo:@{@"Error reason": @"AdServices framework not found"}];
}
return nil;
}

NSMethodSignature *attributionTokenMethodSignature = [attributionClass methodSignatureForSelector:attributionTokenSelector];
Expand All @@ -397,15 +400,17 @@ - (void)adjCheckForAdServicesAttribution:(ADJActivityHandler *)activityHandler {

if (error) {
[logger error:@"Error while retrieving AdServices attribution token: %@", error];
[activityHandler setAdServicesAttributionToken:nil error:error];
return;
if (errorPtr) {
*errorPtr = error;
}
return nil;
}

NSString * __unsafe_unretained tmpToken = nil;
[tokenInvocation getReturnValue:&tmpToken];

NSString *token = tmpToken;
[activityHandler setAdServicesAttributionToken:token error:nil];
return token;
}

- (BOOL)setiAdWithDetails:(ADJActivityHandler *)activityHandler
Expand Down
16 changes: 13 additions & 3 deletions Adjust/ADJPackageBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@
- (ADJActivityPackage *)buildEventPackage:(ADJEvent *)event
isInDelay:(BOOL)isInDelay;

- (ADJActivityPackage *)buildInfoPackage:(NSString *)infoSource
token:(NSString *)token
errorCodeNumber:(NSNumber *)errorCodeNumber;
- (ADJActivityPackage *)buildInfoPackage:(NSString *)infoSource;

- (ADJActivityPackage *)buildAdRevenuePackage:(NSString *)source payload:(NSData *)payload;

- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource;

- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource
token:(NSString *)token
errorCodeNumber:(NSNumber *)errorCodeNumber;

- (ADJActivityPackage *)buildAttributionPackage:(NSString *)initiatedBy;

- (ADJActivityPackage *)buildGdprPackage;
Expand All @@ -75,4 +77,12 @@
setInt:(int)value
forKey:(NSString *)key;

+ (void)parameters:(NSMutableDictionary *)parameters
setDate1970:(double)value
forKey:(NSString *)key;

+ (BOOL)isAdServicesPackage:(ADJActivityPackage *)activityPackage;

@end
// TODO change to ADJ...
extern NSString * const ADJAttributionTokenParameter;
47 changes: 34 additions & 13 deletions Adjust/ADJPackageBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#import "UIDevice+ADJAdditions.h"
#import "ADJUserDefaults.h"

NSString * const ADJAttributionTokenParameter = @"attribution_token";

@interface ADJPackageBuilder()

@property (nonatomic, assign) double createdAt;
Expand Down Expand Up @@ -92,22 +94,9 @@ - (ADJActivityPackage *)buildEventPackage:(ADJEvent *)event
}

- (ADJActivityPackage *)buildInfoPackage:(NSString *)infoSource
token:(NSString *)token
errorCodeNumber:(NSNumber *)errorCodeNumber
{
NSMutableDictionary *parameters = [self getInfoParameters:infoSource];

if (token != nil) {
[ADJPackageBuilder parameters:parameters
setString:token
forKey:@"attribution_token"];
}
if (errorCodeNumber != nil) {
[ADJPackageBuilder parameters:parameters
setInt:errorCodeNumber.intValue
forKey:@"error_code"];
}

ADJActivityPackage *infoPackage = [self defaultActivityPackage];
infoPackage.path = @"/sdk_info";
infoPackage.activityKind = ADJActivityKindInfo;
Expand All @@ -133,7 +122,34 @@ - (ADJActivityPackage *)buildAdRevenuePackage:(NSString *)source payload:(NSData
}

- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource {
return [self buildClickPackage:clickSource extraParameters:nil];
}

- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource
token:(NSString *)token
errorCodeNumber:(NSNumber *)errorCodeNumber {

NSMutableDictionary *parameters = [NSMutableDictionary dictionary];

if (token != nil) {
[ADJPackageBuilder parameters:parameters
setString:token
forKey:ADJAttributionTokenParameter];
}
if (errorCodeNumber != nil) {
[ADJPackageBuilder parameters:parameters
setInt:errorCodeNumber.intValue
forKey:@"error_code"];
}

return [self buildClickPackage:clickSource extraParameters:parameters];
}

- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource extraParameters:(NSDictionary *)extraParameters {
NSMutableDictionary *parameters = [self getClickParameters:clickSource];
if (extraParameters != nil) {
[parameters addEntriesFromDictionary:extraParameters];
}

if ([clickSource isEqualToString:ADJiAdPackageKey]) {
// send iAd errors in the parameters
Expand Down Expand Up @@ -1292,4 +1308,9 @@ + (void)parameters:(NSMutableDictionary *)parameters setData:(NSData *)value for
forKey:key];
}

+ (BOOL)isAdServicesPackage:(ADJActivityPackage *)activityPackage {
NSString *source = activityPackage.parameters[@"source"];
return ([ADJUtil isNotNull:source] && [source isEqualToString:ADJAdServicesPackageKey]);
}

@end
26 changes: 26 additions & 0 deletions Adjust/ADJSdkClickHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#import "ADJSdkClickHandler.h"
#import "ADJBackoffStrategy.h"
#import "ADJUserDefaults.h"
#import "ADJPackageBuilder.h"
#import "UIDevice+ADJAdditions.h"

static const char * const kInternalQueueName = "com.adjust.SdkClickQueue";

Expand Down Expand Up @@ -144,6 +146,23 @@ - (void)sendNextSdkClickI:(ADJSdkClickHandler *)selfI {
[selfI sendNextSdkClick];
return;
}

if ([ADJPackageBuilder isAdServicesPackage:sdkClickPackage]) {
// refresh token
NSString *token = [[UIDevice currentDevice] adjFetchAdServicesAttribution:nil];

if (token != nil && ![sdkClickPackage.parameters[ADJAttributionTokenParameter] isEqualToString:token]) {
// update token
[ADJPackageBuilder parameters:sdkClickPackage.parameters
setString:token
forKey:ADJAttributionTokenParameter];

// update created_at
[ADJPackageBuilder parameters:sdkClickPackage.parameters
setDate1970:[NSDate.date timeIntervalSince1970]
forKey:@"created_at"];
}
}

dispatch_block_t work = ^{
NSDictionary *sendingParameters = @{
Expand Down Expand Up @@ -194,6 +213,13 @@ - (void)responseCallback:(ADJResponseData *)responseData {
if ([responseData.sdkClickPackage.parameters.allValues containsObject:ADJiAdPackageKey]) {
// received iAd click package response, clear the errors from UserDefaults
[ADJUserDefaults cleariAdErrors];
[self.logger info:@"Received iAd click response"];
}

if ([ADJPackageBuilder isAdServicesPackage:responseData.sdkClickPackage]) {
// set as tracked
[ADJUserDefaults setAdServicesTracked];
[self.logger info:@"Received Apple Ads click response"];
}

[self.activityHandler finishedTracking:responseData];
Expand Down
3 changes: 3 additions & 0 deletions Adjust/ADJUserDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@
+ (NSDictionary<NSString *, NSNumber *> *)getiAdErrors;
+ (void)cleariAdErrors;

+ (void)setAdServicesTracked;
+ (BOOL)getAdServicesTracked;

@end
11 changes: 11 additions & 0 deletions Adjust/ADJUserDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
static NSString * const PREFS_KEY_DEEPLINK_CLICK_TIME = @"adj_deeplink_click_time";
static NSString * const PREFS_KEY_DISABLE_THIRD_PARTY_SHARING = @"adj_disable_third_party_sharing";
static NSString * const PREFS_KEY_IAD_ERRORS = @"adj_iad_errors";
static NSString * const PREFS_KEY_ADSERVICES_TRACKED = @"adj_adservices_tracked";

@implementation ADJUserDefaults

Expand Down Expand Up @@ -120,6 +121,14 @@ + (void)cleariAdErrors {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_IAD_ERRORS];
}

+ (void)setAdServicesTracked {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:PREFS_KEY_ADSERVICES_TRACKED];
}

+ (BOOL)getAdServicesTracked {
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_KEY_ADSERVICES_TRACKED];
}

+ (void)clearAdjustStuff {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_PUSH_TOKEN_DATA];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_PUSH_TOKEN_STRING];
Expand All @@ -128,6 +137,8 @@ + (void)clearAdjustStuff {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_DEEPLINK_URL];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_DEEPLINK_CLICK_TIME];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_DISABLE_THIRD_PARTY_SHARING];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_IAD_ERRORS];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_KEY_ADSERVICES_TRACKED];
}

@end
Loading

0 comments on commit 936af17

Please sign in to comment.