From 43c9b5ebe95c915e56c47e4091f3690e8b358472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Mathe=CC=81?= Date: Tue, 17 Jul 2018 13:29:31 +0200 Subject: [PATCH 1/3] App secret support --- Pod/Classes/SEGAdjustIntegration.h | 2 +- Pod/Classes/SEGAdjustIntegration.m | 17 ++++++++++++++++- Pod/Classes/SEGAdjustIntegrationFactory.h | 1 + Pod/Classes/SEGAdjustIntegrationFactory.m | 17 ++++++++++++----- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Pod/Classes/SEGAdjustIntegration.h b/Pod/Classes/SEGAdjustIntegration.h index 28aebab..c375c09 100644 --- a/Pod/Classes/SEGAdjustIntegration.h +++ b/Pod/Classes/SEGAdjustIntegration.h @@ -8,6 +8,6 @@ @property (nonatomic, strong) NSDictionary *settings; @property (nonatomic, strong) SEGAnalytics *analytics; -- (instancetype)initWithSettings:(NSDictionary *)settings withAnalytics:(SEGAnalytics *)analytics; +- (instancetype)initWithAppSecret:(nullable NSArray *)secret settings:(NSDictionary *)settings analytics:(SEGAnalytics *)analytics; @end diff --git a/Pod/Classes/SEGAdjustIntegration.m b/Pod/Classes/SEGAdjustIntegration.m index 6301600..ede9d91 100644 --- a/Pod/Classes/SEGAdjustIntegration.m +++ b/Pod/Classes/SEGAdjustIntegration.m @@ -6,7 +6,7 @@ @implementation SEGAdjustIntegration #pragma mark - Initialization -- (instancetype)initWithSettings:(NSDictionary *)settings withAnalytics:(SEGAnalytics *)analytics +- (instancetype)initWithAppSecret:(nullable NSArray *)secret settings:(NSDictionary *)settings analytics:(SEGAnalytics *)analytics { if (self = [super init]) { self.settings = settings; @@ -22,6 +22,21 @@ - (instancetype)initWithSettings:(NSDictionary *)settings withAnalytics:(SEGAnal ADJConfig *adjustConfig = [ADJConfig configWithAppToken:appToken environment:environment]; + if (secret != nil) { + NSAssert(secret.count == 5, @"App secret must contain a secret id followed by four info values"); + + if ([adjustConfig respondsToSelector: @selector(setAppSecret:info1:info2:info3:info4:)]) { + + [adjustConfig setAppSecret:secret[0].unsignedIntegerValue + info1:secret[1].unsignedIntegerValue + info2:secret[2].unsignedIntegerValue + info3:secret[3].unsignedIntegerValue + info4:secret[4].unsignedIntegerValue]; + } else { + SEGLog(@"App secret not supported by current Adjust version"); + } + } + if ([self setEventBufferingEnabled]) { [adjustConfig setEventBufferingEnabled:YES]; } diff --git a/Pod/Classes/SEGAdjustIntegrationFactory.h b/Pod/Classes/SEGAdjustIntegrationFactory.h index 2fce063..832971a 100644 --- a/Pod/Classes/SEGAdjustIntegrationFactory.h +++ b/Pod/Classes/SEGAdjustIntegrationFactory.h @@ -5,5 +5,6 @@ @interface SEGAdjustIntegrationFactory : NSObject + (instancetype)instance; ++ (instancetype)instanceWithAppSecret:(nullable NSArray *)secret; @end diff --git a/Pod/Classes/SEGAdjustIntegrationFactory.m b/Pod/Classes/SEGAdjustIntegrationFactory.m index a894ea1..f9d4355 100644 --- a/Pod/Classes/SEGAdjustIntegrationFactory.m +++ b/Pod/Classes/SEGAdjustIntegrationFactory.m @@ -2,27 +2,34 @@ #import "SEGAdjustIntegration.h" -@implementation SEGAdjustIntegrationFactory +@implementation SEGAdjustIntegrationFactory { + NSArray *appSecret; +} + ++ (instancetype)instance { + return [self instanceWithAppSecret: nil]; +} -+ (instancetype)instance ++ (instancetype)instanceWithAppSecret: (nullable NSArray *)secret { static dispatch_once_t once; static SEGAdjustIntegrationFactory *sharedInstance; dispatch_once(&once, ^{ - sharedInstance = [[self alloc] init]; + sharedInstance = [[self alloc] initWithAppSecret: secret]; }); return sharedInstance; } -- (instancetype)init +- (instancetype)initWithAppSecret: (NSArray *)secret { self = [super init]; + appSecret = secret; return self; } - (id)createWithSettings:(NSDictionary *)settings forAnalytics:(SEGAnalytics *)analytics { - return [[SEGAdjustIntegration alloc] initWithSettings:settings withAnalytics:analytics]; + return [[SEGAdjustIntegration alloc] initWithAppSecret: appSecret settings:settings analytics:analytics]; } - (NSString *)key From 0a17f7657294a4c68245ea2e9477b3b1c4db68f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Mathe=CC=81?= Date: Wed, 18 Jul 2018 16:09:56 +0200 Subject: [PATCH 2/3] Use a dedicated class to represent the app secret instead of an array --- Pod/Classes/SEGAdjustAppSecret.h | 18 ++++++++++++ Pod/Classes/SEGAdjustAppSecret.m | 34 +++++++++++++++++++++++ Pod/Classes/SEGAdjustIntegration.m | 15 +++++----- Pod/Classes/SEGAdjustIntegrationFactory.h | 4 ++- Pod/Classes/SEGAdjustIntegrationFactory.m | 7 +++-- 5 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 Pod/Classes/SEGAdjustAppSecret.h create mode 100644 Pod/Classes/SEGAdjustAppSecret.m diff --git a/Pod/Classes/SEGAdjustAppSecret.h b/Pod/Classes/SEGAdjustAppSecret.h new file mode 100644 index 0000000..37655d0 --- /dev/null +++ b/Pod/Classes/SEGAdjustAppSecret.h @@ -0,0 +1,18 @@ +#import + + +@interface SEGAdjustAppSecret : NSObject + +@property (nonatomic, readonly) NSUInteger ID; +@property (nonatomic, readonly) NSUInteger info1; +@property (nonatomic, readonly) NSUInteger info2; +@property (nonatomic, readonly) NSUInteger info3; +@property (nonatomic, readonly) NSUInteger info4; + +- (instancetype)initWithID:(NSUInteger)ID + info1:(NSUInteger)info1 + info2:(NSUInteger)info2 + info3:(NSUInteger)info3 + info4:(NSUInteger)info4; + +@end diff --git a/Pod/Classes/SEGAdjustAppSecret.m b/Pod/Classes/SEGAdjustAppSecret.m new file mode 100644 index 0000000..ffce70f --- /dev/null +++ b/Pod/Classes/SEGAdjustAppSecret.m @@ -0,0 +1,34 @@ +#import "SEGAdjustAppSecret.h" + + +@interface SEGAdjustAppSecret () + +@property (nonatomic, assign) NSUInteger ID; +@property (nonatomic, assign) NSUInteger info1; +@property (nonatomic, assign) NSUInteger info2; +@property (nonatomic, assign) NSUInteger info3; +@property (nonatomic, assign) NSUInteger info4; + +@end + + +@implementation SEGAdjustAppSecret + +#pragma mark - Initialization + +- (instancetype)initWithID:(NSUInteger)ID + info1:(NSUInteger)info1 + info2:(NSUInteger)info2 + info3:(NSUInteger)info3 + info4:(NSUInteger)info4 { + if (self = [super init]) { + self.ID = ID; + self.info1 = info1; + self.info2 = info2; + self.info3 = info3; + self.info4 = info4; + } + return self; +} + +@end diff --git a/Pod/Classes/SEGAdjustIntegration.m b/Pod/Classes/SEGAdjustIntegration.m index ede9d91..e6ea0ab 100644 --- a/Pod/Classes/SEGAdjustIntegration.m +++ b/Pod/Classes/SEGAdjustIntegration.m @@ -1,4 +1,5 @@ #import "SEGAdjustIntegration.h" +#import "SEGAdjustAppSecret.h" #import @@ -6,7 +7,7 @@ @implementation SEGAdjustIntegration #pragma mark - Initialization -- (instancetype)initWithAppSecret:(nullable NSArray *)secret settings:(NSDictionary *)settings analytics:(SEGAnalytics *)analytics +- (instancetype)initWithAppSecret:(nullable SEGAdjustAppSecret *)secret settings:(NSDictionary *)settings analytics:(SEGAnalytics *)analytics { if (self = [super init]) { self.settings = settings; @@ -23,15 +24,13 @@ - (instancetype)initWithAppSecret:(nullable NSArray *)secret setting environment:environment]; if (secret != nil) { - NSAssert(secret.count == 5, @"App secret must contain a secret id followed by four info values"); - if ([adjustConfig respondsToSelector: @selector(setAppSecret:info1:info2:info3:info4:)]) { - [adjustConfig setAppSecret:secret[0].unsignedIntegerValue - info1:secret[1].unsignedIntegerValue - info2:secret[2].unsignedIntegerValue - info3:secret[3].unsignedIntegerValue - info4:secret[4].unsignedIntegerValue]; + [adjustConfig setAppSecret:secret.ID + info1:secret.info1 + info2:secret.info2 + info3:secret.info3 + info4:secret.info4]; } else { SEGLog(@"App secret not supported by current Adjust version"); } diff --git a/Pod/Classes/SEGAdjustIntegrationFactory.h b/Pod/Classes/SEGAdjustIntegrationFactory.h index 832971a..d412507 100644 --- a/Pod/Classes/SEGAdjustIntegrationFactory.h +++ b/Pod/Classes/SEGAdjustIntegrationFactory.h @@ -1,10 +1,12 @@ #import #import +@class SEGAdjustAppSecret; + @interface SEGAdjustIntegrationFactory : NSObject + (instancetype)instance; -+ (instancetype)instanceWithAppSecret:(nullable NSArray *)secret; ++ (instancetype)instanceWithAppSecret:(nullable SEGAdjustAppSecret *)secret NS_SWIFT_NAME(instance(appSecret:)); @end diff --git a/Pod/Classes/SEGAdjustIntegrationFactory.m b/Pod/Classes/SEGAdjustIntegrationFactory.m index f9d4355..8643d73 100644 --- a/Pod/Classes/SEGAdjustIntegrationFactory.m +++ b/Pod/Classes/SEGAdjustIntegrationFactory.m @@ -1,16 +1,17 @@ #import "SEGAdjustIntegrationFactory.h" #import "SEGAdjustIntegration.h" +#import "SEGAdjustAppSecret.h" @implementation SEGAdjustIntegrationFactory { - NSArray *appSecret; + SEGAdjustAppSecret *appSecret; } + (instancetype)instance { return [self instanceWithAppSecret: nil]; } -+ (instancetype)instanceWithAppSecret: (nullable NSArray *)secret ++ (instancetype)instanceWithAppSecret: (nullable SEGAdjustAppSecret *)secret { static dispatch_once_t once; static SEGAdjustIntegrationFactory *sharedInstance; @@ -20,7 +21,7 @@ + (instancetype)instanceWithAppSecret: (nullable NSArray *)secret return sharedInstance; } -- (instancetype)initWithAppSecret: (NSArray *)secret +- (instancetype)initWithAppSecret: (SEGAdjustAppSecret *)secret { self = [super init]; appSecret = secret; From db15f237fca4e5fbc444db116a4f03307fbdb1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Mathe=CC=81?= Date: Thu, 19 Jul 2018 15:50:22 +0200 Subject: [PATCH 3/3] Avoid warning with old Adjust versions that don't support app secret --- Pod/Classes/SEGAdjustIntegration.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Pod/Classes/SEGAdjustIntegration.m b/Pod/Classes/SEGAdjustIntegration.m index e6ea0ab..5431c26 100644 --- a/Pod/Classes/SEGAdjustIntegration.m +++ b/Pod/Classes/SEGAdjustIntegration.m @@ -2,6 +2,14 @@ #import "SEGAdjustAppSecret.h" #import +@interface ADJConfig () +- (void)setAppSecret:(NSUInteger)secretId + info1:(NSUInteger)info1 + info2:(NSUInteger)info2 + info3:(NSUInteger)info3 + info4:(NSUInteger)info4; +@end + @implementation SEGAdjustIntegration