From 2646fc93913e80bd1726d83eebab7b4c1e882672 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 28 Oct 2014 10:08:06 +0100 Subject: [PATCH 01/86] Track with event object --- Adjust.xcodeproj/project.pbxproj | 12 +++++ Adjust/AIActivityHandler.h | 8 +--- Adjust/AIActivityHandler.m | 82 +++++++------------------------- Adjust/AIDeviceInfo.h | 28 +++++++++++ Adjust/AIDeviceInfo.m | 13 +++++ Adjust/AIEvent.h | 32 +++++++++++++ Adjust/AIEvent.m | 52 ++++++++++++++++++++ Adjust/AIPackageBuilder.h | 9 ++-- Adjust/AIPackageBuilder.m | 44 ++++++----------- Adjust/AIUtil.m | 2 +- Adjust/Adjust.h | 42 ++++------------ Adjust/Adjust.m | 42 +--------------- AdjustBridge/AdjustBridge.js.txt | 9 +--- AdjustBridge/AdjustBridge.m | 28 +++++------ 14 files changed, 200 insertions(+), 203 deletions(-) create mode 100644 Adjust/AIDeviceInfo.h create mode 100644 Adjust/AIDeviceInfo.m create mode 100644 Adjust/AIEvent.h create mode 100644 Adjust/AIEvent.m diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index 0cc82847c..8aa56d084 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -7,10 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 9609BC6A19EEA55800E02303 /* AIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 9609BC6919EEA55800E02303 /* AIEvent.m */; }; 96325E89190E892000A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8A190E892600A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8B190E8D6200A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8C190E8D6B00A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + 9644B7EC19F148F3008576FC /* AIDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 9644B7EB19F148F3008576FC /* AIDeviceInfo.m */; }; 9679921118BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; }; 9679921F18BBAE2800394606 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921E18BBAE2800394606 /* XCTest.framework */; }; 9679922018BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; }; @@ -73,8 +75,12 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 9609BC6819EEA55800E02303 /* AIEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIEvent.h; sourceTree = ""; }; + 9609BC6919EEA55800E02303 /* AIEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIEvent.m; sourceTree = ""; }; 96325E84190E5CD900A97911 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 96325E86190E5CE400A97911 /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iAd.framework; path = System/Library/Frameworks/iAd.framework; sourceTree = SDKROOT; }; + 9644B7EA19F148F3008576FC /* AIDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIDeviceInfo.h; sourceTree = ""; }; + 9644B7EB19F148F3008576FC /* AIDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIDeviceInfo.m; sourceTree = ""; }; 9679920D18BBAE2800394606 /* libAdjust.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAdjust.a; sourceTree = BUILT_PRODUCTS_DIR; }; 9679921018BBAE2800394606 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 9679921D18BBAE2800394606 /* AdjustTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AdjustTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -249,6 +255,10 @@ 96E5E37E18BBB48A008E7B30 /* AITimer.m */, 96E5E37F18BBB48A008E7B30 /* AIUtil.h */, 96E5E38018BBB48A008E7B30 /* AIUtil.m */, + 9609BC6819EEA55800E02303 /* AIEvent.h */, + 9609BC6919EEA55800E02303 /* AIEvent.m */, + 9644B7EA19F148F3008576FC /* AIDeviceInfo.h */, + 9644B7EB19F148F3008576FC /* AIDeviceInfo.m */, ); path = Adjust; sourceTree = ""; @@ -383,8 +393,10 @@ 96E5E39118BBB48A008E7B30 /* UIDevice+AIAdditions.m in Sources */, 96E5E38C18BBB48A008E7B30 /* AIActivityKind.m in Sources */, 96E5E38D18BBB48A008E7B30 /* AIActivityPackage.m in Sources */, + 9644B7EC19F148F3008576FC /* AIDeviceInfo.m in Sources */, 96E5E38E18BBB48A008E7B30 /* AIActivityState.m in Sources */, 96E5E39018BBB48A008E7B30 /* NSString+AIAdditions.m in Sources */, + 9609BC6A19EEA55800E02303 /* AIEvent.m in Sources */, 96E5E39518BBB48A008E7B30 /* AIPackageHandler.m in Sources */, 96E5E39318BBB48A008E7B30 /* AILogger.m in Sources */, 96E5E39418BBB48A008E7B30 /* AIPackageBuilder.m in Sources */, diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index 8f72a09f2..3632a1696 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -22,13 +22,7 @@ - (void)trackSubsessionStart; - (void)trackSubsessionEnd; -- (void)trackEvent:(NSString *)eventToken - withParameters:(NSDictionary *)parameters; - -- (void)trackRevenue:(double)amount - transactionId:(NSString *)transactionId - forEvent:(NSString *)eventToken - withParameters:(NSDictionary *)parameters; +- (void)trackEvent:(AIEvent *)event; - (void)finishedTrackingWithResponse:(AIResponseData *)response deepLink:(NSString *)deepLink; - (void)setEnabled:(BOOL)enabled; diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index 9afe5db54..e8b49b71a 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -100,21 +100,10 @@ - (void)trackSubsessionEnd { }); } -- (void)trackEvent:(NSString *)eventToken - withParameters:(NSDictionary *)parameters +- (void)trackEvent:(AIEvent *)event { dispatch_async(self.internalQueue, ^{ - [self eventInternal:eventToken parameters:parameters]; - }); -} - -- (void)trackRevenue:(double)amount - transactionId:(NSString *)transactionId - forEvent:(NSString *)eventToken - withParameters:(NSDictionary *)parameters -{ - dispatch_async(self.internalQueue, ^{ - [self revenueInternal:amount transactionId:transactionId event:eventToken parameters:parameters]; + [self eventInternal:event]; }); } @@ -278,27 +267,30 @@ - (void)endInternal { [self writeActivityState]; } -- (void)eventInternal:(NSString *)eventToken - parameters:(NSDictionary *)parameters +- (void)eventInternal:(AIEvent *)event { + // check consistency if (![self checkAppTokenNotNil:self.appToken]) return; if (![self checkActivityState:self.activityState]) return; - if (![self checkEventTokenNotNil:eventToken]) return; - if (![self checkEventTokenLength:eventToken]) return; + if (![self checkEventTokenNotNil:event.eventToken]) return; + if (![self checkEventTokenLength:event.eventToken]) return; + if (![self checkAmount:event.revenue]) return; + if (![self checkTransactionId:event.transactionId]) return; if (!self.activityState.enabled) { return; } - AIPackageBuilder *eventBuilder = [[AIPackageBuilder alloc] init]; - eventBuilder.eventToken = eventToken; - eventBuilder.callbackParameters = parameters; - + // update activity state double now = [NSDate.date timeIntervalSince1970]; [self updateActivityState:now]; self.activityState.createdAt = now; self.activityState.eventCount++; + // create and populate event package + AIPackageBuilder *eventBuilder = [[AIPackageBuilder alloc] init]; + eventBuilder.event = event; + [self injectGeneralAttributes:eventBuilder]; [self.activityState injectEventAttributes:eventBuilder]; AIActivityPackage *eventPackage = [eventBuilder buildEventPackage]; @@ -314,46 +306,6 @@ - (void)eventInternal:(NSString *)eventToken [self.logger debug:@"Event %d", self.activityState.eventCount]; } -- (void)revenueInternal:(double)amount - transactionId:(NSString *)transactionId - event:(NSString *)eventToken - parameters:(NSDictionary *)parameters -{ - if (![self checkAppTokenNotNil:self.appToken]) return; - if (![self checkActivityState:self.activityState]) return; - if (![self checkAmount:amount]) return; - if (![self checkEventTokenLength:eventToken]) return; - if (![self checkTransactionId:transactionId]) return; - - if (!self.activityState.enabled) { - return; - } - - AIPackageBuilder *revenueBuilder = [[AIPackageBuilder alloc] init]; - revenueBuilder.amountInCents = amount; - revenueBuilder.eventToken = eventToken; - revenueBuilder.callbackParameters = parameters; - - double now = [NSDate.date timeIntervalSince1970]; - [self updateActivityState:now]; - self.activityState.createdAt = now; - self.activityState.eventCount++; - - [self injectGeneralAttributes:revenueBuilder]; - [self.activityState injectEventAttributes:revenueBuilder]; - AIActivityPackage *revenuePackage = [revenueBuilder buildRevenuePackage]; - [self.packageHandler addPackage:revenuePackage]; - - if (self.bufferEvents) { - [self.logger info:@"Buffered revenue%@", revenuePackage.suffix]; - } else { - [self.packageHandler sendFirstPackage]; - } - - [self writeActivityState]; - [self.logger debug:@"Event %d (revenue)", self.activityState.eventCount]; -} - - (void) readOpenUrlInternal:(NSURL *)url { NSArray* queryArray = [url.query componentsSeparatedByString:@"&"]; NSMutableDictionary* adjustDeepLinks = [NSMutableDictionary dictionary]; @@ -584,16 +536,16 @@ - (BOOL)checkEventTokenLength:(NSString *)eventToken { return YES; } -- (BOOL)checkAmount:(double)amount { - if (amount < 0.0) { - [self.logger error:@"Invalid amount %.1f", amount]; +- (BOOL)checkAmount:(NSNumber *)amount { + if (amount != nil && [amount doubleValue] < 0.0) { + [self.logger error:@"Invalid amount %.1f", [amount doubleValue]]; return NO; } return YES; } - (BOOL) checkTransactionId:(NSString *)transactionId { - if (transactionId.length == 0) { + if (transactionId == nil || transactionId.length == 0) { return YES; // no transaction ID given } diff --git a/Adjust/AIDeviceInfo.h b/Adjust/AIDeviceInfo.h new file mode 100644 index 000000000..fc99dad56 --- /dev/null +++ b/Adjust/AIDeviceInfo.h @@ -0,0 +1,28 @@ +// +// AIDeviceInfo.h +// adjust +// +// Created by Pedro Filipe on 17/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import + +@interface AIDeviceInfo : NSObject + +@property (nonatomic, copy) NSString *appToken; +@property (nonatomic, copy) NSString *macSha1; +@property (nonatomic, copy) NSString *macShortMd5; +@property (nonatomic, copy) NSString *idForAdvertisers; +@property (nonatomic, copy) NSString *fbAttributionId; +@property (nonatomic, copy) NSString *environment; +@property (nonatomic, copy) NSString *userAgent; +@property (nonatomic, copy) NSString *clientSdk; +//@property (nonatomic, copy) NSString *uuid; +@property (nonatomic, assign) BOOL trackingEnabled; +@property (nonatomic, assign) BOOL isIad; +@property (nonatomic, copy) NSString *vendorId; +@property (nonatomic, copy) NSString *pushToken; + + +@end diff --git a/Adjust/AIDeviceInfo.m b/Adjust/AIDeviceInfo.m new file mode 100644 index 000000000..b475052b9 --- /dev/null +++ b/Adjust/AIDeviceInfo.m @@ -0,0 +1,13 @@ +// +// AIDeviceInfo.m +// adjust +// +// Created by Pedro Filipe on 17/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import "AIDeviceInfo.h" + +@implementation AIDeviceInfo + +@end diff --git a/Adjust/AIEvent.h b/Adjust/AIEvent.h new file mode 100644 index 000000000..6439ff89c --- /dev/null +++ b/Adjust/AIEvent.h @@ -0,0 +1,32 @@ +// +// AITrackOption.h +// adjust +// +// Created by Pedro Filipe on 15/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import + +@interface AIEvent : NSObject + +@property (nonatomic, copy) NSString* eventToken; +@property (nonatomic, copy) NSNumber* revenue; +@property (nonatomic, copy) NSMutableDictionary* callbackParameters; +@property (nonatomic, copy) NSMutableDictionary* partnerParameters; +@property (nonatomic, copy) NSString* transactionId; +@property (nonatomic, copy) NSString* currency; + +- (id) initWithEventToken:(NSString *)eventToken; + +- (void) addCallbackParameter:(NSString *)key + andValue:(NSString *)value; + +- (void) addPartnerParameter:(NSString *)key + andValue:(NSString *)value; + +- (void) setRevenue:(double)amount currency:(NSString *)currency; +// check currency correctness, warn if weird +- (void) setTransactionId:(NSString *)transactionId; + +@end diff --git a/Adjust/AIEvent.m b/Adjust/AIEvent.m new file mode 100644 index 000000000..8926f0cbc --- /dev/null +++ b/Adjust/AIEvent.m @@ -0,0 +1,52 @@ +// +// AITrackOption.m +// adjust +// +// Created by Pedro Filipe on 15/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import "AIEvent.h" + +#pragma mark - + +@implementation AIEvent + +- (id) initWithEventToken:(NSString *)eventToken { + self = [super init]; + if (self == nil) return nil; + + self.eventToken = eventToken; + + return self; +} + +- (void) addCallbackParameter:(NSString *)key + andValue:(NSString *)value { + if (_callbackParameters == nil) { + _callbackParameters = [[NSMutableDictionary alloc] init]; + } + + [_callbackParameters setObject:value forKey:key]; +} + +- (void) addPartnerParameter:(NSString *)key + andValue:(NSString *)value { + if (_partnerParameters == nil) { + _partnerParameters = [[NSMutableDictionary alloc] init]; + } + + [_partnerParameters setObject:value forKey:key]; + +} + +- (void) setRevenue:(double) amount currency:(NSString *)currency{ + _revenue = [NSNumber numberWithDouble:amount]; + _currency = currency; +} + +- (void) setTransactionId:(NSString *)transactionId { + _transactionId = transactionId; +} + +@end diff --git a/Adjust/AIPackageBuilder.h b/Adjust/AIPackageBuilder.h index 87268e869..287d0b31e 100644 --- a/Adjust/AIPackageBuilder.h +++ b/Adjust/AIPackageBuilder.h @@ -6,6 +6,8 @@ // Copyright (c) 2013 adjust GmbH. All rights reserved. // #import +#import "AIEvent.h" +#import "AIDeviceInfo.h" @class AIActivityPackage; @@ -36,17 +38,16 @@ // events @property (nonatomic, assign) int eventCount; -@property (nonatomic, copy) NSString *eventToken; -@property (nonatomic, copy) NSDictionary *callbackParameters; -@property (nonatomic, assign) double amountInCents; +@property (nonatomic, retain) AIEvent* event; // reattributions @property (nonatomic, copy) NSDictionary* deeplinkParameters; +//- (id) initWithDeviceInfo:(AIDeviceInfo *)deviceInfo; + - (AIActivityPackage *)buildSessionPackage; - (AIActivityPackage *)buildEventPackage; -- (AIActivityPackage *)buildRevenuePackage; - (AIActivityPackage *)buildReattributionPackage; @end diff --git a/Adjust/AIPackageBuilder.m b/Adjust/AIPackageBuilder.m index 8f58855cb..85e931346 100644 --- a/Adjust/AIPackageBuilder.m +++ b/Adjust/AIPackageBuilder.m @@ -29,7 +29,11 @@ - (AIActivityPackage *)buildSessionPackage { - (AIActivityPackage *)buildEventPackage { NSMutableDictionary *parameters = [self defaultParameters]; - [self injectEventParameters:parameters]; + [self parameters:parameters setString:self.amountString forKey:@"amount"]; + [self parameters:parameters setString:self.event.currency forKey:@"currency"]; + [self parameters:parameters setInt:self.eventCount forKey:@"event_count"]; + [self parameters:parameters setString:self.event.eventToken forKey:@"event_token"]; + [self parameters:parameters setDictionaryBase64:self.event.callbackParameters forKey:@"params"]; AIActivityPackage *eventPackage = [self defaultActivityPackage]; eventPackage.path = @"/event"; @@ -40,19 +44,6 @@ - (AIActivityPackage *)buildEventPackage { return eventPackage; } -- (AIActivityPackage *)buildRevenuePackage { - NSMutableDictionary *parameters = [self defaultParameters]; - [self parameters:parameters setString:self.amountString forKey:@"amount"]; - [self injectEventParameters:parameters]; - - AIActivityPackage *revenuePackage = [self defaultActivityPackage]; - revenuePackage.path = @"/revenue"; - revenuePackage.activityKind = AIActivityKindRevenue; - revenuePackage.suffix = self.revenueSuffix; - revenuePackage.parameters = parameters; - - return revenuePackage; -} - (AIActivityPackage *)buildReattributionPackage { NSMutableDictionary *parameters = [self defaultParameters]; @@ -101,29 +92,22 @@ - (NSMutableDictionary *)defaultParameters { return parameters; } -- (void)injectEventParameters:(NSMutableDictionary *)parameters { - // event specific - [self parameters:parameters setInt:self.eventCount forKey:@"event_count"]; - [self parameters:parameters setString:self.eventToken forKey:@"event_token"]; - [self parameters:parameters setDictionaryBase64:self.callbackParameters forKey:@"params"]; -} - - (NSString *)amountString { - int amountInMillis = round(10 * self.amountInCents); - self.amountInCents = amountInMillis / 10.0; // now rounded to one decimal point + if (self.event.revenue == nil || [self.event.revenue doubleValue] == 0) { + return nil; + } + double revenue = [self.event.revenue doubleValue]; + int amountInMillis = round(1000 * revenue); + self.event.revenue = [NSNumber numberWithDouble:(amountInMillis / 1000.0)]; // now rounded to one decimal point NSString *amountString = [NSNumber numberWithInt:amountInMillis].stringValue; return amountString; } - (NSString *)eventSuffix { - return [NSString stringWithFormat:@" '%@'", self.eventToken]; -} - -- (NSString *)revenueSuffix { - if (self.eventToken != nil) { - return [NSString stringWithFormat:@" (%.1f cent, '%@')", self.amountInCents, self.eventToken]; + if (self.event.revenue == nil) { + return [NSString stringWithFormat:@" '%@'", self.event.eventToken]; } else { - return [NSString stringWithFormat:@" (%.1f cent)", self.amountInCents]; + return [NSString stringWithFormat:@" (%.3f cent, '%@')", [self.event.revenue doubleValue], self.event.eventToken]; } } diff --git a/Adjust/AIUtil.m b/Adjust/AIUtil.m index 7211e6a69..6beca8642 100644 --- a/Adjust/AIUtil.m +++ b/Adjust/AIUtil.m @@ -15,7 +15,7 @@ #include static NSString * const kBaseUrl = @"https://app.adjust.io"; -static NSString * const kClientSdk = @"ios3.4.0"; +static NSString * const kClientSdk = @"ios4.0.0"; static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'Z"; static NSDateFormatter * dateFormat; diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index 3801a1681..513df1f58 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -8,6 +8,7 @@ #import "AILogger.h" #import "AIResponseData.h" +#import "AIEvent.h" @protocol AdjustDelegate; @@ -55,41 +56,17 @@ static NSString * const AIEnvironmentProduction = @"production"; * top of that you can pass a set of parameters to the following method that * will be forwarded to these callbacks. * - * @param eventToken The Event Token for this kind of event. They are created - * in the dashboard at http://adjust.com and should be six characters long. - * @param parameters An optional dictionary containing the callback parameters. - * Provide key-value-pairs to be forwarded to your callbacks. - */ -+ (void)trackEvent:(NSString *)eventToken; -+ (void)trackEvent:(NSString *)eventToken withParameters:(NSDictionary *)parameters; - -/** - * Tell Adjust that a user generated some revenue. + * The event can contain some revenue. The amount is measured in units and + * rounded to the decimal cent point. * - * The amount is measured in cents and rounded to on digit after the - * decimal point. If you want to differentiate between several revenue - * types, you can do so by using different event tokens. If your revenue - * events have callbacks, you can also pass in parameters that will be - * forwarded to your end point. + * A transaction ID can be used to avoid duplicate revenue events. The last ten + * transaction identifiers are remembered. * - * A transaction ID can be used to avoid duplicate revenue events. The last ten transaction identifiers are remembered. - * This is useful for in-app purchase tracking where you can pass in the identifier of the reported transaction. - * - * @param amountInCents The amount in cents (example: 1.5 means one and a half cents) - * @param transactionIdentifier The identifier used to avoid duplicate revenue events (optional, see above) - * @param eventToken The token for this revenue event (optional, see above) - * @param parameters Parameters for this revenue event (optional, see above) + * @param event The Event object for this kind of event. It needs a event token + * that is created in the dashboard at http://adjust.com and should be six + * characters long. */ -+ (void)trackRevenue:(double)amountInCents; -+ (void)trackRevenue:(double)amountInCents forEvent:(NSString *)eventToken; -+ (void)trackRevenue:(double)amountInCents forEvent:(NSString *)eventToken withParameters:(NSDictionary *)parameters; - -+ (void)trackRevenue:(double)amountInCents transactionId:(NSString *)transactionId; -+ (void)trackRevenue:(double)amountInCents transactionId:(NSString *)transactionId forEvent:(NSString *)eventToken; -+ (void)trackRevenue:(double)amountInCents - transactionId:(NSString *)transactionId - forEvent:(NSString *)eventToken - withParameters:(NSDictionary *)parameters; ++ (void)trackEvent:(AIEvent *)event; /** * Change the verbosity of Adjust's logs. @@ -174,6 +151,7 @@ static NSString * const AIEnvironmentProduction = @"production"; * Set the device token used by push notifications */ + (void)setDeviceToken:(NSData *)deviceToken; + @end diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 924c2fab0..3cbe018d3 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -33,46 +33,8 @@ + (void)setSdkPrefix:(NSString *)sdkPrefix { [activityHandler setSdkPrefix:sdkPrefix]; } -+ (void)trackEvent:(NSString *)eventToken { - [activityHandler trackEvent:eventToken withParameters:nil]; -} - -+ (void)trackEvent:(NSString *)eventToken withParameters:(NSDictionary *)parameters { - [activityHandler trackEvent:eventToken withParameters:parameters]; -} - -+ (void)trackRevenue:(double)amountInCents { - [activityHandler trackRevenue:amountInCents transactionId:nil forEvent:nil withParameters:nil]; -} - -+ (void)trackRevenue:(double)amountInCents forEvent:(NSString *)eventToken { - [activityHandler trackRevenue:amountInCents transactionId:nil forEvent:eventToken withParameters:nil]; -} - -+ (void)trackRevenue:(double)amountInCents - forEvent:(NSString *)eventToken - withParameters:(NSDictionary *)parameters -{ - [activityHandler trackRevenue:amountInCents transactionId:nil forEvent:eventToken withParameters:parameters]; -} - -+ (void)trackRevenue:(double)amountInCents transactionId:(NSString *)transactionId { - [activityHandler trackRevenue:amountInCents transactionId:transactionId forEvent:nil withParameters:nil]; -} - -+ (void)trackRevenue:(double)amountInCents transactionId:(NSString *)transactionId forEvent:(NSString *)eventToken { - [activityHandler trackRevenue:amountInCents transactionId:transactionId forEvent:eventToken withParameters:nil]; -} - -+ (void)trackRevenue:(double)amountInCents - transactionId:(NSString *)transactionId - forEvent:(NSString *)eventToken - withParameters:(NSDictionary *)parameters -{ - [activityHandler trackRevenue:amountInCents - transactionId:transactionId - forEvent:eventToken - withParameters:parameters]; ++ (void)trackEvent:(AIEvent *)event { + [activityHandler trackEvent:event]; } + (void)setLogLevel:(AILogLevel)logLevel { diff --git a/AdjustBridge/AdjustBridge.js.txt b/AdjustBridge/AdjustBridge.js.txt index e0c8ffd79..c7bb877f1 100644 --- a/AdjustBridge/AdjustBridge.js.txt +++ b/AdjustBridge/AdjustBridge.js.txt @@ -11,13 +11,7 @@ window.AdjustBridge = (function () { function trackEventPrivate (eventToken, parameters) { bridge.callHandler(adjustPrefix + 'trackEvent', - {'eventToken': eventToken, 'parameters': parameters}, - function(response) {}) - }; - - function trackRevenuePrivate (amountInCents, eventToken, parameters) { - bridge.callHandler(adjustPrefix + 'trackRevenue', - {'amountInCents': amountInCents, 'eventToken': eventToken, 'parameters': parameters}, + {'eventToken': eventToken, 'parameters': parameters, 'revenue': revenue}, function(response) {}) }; @@ -46,7 +40,6 @@ window.AdjustBridge = (function () { return { setBridge: setBridgePrivate, trackEvent: trackEventPrivate, - trackRevenue: trackRevenuePrivate, setResponseDelegate: setResponseDelegatePrivate, setEnabled: setEnabledPrivate, isEnabled: isEnabledPrivate, diff --git a/AdjustBridge/AdjustBridge.m b/AdjustBridge/AdjustBridge.m index d9ea03545..0c0905900 100644 --- a/AdjustBridge/AdjustBridge.m +++ b/AdjustBridge/AdjustBridge.m @@ -32,27 +32,23 @@ + (void) loadBridge:(NSObject *) webViewDelegate NSString* eventToken = [data objectForKey:@"eventToken"]; NSDictionary* parameters = [data objectForKey:@"parameters"]; + NSNumber* revenue = [data objectForKey:@"revenue"]; + NSString* currency = [data objectForKey:@"currency"]; + + AIEvent* event = [[AIEvent alloc] initWithEventToken:eventToken]; if (parameters != nil) { - [Adjust trackEvent:eventToken withParameters:parameters]; - } else { - [Adjust trackEvent:eventToken]; + for (NSString* key in parameters) { + NSString* value = [parameters objectForKey:key]; + [event addCallbackParameter:key andValue:value]; + } } - }]; - - [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@trackRevenue", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { - - NSString* eventToken = [data objectForKey:@"eventToken"]; - NSDictionary* parameters = [data objectForKey:@"parameters"]; - double amountInCents = [[data objectForKey:@"amountInCents"] doubleValue]; - if (parameters != nil) { - [Adjust trackRevenue:amountInCents forEvent:eventToken withParameters:parameters]; - } else if (eventToken != nil) { - [Adjust trackRevenue:amountInCents forEvent:eventToken]; - } else { - [Adjust trackRevenue:amountInCents]; + if (revenue != nil) { + [event setRevenue:[revenue doubleValue] currency:currency]; } + + [Adjust trackEvent:event]; }]; [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@setResponseDelegate", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { From 21a5548e6179954dd5496314a14eed3f51c63b3c Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 28 Oct 2014 18:47:27 +0100 Subject: [PATCH 02/86] User agent to parameters --- Adjust.xcodeproj/project.pbxproj | 14 ++-- Adjust/AIActivityHandler.h | 12 ++-- Adjust/AIActivityHandler.m | 103 ++++++++++++++++------------ Adjust/AIActivityPackage.h | 1 - Adjust/AIActivityPackage.m | 3 - Adjust/AIActivityState.m | 2 +- Adjust/AIDeviceInfo.h | 13 ++-- Adjust/AIDeviceInfo.m | 22 ++++++ Adjust/AIEvent.h | 2 +- Adjust/AIEvent.m | 15 ++++ Adjust/AIPackageBuilder.h | 17 +---- Adjust/AIPackageBuilder.m | 56 ++++++++++----- Adjust/AIRequestHandler.m | 1 - Adjust/AIUserAgent.h | 22 ++++++ Adjust/AIUserAgent.m | 30 ++++++++ Adjust/AIUtil.h | 3 +- Adjust/AIUtil.m | 29 ++++---- Adjust/Adjust.m | 10 +-- AdjustTests/AIActivityHandlerMock.m | 4 +- 19 files changed, 240 insertions(+), 119 deletions(-) create mode 100644 Adjust/AIUserAgent.h create mode 100644 Adjust/AIUserAgent.m diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index 8aa56d084..947f24443 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -12,7 +12,8 @@ 96325E8A190E892600A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8B190E8D6200A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8C190E8D6B00A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; - 9644B7EC19F148F3008576FC /* AIDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 9644B7EB19F148F3008576FC /* AIDeviceInfo.m */; }; + 965307F61A000DA400107FF9 /* AIDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 965307F51A000DA400107FF9 /* AIDeviceInfo.m */; }; + 965307F81A000DCC00107FF9 /* AIUserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 965307F71A000DCC00107FF9 /* AIUserAgent.m */; }; 9679921118BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; }; 9679921F18BBAE2800394606 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921E18BBAE2800394606 /* XCTest.framework */; }; 9679922018BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; }; @@ -80,7 +81,9 @@ 96325E84190E5CD900A97911 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 96325E86190E5CE400A97911 /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iAd.framework; path = System/Library/Frameworks/iAd.framework; sourceTree = SDKROOT; }; 9644B7EA19F148F3008576FC /* AIDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIDeviceInfo.h; sourceTree = ""; }; - 9644B7EB19F148F3008576FC /* AIDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIDeviceInfo.m; sourceTree = ""; }; + 9653078119FFD56900107FF9 /* AIUserAgent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AIUserAgent.h; sourceTree = ""; }; + 965307F51A000DA400107FF9 /* AIDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIDeviceInfo.m; sourceTree = ""; }; + 965307F71A000DCC00107FF9 /* AIUserAgent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIUserAgent.m; sourceTree = ""; }; 9679920D18BBAE2800394606 /* libAdjust.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAdjust.a; sourceTree = BUILT_PRODUCTS_DIR; }; 9679921018BBAE2800394606 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 9679921D18BBAE2800394606 /* AdjustTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AdjustTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -258,7 +261,9 @@ 9609BC6819EEA55800E02303 /* AIEvent.h */, 9609BC6919EEA55800E02303 /* AIEvent.m */, 9644B7EA19F148F3008576FC /* AIDeviceInfo.h */, - 9644B7EB19F148F3008576FC /* AIDeviceInfo.m */, + 965307F51A000DA400107FF9 /* AIDeviceInfo.m */, + 9653078119FFD56900107FF9 /* AIUserAgent.h */, + 965307F71A000DCC00107FF9 /* AIUserAgent.m */, ); path = Adjust; sourceTree = ""; @@ -393,11 +398,12 @@ 96E5E39118BBB48A008E7B30 /* UIDevice+AIAdditions.m in Sources */, 96E5E38C18BBB48A008E7B30 /* AIActivityKind.m in Sources */, 96E5E38D18BBB48A008E7B30 /* AIActivityPackage.m in Sources */, - 9644B7EC19F148F3008576FC /* AIDeviceInfo.m in Sources */, + 965307F61A000DA400107FF9 /* AIDeviceInfo.m in Sources */, 96E5E38E18BBB48A008E7B30 /* AIActivityState.m in Sources */, 96E5E39018BBB48A008E7B30 /* NSString+AIAdditions.m in Sources */, 9609BC6A19EEA55800E02303 /* AIEvent.m in Sources */, 96E5E39518BBB48A008E7B30 /* AIPackageHandler.m in Sources */, + 965307F81A000DCC00107FF9 /* AIUserAgent.m in Sources */, 96E5E39318BBB48A008E7B30 /* AILogger.m in Sources */, 96E5E39418BBB48A008E7B30 /* AIPackageBuilder.m in Sources */, 96E5E39218BBB48A008E7B30 /* AIAdjustFactory.m in Sources */, diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index 3632a1696..244c8c95d 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -10,12 +10,6 @@ @protocol AIActivityHandler -@property (nonatomic, copy) NSString *environment; -@property (nonatomic, assign) BOOL bufferEvents; -@property (nonatomic, assign) BOOL trackMacMd5; -@property (nonatomic, assign) NSObject *delegate; -@property (nonatomic, assign) BOOL isIad; - - (id)initWithAppToken:(NSString *)appToken; - (void)setSdkPrefix:(NSString *)sdkPrefix; @@ -30,6 +24,12 @@ - (void)readOpenUrl:(NSURL*)url; - (void)savePushToken:(NSData *)pushToken; +- (void)setEnvironment:(NSString *)environment; +- (void)setBufferEvents:(BOOL)bufferEvents; +- (void)setTrackMacMd5:(BOOL)trackMacMd5; +- (void)setDelegate:(NSObject *) delegate; +- (void)setIsIad:(BOOL)isIad; + @end @interface AIActivityHandler : NSObject diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index e8b49b71a..c49934991 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -18,6 +18,7 @@ #import "NSString+AIAdditions.h" #import "AIAdjustFactory.h" + static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAdjustPrefix = @"adjust_"; static const char * const kInternalQueueName = "io.adjust.ActivityQueue"; @@ -34,18 +35,12 @@ @interface AIActivityHandler() @property (nonatomic, retain) AIActivityState *activityState; @property (nonatomic, retain) AITimer *timer; @property (nonatomic, retain) id logger; +@property (nonatomic, assign) BOOL enabled; +@property (nonatomic, assign) BOOL bufferEvents; +@property (nonatomic, assign) BOOL trackMacMd5; +@property (nonatomic, retain) NSObject *delegate; -@property (nonatomic, copy) NSString *appToken; -@property (nonatomic, copy) NSString *macSha1; -@property (nonatomic, copy) NSString *macShortMd5; -@property (nonatomic, copy) NSString *idForAdvertisers; -@property (nonatomic, copy) NSString *fbAttributionId; -@property (nonatomic, copy) NSString *userAgent; -@property (nonatomic, copy) NSString *clientSdk; -@property (nonatomic, assign) BOOL trackingEnabled; -@property (nonatomic, assign) BOOL internalEnabled; -@property (nonatomic, copy) NSString *vendorId; -@property (nonatomic, copy) NSString *pushToken; +@property (nonatomic, copy) AIDeviceInfo* deviceInfo; @end @@ -53,12 +48,6 @@ @interface AIActivityHandler() #pragma mark - @implementation AIActivityHandler -@synthesize environment; -@synthesize bufferEvents; -@synthesize trackMacMd5; -@synthesize delegate; -@synthesize isIad; - + (id)handlerWithAppToken:(NSString *)appToken { return [[AIActivityHandler alloc] initWithAppToken:appToken]; } @@ -69,13 +58,15 @@ - (id)initWithAppToken:(NSString *)yourAppToken { [self addNotificationObserver]; self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); - self.clientSdk = AIUtil.clientSdk; + self.deviceInfo = [[AIDeviceInfo alloc] init]; + + self.deviceInfo.clientSdk = AIUtil.clientSdk; self.logger = AIAdjustFactory.logger; // default values - self.environment = @"unknown"; - self.trackMacMd5 = YES; - self.internalEnabled = YES; + self.deviceInfo.environment = @"unknown"; + _trackMacMd5 = YES; + _enabled = YES; dispatch_async(self.internalQueue, ^{ [self initInternal:yourAppToken]; @@ -85,7 +76,7 @@ - (id)initWithAppToken:(NSString *)yourAppToken { } - (void)setSdkPrefix:(NSString *)sdkPrefix { - self.clientSdk = [NSString stringWithFormat:@"%@@%@", sdkPrefix, self.clientSdk]; + self.deviceInfo.clientSdk = [NSString stringWithFormat:@"%@@%@", sdkPrefix, AIUtil.clientSdk]; } - (void)trackSubsessionStart { @@ -141,7 +132,7 @@ - (void)launchDeepLink:(NSString *) deepLink{ } - (void)setEnabled:(BOOL)enabled { - self.internalEnabled = enabled; + _enabled = enabled; if ([self checkActivityState:self.activityState]) { self.activityState.enabled = enabled; } @@ -156,7 +147,7 @@ - (BOOL)isEnabled { if ([self checkActivityState:self.activityState]) { return self.activityState.enabled; } else { - return self.internalEnabled; + return _enabled; } } @@ -172,6 +163,27 @@ - (void)savePushToken:(NSData *)pushToken { }); } +- (void)setEnvironment:(NSString *)environment { + self.deviceInfo.environment = environment; +} + +- (void)setBufferEvents:(BOOL)bufferEvents { + _bufferEvents = bufferEvents; +} + +- (void)setTrackMacMd5:(BOOL)trackMacMd5 { + _trackMacMd5 = trackMacMd5; +} + +- (void)setDelegate:(NSObject *) delegate { + _delegate = delegate; +} + +- (void)setIsIad:(BOOL)isIad { + self.deviceInfo.isIad = isIad; +} + + #pragma mark - internal - (void)initInternal:(NSString *)yourAppToken { if (![self checkAppTokenNotNil:yourAppToken]) return; @@ -180,14 +192,14 @@ - (void)initInternal:(NSString *)yourAppToken { NSString *macAddress = UIDevice.currentDevice.aiMacAddress; NSString *macShort = macAddress.aiRemoveColons; - self.appToken = yourAppToken; - self.macSha1 = macAddress.aiSha1; - self.macShortMd5 = macShort.aiMd5; - self.trackingEnabled = UIDevice.currentDevice.aiTrackingEnabled; - self.idForAdvertisers = UIDevice.currentDevice.aiIdForAdvertisers; - self.fbAttributionId = UIDevice.currentDevice.aiFbAttributionId; - self.userAgent = AIUtil.userAgent; - self.vendorId = UIDevice.currentDevice.aiVendorId; + self.deviceInfo.appToken = yourAppToken; + self.deviceInfo.macSha1 = macAddress.aiSha1; + self.deviceInfo.macShortMd5 = macShort.aiMd5; + self.deviceInfo.trackingEnabled = UIDevice.currentDevice.aiTrackingEnabled; + self.deviceInfo.idForAdvertisers = UIDevice.currentDevice.aiIdForAdvertisers; + self.deviceInfo.fbAttributionId = UIDevice.currentDevice.aiFbAttributionId; + self.deviceInfo.userAgent = AIUtil.userAgent; + self.deviceInfo.vendorId = UIDevice.currentDevice.aiVendorId; [[UIDevice currentDevice] aiSetIad:self]; @@ -198,7 +210,7 @@ - (void)initInternal:(NSString *)yourAppToken { } - (void)startInternal { - if (![self checkAppTokenNotNil:self.appToken]) return; + if (![self checkAppTokenNotNil:self.deviceInfo.appToken]) return; if (self.activityState != nil && !self.activityState.enabled) { @@ -218,7 +230,7 @@ - (void)startInternal { [self transferSessionPackage]; [self.activityState resetSessionAttributes:now]; - self.activityState.enabled = self.internalEnabled; + self.activityState.enabled = _enabled; [self writeActivityState]; [self.logger info:@"First session"]; return; @@ -258,7 +270,7 @@ - (void)startInternal { } - (void)endInternal { - if (![self checkAppTokenNotNil:self.appToken]) return; + if (![self checkAppTokenNotNil:self.deviceInfo.appToken]) return; [self.packageHandler pauseSending]; [self stopTimer]; @@ -270,7 +282,7 @@ - (void)endInternal { - (void)eventInternal:(AIEvent *)event { // check consistency - if (![self checkAppTokenNotNil:self.appToken]) return; + if (![self checkAppTokenNotNil:self.deviceInfo.appToken]) return; if (![self checkActivityState:self.activityState]) return; if (![self checkEventTokenNotNil:event.eventToken]) return; if (![self checkEventTokenLength:event.eventToken]) return; @@ -291,12 +303,14 @@ - (void)eventInternal:(AIEvent *)event AIPackageBuilder *eventBuilder = [[AIPackageBuilder alloc] init]; eventBuilder.event = event; - [self injectGeneralAttributes:eventBuilder]; + //[self injectGeneralAttributes:eventBuilder]; + eventBuilder.deviceInfo = self.deviceInfo; + eventBuilder.trackMd5 = _trackMacMd5; [self.activityState injectEventAttributes:eventBuilder]; AIActivityPackage *eventPackage = [eventBuilder buildEventPackage]; [self.packageHandler addPackage:eventPackage]; - if (self.bufferEvents) { + if (_bufferEvents) { [self.logger info:@"Buffered event%@", eventPackage.suffix]; } else { [self.packageHandler sendFirstPackage]; @@ -332,7 +346,9 @@ - (void) readOpenUrlInternal:(NSURL *)url { AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init]; reattributionBuilder.deeplinkParameters = adjustDeepLinks; - [self injectGeneralAttributes:reattributionBuilder]; + //[self injectGeneralAttributes:reattributionBuilder]; + reattributionBuilder.deviceInfo = self.deviceInfo; + reattributionBuilder.trackMd5 = _trackMacMd5; AIActivityPackage *reattributionPackage = [reattributionBuilder buildReattributionPackage]; [self.packageHandler addPackage:reattributionPackage]; [self.packageHandler sendFirstPackage]; @@ -348,7 +364,7 @@ - (void) savePushTokenInternal:(NSData *)pushToken { NSString *token = [pushToken.description stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]]; token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; - self.pushToken = token; + self.deviceInfo.pushToken = token; } #pragma mark - private @@ -415,13 +431,16 @@ - (NSString *)activityStateFilename { - (void)transferSessionPackage { AIPackageBuilder *sessionBuilder = [[AIPackageBuilder alloc] init]; - [self injectGeneralAttributes:sessionBuilder]; + //[self injectGeneralAttributes:sessionBuilder]; + sessionBuilder.deviceInfo = self.deviceInfo; + sessionBuilder.trackMd5 = _trackMacMd5; [self.activityState injectSessionAttributes:sessionBuilder]; AIActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage]; [self.packageHandler addPackage:sessionPackage]; [self.packageHandler sendFirstPackage]; } +/* - (void)injectGeneralAttributes:(AIPackageBuilder *)builder { builder.userAgent = self.userAgent; builder.clientSdk = self.clientSdk; @@ -439,7 +458,7 @@ - (void)injectGeneralAttributes:(AIPackageBuilder *)builder { builder.macShortMd5 = self.macShortMd5; } } - +*/ # pragma mark - timer - (void)startTimer { if (self.timer == nil) { diff --git a/Adjust/AIActivityPackage.h b/Adjust/AIActivityPackage.h index da36d6d26..7079d6ef4 100644 --- a/Adjust/AIActivityPackage.h +++ b/Adjust/AIActivityPackage.h @@ -12,7 +12,6 @@ // data @property (nonatomic, copy) NSString *path; -@property (nonatomic, copy) NSString *userAgent; @property (nonatomic, copy) NSString *clientSdk; @property (nonatomic, retain) NSDictionary *parameters; diff --git a/Adjust/AIActivityPackage.m b/Adjust/AIActivityPackage.m index 3fae228b6..c0de84e2d 100644 --- a/Adjust/AIActivityPackage.m +++ b/Adjust/AIActivityPackage.m @@ -21,7 +21,6 @@ - (NSString *)description { - (NSString *)extendedString { NSMutableString *builder = [NSMutableString string]; [builder appendFormat:@"Path: %@\n", self.path]; - [builder appendFormat:@"UserAgent: %@\n", self.userAgent]; [builder appendFormat:@"ClientSdk: %@\n", self.clientSdk]; if (self.parameters != nil) { @@ -53,7 +52,6 @@ - (id)initWithCoder:(NSCoder *)decoder { if (self == nil) return self; self.path = [decoder decodeObjectForKey:@"path"]; - self.userAgent = [decoder decodeObjectForKey:@"userAgent"]; self.clientSdk = [decoder decodeObjectForKey:@"clientSdk"]; self.parameters = [decoder decodeObjectForKey:@"parameters"]; NSString *kindString = [decoder decodeObjectForKey:@"kind"]; @@ -68,7 +66,6 @@ - (void)encodeWithCoder:(NSCoder *)encoder { NSString *kindString = AIActivityKindToString(self.activityKind); [encoder encodeObject:self.path forKey:@"path"]; - [encoder encodeObject:self.userAgent forKey:@"userAgent"]; [encoder encodeObject:self.clientSdk forKey:@"clientSdk"]; [encoder encodeObject:self.parameters forKey:@"parameters"]; [encoder encodeObject:kindString forKey:@"kind"]; diff --git a/Adjust/AIActivityState.m b/Adjust/AIActivityState.m index b116a51da..49529a02b 100644 --- a/Adjust/AIActivityState.m +++ b/Adjust/AIActivityState.m @@ -135,7 +135,7 @@ - (void)injectGeneralAttributes:(AIPackageBuilder *)builder { builder.sessionLength = self.sessionLength; builder.timeSpent = self.timeSpent; builder.createdAt = self.createdAt; - builder.uuid = self.uuid; + builder.deviceInfo.uuid = self.uuid; } @end diff --git a/Adjust/AIDeviceInfo.h b/Adjust/AIDeviceInfo.h index fc99dad56..28b49f7aa 100644 --- a/Adjust/AIDeviceInfo.h +++ b/Adjust/AIDeviceInfo.h @@ -7,22 +7,23 @@ // #import +#import "AIUserAgent.h" -@interface AIDeviceInfo : NSObject +@interface AIDeviceInfo : NSObject -@property (nonatomic, copy) NSString *appToken; @property (nonatomic, copy) NSString *macSha1; @property (nonatomic, copy) NSString *macShortMd5; @property (nonatomic, copy) NSString *idForAdvertisers; @property (nonatomic, copy) NSString *fbAttributionId; -@property (nonatomic, copy) NSString *environment; -@property (nonatomic, copy) NSString *userAgent; -@property (nonatomic, copy) NSString *clientSdk; -//@property (nonatomic, copy) NSString *uuid; @property (nonatomic, assign) BOOL trackingEnabled; @property (nonatomic, assign) BOOL isIad; @property (nonatomic, copy) NSString *vendorId; @property (nonatomic, copy) NSString *pushToken; +@property (nonatomic, copy) AIUserAgent *userAgent; +@property (nonatomic, copy) NSString *appToken; +@property (nonatomic, copy) NSString *environment; +@property (nonatomic, copy) NSString *clientSdk; +@property (nonatomic, copy) NSString *uuid; @end diff --git a/Adjust/AIDeviceInfo.m b/Adjust/AIDeviceInfo.m index b475052b9..90de7e271 100644 --- a/Adjust/AIDeviceInfo.m +++ b/Adjust/AIDeviceInfo.m @@ -10,4 +10,26 @@ @implementation AIDeviceInfo +-(id)copyWithZone:(NSZone *)zone +{ + AIDeviceInfo* copy = [[[self class] allocWithZone:zone] init]; + if (copy) { + copy.macSha1 = [self.macSha1 copyWithZone:zone]; + copy.macShortMd5 = [self.macShortMd5 copyWithZone:zone]; + copy.idForAdvertisers = [self.idForAdvertisers copyWithZone:zone]; + copy.fbAttributionId = [self.fbAttributionId copyWithZone:zone]; + copy.trackingEnabled = self.trackingEnabled; + copy.isIad = self.isIad; + copy.vendorId = [self.vendorId copyWithZone:zone]; + copy.pushToken = [self.pushToken copyWithZone:zone]; + copy.userAgent = [self.userAgent copyWithZone:zone]; + copy.appToken = [self.appToken copyWithZone:zone]; + copy.environment = [self.environment copyWithZone:zone]; + copy.clientSdk = [self.clientSdk copyWithZone:zone]; + copy.uuid = [self.uuid copyWithZone:zone]; + } + + return copy; +} + @end diff --git a/Adjust/AIEvent.h b/Adjust/AIEvent.h index 6439ff89c..1f84bf5cf 100644 --- a/Adjust/AIEvent.h +++ b/Adjust/AIEvent.h @@ -8,7 +8,7 @@ #import -@interface AIEvent : NSObject +@interface AIEvent : NSObject @property (nonatomic, copy) NSString* eventToken; @property (nonatomic, copy) NSNumber* revenue; diff --git a/Adjust/AIEvent.m b/Adjust/AIEvent.m index 8926f0cbc..e1e9a9433 100644 --- a/Adjust/AIEvent.m +++ b/Adjust/AIEvent.m @@ -49,4 +49,19 @@ - (void) setTransactionId:(NSString *)transactionId { _transactionId = transactionId; } +-(id)copyWithZone:(NSZone *)zone +{ + AIEvent* copy = [[[self class] allocWithZone:zone] init]; + if (copy) { + copy.eventToken = [self.eventToken copyWithZone:zone]; + copy.revenue = [self.revenue copyWithZone:zone]; + copy.callbackParameters = [self.callbackParameters copyWithZone:zone]; + copy.partnerParameters = [self.partnerParameters copyWithZone:zone]; + copy.transactionId = [self.transactionId copyWithZone:zone]; + copy.currency = [self.currency copyWithZone:zone]; + } + return copy; + +} + @end diff --git a/Adjust/AIPackageBuilder.h b/Adjust/AIPackageBuilder.h index 287d0b31e..be058d1d6 100644 --- a/Adjust/AIPackageBuilder.h +++ b/Adjust/AIPackageBuilder.h @@ -14,19 +14,8 @@ @interface AIPackageBuilder : NSObject // general -@property (nonatomic, copy) NSString *appToken; -@property (nonatomic, copy) NSString *macSha1; -@property (nonatomic, copy) NSString *macShortMd5; -@property (nonatomic, copy) NSString *idForAdvertisers; -@property (nonatomic, copy) NSString *fbAttributionId; -@property (nonatomic, copy) NSString *environment; -@property (nonatomic, copy) NSString *userAgent; -@property (nonatomic, copy) NSString *clientSdk; -@property (nonatomic, copy) NSString *uuid; -@property (nonatomic, assign) BOOL trackingEnabled; -@property (nonatomic, assign) BOOL isIad; -@property (nonatomic, copy) NSString *vendorId; -@property (nonatomic, copy) NSString *pushToken; +@property (nonatomic, copy) AIDeviceInfo* deviceInfo; +@property (nonatomic, assign) BOOL trackMd5; // sessions @property (nonatomic, assign) int sessionCount; @@ -38,7 +27,7 @@ // events @property (nonatomic, assign) int eventCount; -@property (nonatomic, retain) AIEvent* event; +@property (nonatomic, copy) AIEvent* event; // reattributions @property (nonatomic, copy) NSDictionary* deeplinkParameters; diff --git a/Adjust/AIPackageBuilder.m b/Adjust/AIPackageBuilder.m index 85e931346..e27327047 100644 --- a/Adjust/AIPackageBuilder.m +++ b/Adjust/AIPackageBuilder.m @@ -61,29 +61,16 @@ - (AIActivityPackage *)buildReattributionPackage { #pragma mark private - (AIActivityPackage *)defaultActivityPackage { AIActivityPackage *activityPackage = [[AIActivityPackage alloc] init]; - activityPackage.userAgent = self.userAgent; - activityPackage.clientSdk = self.clientSdk; + activityPackage.clientSdk = self.deviceInfo.clientSdk; return activityPackage; } - (NSMutableDictionary *)defaultParameters { NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; - // general + [self constructDeviceInfo:self.deviceInfo toParameters:parameters trackMacMd5:self.trackMd5]; + [self parameters:parameters setDate:self.createdAt forKey:@"created_at"]; - [self parameters:parameters setString:self.appToken forKey:@"app_token"]; - [self parameters:parameters setString:self.macSha1 forKey:@"mac_sha1"]; - [self parameters:parameters setString:self.macShortMd5 forKey:@"mac_md5"]; - [self parameters:parameters setString:self.uuid forKey:@"ios_uuid"]; - [self parameters:parameters setString:self.idForAdvertisers forKey:@"idfa"]; - [self parameters:parameters setString:self.fbAttributionId forKey:@"fb_id"]; - [self parameters:parameters setString:self.environment forKey:@"environment"]; - [self parameters:parameters setInt:self.trackingEnabled forKey:@"tracking_enabled"]; - [self parameters:parameters setBool:self.isIad forKey:@"is_iad"]; - [self parameters:parameters setString:self.vendorId forKey:@"idfv"]; - [self parameters:parameters setString:self.pushToken forKey:@"push_token"]; - - // session related (used for events as well) [self parameters:parameters setInt:self.sessionCount forKey:@"session_count"]; [self parameters:parameters setInt:self.subsessionCount forKey:@"subsession_count"]; [self parameters:parameters setDuration:self.sessionLength forKey:@"session_length"]; @@ -92,6 +79,43 @@ - (NSMutableDictionary *)defaultParameters { return parameters; } +- (void) constructDeviceInfo: (AIDeviceInfo *) deviceInfo + toParameters: (NSMutableDictionary *) parameters + trackMacMd5: (BOOL) trackMacMd5{ + + [self constructUserAgent:deviceInfo.userAgent toParameters:parameters]; + + [self parameters:parameters setString:deviceInfo.macSha1 forKey:@"mac_sha1"]; + [self parameters:parameters setString:deviceInfo.idForAdvertisers forKey:@"idfa"]; + [self parameters:parameters setString:deviceInfo.fbAttributionId forKey:@"fb_id"]; + [self parameters:parameters setInt:deviceInfo.trackingEnabled forKey:@"tracking_enabled"]; + [self parameters:parameters setBool:deviceInfo.isIad forKey:@"is_iad"]; + [self parameters:parameters setString:deviceInfo.vendorId forKey:@"idfv"]; + [self parameters:parameters setString:deviceInfo.pushToken forKey:@"push_token"]; + + if (trackMacMd5) { + [self parameters:parameters setString:deviceInfo.macShortMd5 forKey:@"mac_md5"]; + } + + [self parameters:parameters setString:deviceInfo.appToken forKey:@"app_token"]; + [self parameters:parameters setString:deviceInfo.uuid forKey:@"ios_uuid"]; + [self parameters:parameters setString:deviceInfo.environment forKey:@"environment"]; + +} + +- (void) constructUserAgent: (AIUserAgent *) userAgent + toParameters: (NSMutableDictionary *) parameters { + [self parameters:parameters setString:userAgent.bundeIdentifier forKey:@"bundle_identifier"]; + [self parameters:parameters setString:userAgent.bundleVersion forKey:@"bundle_version"]; + [self parameters:parameters setString:userAgent.deviceType forKey:@"device_type"]; + [self parameters:parameters setString:userAgent.deviceName forKey:@"device_name"]; + [self parameters:parameters setString:userAgent.osName forKey:@"os_name"]; + [self parameters:parameters setString:userAgent.systemVersion forKey:@"system_version"]; + [self parameters:parameters setString:userAgent.languageCode forKey:@"language_code"]; + [self parameters:parameters setString:userAgent.countryCode forKey:@"country_code"]; +} + + - (NSString *)amountString { if (self.event.revenue == nil || [self.event.revenue doubleValue] == 0) { return nil; diff --git a/Adjust/AIRequestHandler.m b/Adjust/AIRequestHandler.m index 8f143d1bd..bae24183d 100644 --- a/Adjust/AIRequestHandler.m +++ b/Adjust/AIRequestHandler.m @@ -103,7 +103,6 @@ - (NSMutableURLRequest *)requestForPackage:(AIActivityPackage *)package { [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setValue:package.clientSdk forHTTPHeaderField:@"Client-Sdk"]; - [request setValue:package.userAgent forHTTPHeaderField:@"User-Agent"]; [request setHTTPBody:[self bodyForParameters:package.parameters]]; return request; diff --git a/Adjust/AIUserAgent.h b/Adjust/AIUserAgent.h new file mode 100644 index 000000000..374b2a246 --- /dev/null +++ b/Adjust/AIUserAgent.h @@ -0,0 +1,22 @@ +// +// AIUserAgent.h +// adjust +// +// Created by Pedro Filipe on 28/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import + +@interface AIUserAgent : NSObject + +@property (nonatomic, copy) NSString *bundeIdentifier; +@property (nonatomic, copy) NSString *bundleVersion; +@property (nonatomic, copy) NSString *deviceType; +@property (nonatomic, copy) NSString *deviceName; +@property (nonatomic, copy) NSString *osName; +@property (nonatomic, copy) NSString *systemVersion; +@property (nonatomic, copy) NSString *languageCode; +@property (nonatomic, copy) NSString *countryCode; + +@end diff --git a/Adjust/AIUserAgent.m b/Adjust/AIUserAgent.m new file mode 100644 index 000000000..15d7433bc --- /dev/null +++ b/Adjust/AIUserAgent.m @@ -0,0 +1,30 @@ +// +// AIUserAgent.m +// adjust +// +// Created by Pedro Filipe on 28/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import "AIUserAgent.h" + +@implementation AIUserAgent + +-(id)copyWithZone:(NSZone *)zone +{ + AIUserAgent * copy = [[[self class] allocWithZone:zone] init]; + if (copy) { + copy.bundeIdentifier = [self.bundeIdentifier copyWithZone:zone]; + copy.bundleVersion = [self.bundleVersion copyWithZone:zone]; + copy.deviceType = [self.deviceType copyWithZone:zone]; + copy.deviceName = [self.deviceName copyWithZone:zone]; + copy.osName = [self.osName copyWithZone:zone]; + copy.systemVersion = [self.systemVersion copyWithZone:zone]; + copy.languageCode = [self.languageCode copyWithZone:zone]; + copy.countryCode = [self.countryCode copyWithZone:zone]; + } + + return copy; +} + +@end diff --git a/Adjust/AIUtil.h b/Adjust/AIUtil.h index 120ab9298..a4d754e18 100644 --- a/Adjust/AIUtil.h +++ b/Adjust/AIUtil.h @@ -6,12 +6,13 @@ // Copyright (c) 2013 adjust GmbH. All rights reserved. // #import +#import "AIUserAgent.h" @interface AIUtil : NSObject + (NSString *)baseUrl; + (NSString *)clientSdk; -+ (NSString *)userAgent; ++ (AIUserAgent *)userAgent; + (void)excludeFromBackup:(NSString *)filename; + (NSString *)dateFormat:(double)value; diff --git a/Adjust/AIUtil.m b/Adjust/AIUtil.m index 6beca8642..0ca199aee 100644 --- a/Adjust/AIUtil.m +++ b/Adjust/AIUtil.m @@ -32,27 +32,24 @@ + (NSString *)clientSdk { return kClientSdk; } -+ (NSString *)userAgent { ++ (AIUserAgent *)userAgent { + + AIUserAgent * userAgent = [[AIUserAgent alloc] init]; + UIDevice *device = UIDevice.currentDevice; NSLocale *locale = NSLocale.currentLocale; NSBundle *bundle = NSBundle.mainBundle; NSDictionary *infoDictionary = bundle.infoDictionary; - NSString *bundeIdentifier = [infoDictionary objectForKey:(NSString *)kCFBundleIdentifierKey]; - NSString *bundleVersion = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]; - NSString *languageCode = [locale objectForKey:NSLocaleLanguageCode]; - NSString *countryCode = [locale objectForKey:NSLocaleCountryCode]; - NSString *osName = @"ios"; - - NSString *userAgent = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ %@ %@", - [self.class sanitizeU:bundeIdentifier], - [self.class sanitizeU:bundleVersion], - [self.class sanitizeU:device.aiDeviceType], - [self.class sanitizeU:device.aiDeviceName], - [self.class sanitizeU:osName], - [self.class sanitizeU:device.systemVersion], - [self.class sanitizeZ:languageCode], - [self.class sanitizeZ:countryCode]]; + userAgent.bundeIdentifier = [infoDictionary objectForKey:(NSString *)kCFBundleIdentifierKey]; + userAgent.bundleVersion = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]; + userAgent.languageCode = [locale objectForKey:NSLocaleLanguageCode]; + userAgent.countryCode = [locale objectForKey:NSLocaleCountryCode]; + userAgent.osName = @"ios"; + + userAgent.deviceType = device.aiDeviceType; + userAgent.deviceName = device.aiDeviceName; + userAgent.systemVersion = device.systemVersion; return userAgent; } diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 3cbe018d3..59e29b069 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -46,14 +46,14 @@ + (void)setEnvironment:(NSString *)environment { if (activityHandler == nil) { [logger error:@"Please call `setEnvironment` after `appDidLaunch`!"]; } else if ([environment isEqualToString:AIEnvironmentSandbox]) { - activityHandler.environment = environment; + [activityHandler setEnvironment:environment]; [logger assert:@"SANDBOX: Adjust is running in Sandbox mode. Use this setting for testing. Don't forget to set the environment to AIEnvironmentProduction before publishing!"]; } else if ([environment isEqualToString:AIEnvironmentProduction]) { - activityHandler.environment = environment; + [activityHandler setEnvironment:environment]; [logger assert:@"PRODUCTION: Adjust is running in Production mode. Use this setting only for the build that you want to publish. Set the environment to AIEnvironmentSandbox if you want to test your app!"]; [logger setLogLevel:AILogLevelAssert]; } else { - activityHandler.environment = @"malformed"; + [activityHandler setEnvironment:@"malformed"]; [logger error:@"Malformed environment '%@'", environment]; } } @@ -64,7 +64,7 @@ + (void)setEventBufferingEnabled:(BOOL)enabled { return; } - activityHandler.bufferEvents = enabled; + [activityHandler setBufferEvents:enabled]; if (enabled) [AIAdjustFactory.logger info:@"Event buffering is enabled"]; } @@ -74,7 +74,7 @@ + (void)setMacMd5TrackingEnabled:(BOOL)enabled { return; } - activityHandler.trackMacMd5 = enabled; + [activityHandler setTrackMacMd5:enabled]; [AIAdjustFactory.logger info:@"Tracking of macMd5 is %@", enabled ? @"enabled" : @"disabled"]; } diff --git a/AdjustTests/AIActivityHandlerMock.m b/AdjustTests/AIActivityHandlerMock.m index 305de4ddf..fc93c344a 100644 --- a/AdjustTests/AIActivityHandlerMock.m +++ b/AdjustTests/AIActivityHandlerMock.m @@ -19,13 +19,13 @@ @interface AIActivityHandlerMock() @end @implementation AIActivityHandlerMock - +/* @synthesize environment; @synthesize bufferEvents; @synthesize trackMacMd5; @synthesize delegate; @synthesize isIad; - +*/ - (id)initWithAppToken:(NSString *)yourAppToken { self = [super init]; if (self == nil) return nil; From f38ba8b9d578aaca1c40b3c7a7833cb4d0d86d12 Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 29 Oct 2014 18:31:25 +0100 Subject: [PATCH 03/86] Attribution changed delegate --- Adjust.xcodeproj/project.pbxproj | 12 ++++ Adjust/AIActivityHandler.h | 8 ++- Adjust/AIActivityHandler.m | 32 ++++++++- Adjust/AIAdjustFactory.h | 13 ++-- Adjust/AIAdjustFactory.m | 16 +++-- Adjust/AIAttribution.h | 40 +++++++++++ Adjust/AIAttribution.m | 117 +++++++++++++++++++++++++++++++ Adjust/AIAttributionHandler.h | 24 +++++++ Adjust/AIAttributionHandler.m | 99 ++++++++++++++++++++++++++ Adjust/Adjust.h | 3 + 10 files changed, 352 insertions(+), 12 deletions(-) create mode 100644 Adjust/AIAttribution.h create mode 100644 Adjust/AIAttribution.m create mode 100644 Adjust/AIAttributionHandler.h create mode 100644 Adjust/AIAttributionHandler.m diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index 947f24443..4b20e35a8 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -19,6 +19,8 @@ 9679922018BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; }; 9679922218BBAE2800394606 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679922118BBAE2800394606 /* UIKit.framework */; }; 9679922518BBAE2800394606 /* libAdjust.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679920D18BBAE2800394606 /* libAdjust.a */; }; + 969952CF1A012F5300928462 /* AIAttributionHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 969952CE1A012F5300928462 /* AIAttributionHandler.m */; }; + 969952D21A01309200928462 /* AIAttribution.m in Sources */ = {isa = PBXBuildFile; fileRef = 969952D11A01309200928462 /* AIAttribution.m */; }; 96CD4478192A546F0029A1AA /* AdjustBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD4473192A546F0029A1AA /* AdjustBridge.m */; }; 96CD4479192A546F0029A1AA /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD4477192A546F0029A1AA /* WebViewJavascriptBridge.m */; }; 96E5E38118BBB48A008E7B30 /* Adjust.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E34D18BBB48A008E7B30 /* Adjust.m */; }; @@ -89,6 +91,10 @@ 9679921D18BBAE2800394606 /* AdjustTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AdjustTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 9679921E18BBAE2800394606 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 9679922118BBAE2800394606 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; + 969952CD1A012F5300928462 /* AIAttributionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIAttributionHandler.h; sourceTree = ""; }; + 969952CE1A012F5300928462 /* AIAttributionHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIAttributionHandler.m; sourceTree = ""; }; + 969952D01A01309200928462 /* AIAttribution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIAttribution.h; sourceTree = ""; }; + 969952D11A01309200928462 /* AIAttribution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIAttribution.m; sourceTree = ""; }; 96ADB109192E0175006E1D9D /* AdjustBridge.js.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AdjustBridge.js.txt; sourceTree = ""; }; 96CD4472192A546F0029A1AA /* AdjustBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdjustBridge.h; sourceTree = ""; }; 96CD4473192A546F0029A1AA /* AdjustBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdjustBridge.m; sourceTree = ""; }; @@ -264,6 +270,10 @@ 965307F51A000DA400107FF9 /* AIDeviceInfo.m */, 9653078119FFD56900107FF9 /* AIUserAgent.h */, 965307F71A000DCC00107FF9 /* AIUserAgent.m */, + 969952CD1A012F5300928462 /* AIAttributionHandler.h */, + 969952CE1A012F5300928462 /* AIAttributionHandler.m */, + 969952D01A01309200928462 /* AIAttribution.h */, + 969952D11A01309200928462 /* AIAttribution.m */, ); path = Adjust; sourceTree = ""; @@ -399,6 +409,8 @@ 96E5E38C18BBB48A008E7B30 /* AIActivityKind.m in Sources */, 96E5E38D18BBB48A008E7B30 /* AIActivityPackage.m in Sources */, 965307F61A000DA400107FF9 /* AIDeviceInfo.m in Sources */, + 969952D21A01309200928462 /* AIAttribution.m in Sources */, + 969952CF1A012F5300928462 /* AIAttributionHandler.m in Sources */, 96E5E38E18BBB48A008E7B30 /* AIActivityState.m in Sources */, 96E5E39018BBB48A008E7B30 /* NSString+AIAdditions.m in Sources */, 9609BC6A19EEA55800E02303 /* AIEvent.m in Sources */, diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index 244c8c95d..e7ba0572b 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -7,8 +7,9 @@ // #import "Adjust.h" +#import "AIAttribution.h" -@protocol AIActivityHandler +@protocol AIActivityHandler - (id)initWithAppToken:(NSString *)appToken; - (void)setSdkPrefix:(NSString *)sdkPrefix; @@ -30,6 +31,11 @@ - (void)setDelegate:(NSObject *) delegate; - (void)setIsIad:(BOOL)isIad; +- (AIAttribution*) attribution; +- (void) setAttribution:(AIAttribution*)attribution; + +- (void) changedAttributionDelegate:(AIAttribution*) attribution; + @end @interface AIActivityHandler : NSObject diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index c49934991..79f1c187f 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -17,6 +17,7 @@ #import "UIDevice+AIAdditions.h" #import "NSString+AIAdditions.h" #import "AIAdjustFactory.h" +#import "AIAttributionHandler.h" static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; @@ -35,10 +36,13 @@ @interface AIActivityHandler() @property (nonatomic, retain) AIActivityState *activityState; @property (nonatomic, retain) AITimer *timer; @property (nonatomic, retain) id logger; +@property (nonatomic, retain) NSObject *delegate; +@property (nonatomic, retain) id attributionHandler; +@property (nonatomic, retain) AIAttribution *attribution; + @property (nonatomic, assign) BOOL enabled; @property (nonatomic, assign) BOOL bufferEvents; @property (nonatomic, assign) BOOL trackMacMd5; -@property (nonatomic, retain) NSObject *delegate; @property (nonatomic, copy) AIDeviceInfo* deviceInfo; @@ -68,6 +72,9 @@ - (id)initWithAppToken:(NSString *)yourAppToken { _trackMacMd5 = YES; _enabled = YES; + //self.attributionInternal = nil; + // todo read from file + dispatch_async(self.internalQueue, ^{ [self initInternal:yourAppToken]; }); @@ -182,7 +189,28 @@ - (void)setDelegate:(NSObject *) delegate { - (void)setIsIad:(BOOL)isIad { self.deviceInfo.isIad = isIad; } +/* +- (AIAttribution*) attribution { + return self.attribution; +} + +- (void) setAttribution:(AIAttribution*)attribution { + _attribution = attribution; +} +*/ + +- (void)changedAttributionDelegate:(AIAttribution *)attribution { + if (![self.delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { + return; + } + if (attribution == nil) { + return; + } + self.attribution = attribution; + [self.delegate performSelectorOnMainThread:@selector(adjustAttributionChanged:) + withObject:attribution waitUntilDone:NO]; +} #pragma mark - internal - (void)initInternal:(NSString *)yourAppToken { @@ -204,6 +232,8 @@ - (void)initInternal:(NSString *)yourAppToken { [[UIDevice currentDevice] aiSetIad:self]; self.packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:self]; + self.attributionHandler = [AIAdjustFactory attributionHandlerForActivityHandler:self]; + [self readActivityState]; [self startInternal]; diff --git a/Adjust/AIAdjustFactory.h b/Adjust/AIAdjustFactory.h index d666b9436..faad1656f 100644 --- a/Adjust/AIAdjustFactory.h +++ b/Adjust/AIAdjustFactory.h @@ -7,12 +7,11 @@ // #import -@class Adjust; - -@protocol AIPackageHandler; -@protocol AIRequestHandler; -@protocol AIActivityHandler; -@protocol AILogger; +#import "AIActivityHandler.h" +#import "AIPackageHandler.h" +#import "AIRequestHandler.h" +#import "AILogger.h" +#import "AIAttributionHandler.h" @interface AIAdjustFactory : NSObject @@ -22,6 +21,7 @@ + (id)logger; + (double)sessionInterval; + (double)subsessionInterval; ++ (id)attributionHandlerForActivityHandler:(id)activityHandler; + (void)setPackageHandler:(id)packageHandler; + (void)setRequestHandler:(id)requestHandler; @@ -29,5 +29,6 @@ + (void)setLogger:(id)logger; + (void)setSessionInterval:(double)sessionInterval; + (void)setSubsessionInterval:(double)subsessionInterval; ++ (void)setAttributionHandler:(id)attributionHandler; @end diff --git a/Adjust/AIAdjustFactory.m b/Adjust/AIAdjustFactory.m index adfbf8294..79b18efa9 100644 --- a/Adjust/AIAdjustFactory.m +++ b/Adjust/AIAdjustFactory.m @@ -7,15 +7,12 @@ // #import "AIAdjustFactory.h" -#import "AIActivityHandler.h" -#import "AIPackageHandler.h" -#import "AIRequestHandler.h" -#import "AILogger.h" static id internalPackageHandler = nil; static id internalRequestHandler = nil; static id internalActivityHandler = nil; static id internalLogger = nil; +static id internalAttributionHandler = nil; static double internalSessionInterval = -1; static double intervalSubsessionInterval = -1; @@ -66,6 +63,14 @@ + (double)subsessionInterval { return intervalSubsessionInterval; } ++ (id)attributionHandlerForActivityHandler:(id)activityHandler { + if (internalAttributionHandler == nil) { + return [AIAttributionHandler handlerWithActivityHandler:activityHandler]; + } + + return [internalAttributionHandler initWithActivityHandler:activityHandler]; +} + + (void)setPackageHandler:(id)packageHandler { internalPackageHandler = packageHandler; } @@ -90,4 +95,7 @@ + (void)setSubsessionInterval:(double)subsessionInterval { intervalSubsessionInterval = subsessionInterval; } ++ (void)setAttributionHandler:(id)attributionHandler { + internalAttributionHandler = attributionHandler; +} @end diff --git a/Adjust/AIAttribution.h b/Adjust/AIAttribution.h new file mode 100644 index 000000000..2e865a452 --- /dev/null +++ b/Adjust/AIAttribution.h @@ -0,0 +1,40 @@ +// +// AIAttribution.h +// adjust +// +// Created by Pedro Filipe on 29/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import + +@interface AIAttribution : NSObject + +// the following attributes are only set when error is nil +// (when activity was tracked successfully and response could be parsed) + +// tracker token of current device +@property (nonatomic, copy) NSString *trackerToken; + +// tracker name of current device +@property (nonatomic, copy) NSString *trackerName; + +// tracker network +@property (nonatomic, copy) NSString *network; + +// tracker campaign +@property (nonatomic, copy) NSString *campaign; + +// tracker adgroup +@property (nonatomic, copy) NSString *adgroup; + +// tracker creative +@property (nonatomic, copy) NSString *creative; + +- (BOOL)isEqualToAttribution:(AIAttribution *)attribution; + ++ (AIAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict; +- (id)initWithJsonDict:(NSDictionary *)jsonDict; +- (NSDictionary *)dictionary; + +@end diff --git a/Adjust/AIAttribution.m b/Adjust/AIAttribution.m new file mode 100644 index 000000000..9c281799a --- /dev/null +++ b/Adjust/AIAttribution.m @@ -0,0 +1,117 @@ +// +// AIAttribution.m +// adjust +// +// Created by Pedro Filipe on 29/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import "AIAttribution.h" + +@implementation AIAttribution + +- (BOOL)isEqualToAttribution:(AIAttribution *)attribution { + if (attribution == nil) { + return NO; + } + if (![self.trackerToken isEqualToString:attribution.trackerToken]) { + return NO; + } + if (![self.trackerName isEqualToString:attribution.trackerName]) { + return NO; + } + if (![self.network isEqualToString:attribution.network]) { + return NO; + } + if (![self.campaign isEqualToString:attribution.campaign]) { + return NO; + } + if (![self.adgroup isEqualToString:attribution.adgroup]) { + return NO; + } + if (![self.creative isEqualToString:attribution.creative]) { + return NO; + } + return YES; +} + ++ (AIAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict { + return [[AIAttribution alloc] initWithJsonDict:jsonDict]; +} + +- (id)initWithJsonDict:(NSDictionary *)jsonDict { + self = [super init]; + if (self == nil) return nil; + + if (jsonDict == nil) { + return nil; + } + + self.trackerToken = [jsonDict objectForKey:@"tracker_token"]; + self.trackerName = [jsonDict objectForKey:@"tracker_name"]; + self.network = [jsonDict objectForKey:@"network"]; + self.campaign = [jsonDict objectForKey:@"campaign"]; + self.adgroup = [jsonDict objectForKey:@"adgroup"]; + self.creative = [jsonDict objectForKey:@"creative"]; + + return self; +} + +- (NSDictionary *)dictionary { + NSMutableDictionary * responseDataDic = [NSMutableDictionary dictionary]; + + if (self.trackerToken != nil) { + [responseDataDic setObject:self.trackerToken forKey:@"trackerToken"]; + } + + if (self.trackerName != nil) { + [responseDataDic setObject:self.trackerName forKey:@"trackerName"]; + } + + if (self.network != nil) { + [responseDataDic setObject:self.network forKey:@"network"]; + } + + if (self.campaign != nil) { + [responseDataDic setObject:self.campaign forKey:@"campaign"]; + } + + if (self.adgroup != nil) { + [responseDataDic setObject:self.adgroup forKey:@"adgroup"]; + } + + if (self.creative != nil) { + [responseDataDic setObject:self.creative forKey:@"creative"]; + } + + return responseDataDic; +} + +#pragma mark - NSObject +- (BOOL)isEqual:(id)object { + if (self == object) { + return YES; + } + + if (![object isKindOfClass:[AIAttribution class]]) { + return NO; + } + + return [self isEqualToAttribution:(AIAttribution *)object]; +} + +- (NSUInteger)hash { + NSUInteger prime = 31; + NSUInteger result = 1; + + result = prime * result + [self.trackerToken hash]; + result = prime * result + [self.trackerName hash]; + result = prime * result + [self.network hash]; + result = prime * result + [self.campaign hash]; + result = prime * result + [self.adgroup hash]; + result = prime * result + [self.creative hash]; + + return result; +} + +@end diff --git a/Adjust/AIAttributionHandler.h b/Adjust/AIAttributionHandler.h new file mode 100644 index 000000000..ee356b721 --- /dev/null +++ b/Adjust/AIAttributionHandler.h @@ -0,0 +1,24 @@ +// +// AIAttributionHandler.h +// adjust +// +// Created by Pedro Filipe on 29/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import +#import "AIActivityHandler.h" + +@protocol AIAttributionHandler + +- (id)initWithActivityHandler:(id) activityHandler; + +- (void)checkAttribution; + +@end + +@interface AIAttributionHandler : NSObject + ++ (id)handlerWithActivityHandler:(id)activityHandler; + +@end diff --git a/Adjust/AIAttributionHandler.m b/Adjust/AIAttributionHandler.m new file mode 100644 index 000000000..28866cc1b --- /dev/null +++ b/Adjust/AIAttributionHandler.m @@ -0,0 +1,99 @@ +// +// AIAttributionHandler.m +// adjust +// +// Created by Pedro Filipe on 29/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import "AIAttributionHandler.h" +#import "AIAdjustFactory.h" +#import "AIUtil.h" +#import "AIActivityHandler.h" +#import "NSString+AIAdditions.h" + +@interface AIAttributionHandler() + +@property (nonatomic) dispatch_queue_t internalQueue; +@property (nonatomic, assign) id activityHandler; +@property (nonatomic, assign) id logger; +@property (nonatomic, retain) NSURL *url; + +@end + +static const double kRequestTimeout = 60; // 60 seconds + +@implementation AIAttributionHandler + ++ (id)handlerWithActivityHandler:(id)activityHandler { + return [[AIAttributionHandler alloc] initWithActivityHandler:activityHandler]; +} + +- (id)initWithActivityHandler:(id) activityHandler { + self = [super init]; + if (self == nil) return nil; + + self.internalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0); + self.activityHandler = activityHandler; + self.logger = AIAdjustFactory.logger; + self.url = [NSURL URLWithString:AIUtil.baseUrl]; + //TODO change baseURL + + return self; +} +// comunicate with server +- (void) checkAttribution { + dispatch_async(self.internalQueue, ^{ + [self checkAttribution]; + }); +} + +#pragma mark - internal +-(void) checkAttributionInternal { + NSMutableURLRequest *request = [self request]; + NSError *requestError; + NSURLResponse *urlResponse = nil; + + NSData *response = [NSURLConnection sendSynchronousRequest:request + returningResponse:&urlResponse + error:&requestError]; + // connection error + if (requestError != nil) { + [self.logger error:@"Failed to get attribution. (%@)", requestError.localizedDescription]; + return; + } + + NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; + NSDictionary *jsonDict = [AIUtil buildJsonDict:responseString]; + + if (jsonDict == nil) { + [self.logger error:@"Failed to parse json attribution response: %@", responseString.aiTrim]; + return; + } + + // check if response contains attribution + AIAttribution * attributionResponse = [AIAttribution dataWithJsonDict:jsonDict]; + + // if it doesn't set timer + + // check if new attribution is different from previous + if ([attributionResponse isEqual:self.activityHandler.attribution]) { + // TODO reset? + return; + } + + // if so, launch response delegate + [self.activityHandler changedAttributionDelegate:attributionResponse]; +} + +#pragma mark - private + +- (NSMutableURLRequest *)request { + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.url]; + request.timeoutInterval = kRequestTimeout; + request.HTTPMethod = @"GET"; + + return request; +} + +@end diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index 513df1f58..abb6e3927 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -9,6 +9,7 @@ #import "AILogger.h" #import "AIResponseData.h" #import "AIEvent.h" +#import "AIAttribution.h" @protocol AdjustDelegate; @@ -173,4 +174,6 @@ static NSString * const AIEnvironmentProduction = @"production"; */ - (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData; +- (void)adjustAttributionChanged:(AIAttribution *)attribution; + @end From b2a5e78e61917bcb16ed3476270518c7ffcb726e Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 30 Oct 2014 16:06:46 +0100 Subject: [PATCH 04/86] Retry attribution update --- Adjust/AIActivityHandler.h | 1 + Adjust/AIActivityHandler.m | 83 ++++++++++++++++++----------------- Adjust/AIActivityState.h | 4 +- Adjust/AIAttribution.h | 2 +- Adjust/AIAttribution.m | 33 ++++++++++++++ Adjust/AIAttributionHandler.h | 4 +- Adjust/AIAttributionHandler.m | 23 +++++++--- Adjust/AIRequestHandler.h | 4 +- Adjust/AIRequestHandler.m | 2 - Adjust/AITimer.h | 10 +++++ Adjust/AITimer.m | 20 +++++++++ Adjust/AIUtil.h | 2 + Adjust/AIUtil.m | 8 ++++ Adjust/Adjust.h | 4 +- Adjust/Adjust.m | 4 ++ 15 files changed, 149 insertions(+), 55 deletions(-) diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index e7ba0572b..28209c721 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -30,6 +30,7 @@ - (void)setTrackMacMd5:(BOOL)trackMacMd5; - (void)setDelegate:(NSObject *) delegate; - (void)setIsIad:(BOOL)isIad; +- (void)setAttributionMaxTime:(double)seconds; - (AIAttribution*) attribution; - (void) setAttribution:(AIAttribution*)attribution; diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index 79f1c187f..da49039c5 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -21,6 +21,7 @@ static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; +static NSString * const kAttributionFilename = @"AdjustIoAttribution"; static NSString * const kAdjustPrefix = @"adjust_"; static const char * const kInternalQueueName = "io.adjust.ActivityQueue"; @@ -106,20 +107,10 @@ - (void)trackEvent:(AIEvent *)event } - (void)finishedTrackingWithResponse:(AIResponseData *)response deepLink:(NSString *)deepLink{ - [self runDelegate:response]; - [self launchDeepLink:deepLink]; -} - -- (void)runDelegate:(AIResponseData *)response { - if (![self.delegate respondsToSelector:@selector(adjustFinishedTrackingWithResponse:)]) { - return; + if (self.attribution == nil) { + [self.attributionHandler getAttribution]; } - if (response == nil) { - return; - } - [self.delegate performSelectorOnMainThread:@selector(adjustFinishedTrackingWithResponse:) - withObject:response waitUntilDone:NO]; - + [self launchDeepLink:deepLink]; } - (void)launchDeepLink:(NSString *) deepLink{ @@ -189,6 +180,11 @@ - (void)setDelegate:(NSObject *) delegate { - (void)setIsIad:(BOOL)isIad { self.deviceInfo.isIad = isIad; } + +- (void)setAttributionMaxTime:(double)seconds { + [self.attributionHandler setAttributionMaxTime:seconds]; +} + /* - (AIAttribution*) attribution { return self.attribution; @@ -422,7 +418,7 @@ - (BOOL)updateActivityState:(double)now { - (void)readActivityState { @try { - NSString *filename = self.activityStateFilename; + NSString *filename = [AIUtil getFullFilename:kActivityStateFilename]; id object = [NSKeyedUnarchiver unarchiveObjectWithFile:filename]; if ([object isKindOfClass:[AIActivityState class]]) { self.activityState = object; @@ -442,7 +438,7 @@ - (void)readActivityState { } - (void)writeActivityState { - NSString *filename = self.activityStateFilename; + NSString *filename = [AIUtil getFullFilename:kActivityStateFilename]; BOOL result = [NSKeyedArchiver archiveRootObject:self.activityState toFile:filename]; if (result == YES) { [AIUtil excludeFromBackup:filename]; @@ -452,16 +448,42 @@ - (void)writeActivityState { } } -- (NSString *)activityStateFilename { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *path = [paths objectAtIndex:0]; - NSString *filename = [path stringByAppendingPathComponent:kActivityStateFilename]; - return filename; + +- (void)readAttribution { + @try { + NSString *filename = [AIUtil getFullFilename:kAttributionFilename]; + id object = [NSKeyedUnarchiver unarchiveObjectWithFile:filename]; + if ([object isKindOfClass:[AIAttribution class]]) { + self.activityState = object; + [self.logger debug:@"Read attribution: %@", self.attribution]; + return; + } else if (object == nil) { + [self.logger verbose:@"Attribution file not found"]; + } else { + [self.logger error:@"Failed to read attribution file"]; + } + } @catch (NSException *ex ) { + [self.logger error:@"Failed to read attribution file (%@)", ex]; + } + + // start with a fresh activity state in case of any exception + self.attribution = nil; +} + +- (void)writeAttribution { + NSString *filename = [AIUtil getFullFilename:kAttributionFilename]; + BOOL result = [NSKeyedArchiver archiveRootObject:self.attribution toFile:filename]; + if (result == YES) { + [AIUtil excludeFromBackup:filename]; + [self.logger debug:@"Wrote attribution: %@", self.attribution]; + } else { + [self.logger error:@"Failed to write attribution file"]; + } } + - (void)transferSessionPackage { AIPackageBuilder *sessionBuilder = [[AIPackageBuilder alloc] init]; - //[self injectGeneralAttributes:sessionBuilder]; sessionBuilder.deviceInfo = self.deviceInfo; sessionBuilder.trackMd5 = _trackMacMd5; [self.activityState injectSessionAttributes:sessionBuilder]; @@ -470,25 +492,6 @@ - (void)transferSessionPackage { [self.packageHandler sendFirstPackage]; } -/* -- (void)injectGeneralAttributes:(AIPackageBuilder *)builder { - builder.userAgent = self.userAgent; - builder.clientSdk = self.clientSdk; - builder.appToken = self.appToken; - builder.macSha1 = self.macSha1; - builder.trackingEnabled = self.trackingEnabled; - builder.idForAdvertisers = self.idForAdvertisers; - builder.fbAttributionId = self.fbAttributionId; - builder.environment = self.environment; - builder.isIad = self.isIad; - builder.vendorId = self.vendorId; - builder.pushToken = self.pushToken; - - if (self.trackMacMd5) { - builder.macShortMd5 = self.macShortMd5; - } -} -*/ # pragma mark - timer - (void)startTimer { if (self.timer == nil) { diff --git a/Adjust/AIActivityState.h b/Adjust/AIActivityState.h index a8ebfd7c8..230b823c8 100644 --- a/Adjust/AIActivityState.h +++ b/Adjust/AIActivityState.h @@ -34,8 +34,8 @@ - (void)resetSessionAttributes:(double)now; -- (void)injectSessionAttributes:(AIPackageBuilder *)packageBilder; -- (void)injectEventAttributes:(AIPackageBuilder *)packageBilder; +- (void)injectSessionAttributes:(AIPackageBuilder *)packageBuilder; +- (void)injectEventAttributes:(AIPackageBuilder *)packageBuilder; // transaction ID management - (void)addTransactionId:(NSString *)transactionId; diff --git a/Adjust/AIAttribution.h b/Adjust/AIAttribution.h index 2e865a452..3147ca5e3 100644 --- a/Adjust/AIAttribution.h +++ b/Adjust/AIAttribution.h @@ -8,7 +8,7 @@ #import -@interface AIAttribution : NSObject +@interface AIAttribution : NSObject // the following attributes are only set when error is nil // (when activity was tracked successfully and response could be parsed) diff --git a/Adjust/AIAttribution.m b/Adjust/AIAttribution.m index 9c281799a..43eb8fe12 100644 --- a/Adjust/AIAttribution.m +++ b/Adjust/AIAttribution.m @@ -87,6 +87,13 @@ - (NSDictionary *)dictionary { return responseDataDic; } +- (NSString *)description { + return [NSString stringWithFormat:@"tt:%@ tn:%@ net:%@ cam:%@ adg:%@ cre:%@", + self.trackerToken, self.trackerName, self.network, self.campaign, + self.adgroup, self.campaign]; +} + + #pragma mark - NSObject - (BOOL)isEqual:(id)object { if (self == object) { @@ -114,4 +121,30 @@ - (NSUInteger)hash { return result; } +#pragma mark NSCoding + +- (id)initWithCoder:(NSCoder *)decoder { + self = [super init]; + if (self == nil) return nil; + + self.trackerToken = [decoder decodeObjectForKey:@"trackerToken"]; + self.trackerName = [decoder decodeObjectForKey:@"trackerName"]; + self.network = [decoder decodeObjectForKey:@"network"]; + self.campaign = [decoder decodeObjectForKey:@"campaign"]; + self.adgroup = [decoder decodeObjectForKey:@"adgroup"]; + self.creative = [decoder decodeObjectForKey:@"creative"]; + + return self; +} + +- (void)encodeWithCoder:(NSCoder *)encoder { + [encoder encodeObject:self.trackerToken forKey:@"trackerToken"]; + [encoder encodeObject:self.trackerName forKey:@"trackerName"]; + [encoder encodeObject:self.network forKey:@"network"]; + [encoder encodeObject:self.campaign forKey:@"campaign"]; + [encoder encodeObject:self.adgroup forKey:@"adgroup"]; + [encoder encodeObject:self.creative forKey:@"creative"]; +} + + @end diff --git a/Adjust/AIAttributionHandler.h b/Adjust/AIAttributionHandler.h index ee356b721..f029632e5 100644 --- a/Adjust/AIAttributionHandler.h +++ b/Adjust/AIAttributionHandler.h @@ -13,7 +13,9 @@ - (id)initWithActivityHandler:(id) activityHandler; -- (void)checkAttribution; +- (void)getAttribution; + +- (void)setAttributionMaxTime:(double)seconds; @end diff --git a/Adjust/AIAttributionHandler.m b/Adjust/AIAttributionHandler.m index 28866cc1b..c5596161d 100644 --- a/Adjust/AIAttributionHandler.m +++ b/Adjust/AIAttributionHandler.m @@ -11,6 +11,9 @@ #import "AIUtil.h" #import "AIActivityHandler.h" #import "NSString+AIAdditions.h" +#import "AITimer.h" + +static const uint64_t kTimerLeeway = 1 * NSEC_PER_SEC; // 1 second @interface AIAttributionHandler() @@ -18,6 +21,8 @@ @interface AIAttributionHandler() @property (nonatomic, assign) id activityHandler; @property (nonatomic, assign) id logger; @property (nonatomic, retain) NSURL *url; +@property (nonatomic, retain) AITimer *timer; +@property (nonatomic, assign) double attributionMaxTime; @end @@ -42,9 +47,9 @@ - (id)initWithActivityHandler:(id) activityHandler { return self; } // comunicate with server -- (void) checkAttribution { +- (void) getAttribution { dispatch_async(self.internalQueue, ^{ - [self checkAttribution]; + [self getAttribution]; }); } @@ -72,11 +77,19 @@ -(void) checkAttributionInternal { } // check if response contains attribution - AIAttribution * attributionResponse = [AIAttribution dataWithJsonDict:jsonDict]; - - // if it doesn't set timer + NSDictionary *jsonAttribution = [jsonDict objectForKey:@"attribution"]; + if (jsonAttribution == nil) { + // read time to wait and set timer to re-try + NSNumber * timer_seconds = [jsonDict objectForKey:@"timer"]; + uint64_t timer_nano = [timer_seconds intValue] * NSEC_PER_SEC; + self.timer = [AITimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self checkAttributionInternal]; }]; + [self.timer resume]; + return; + } // check if new attribution is different from previous + AIAttribution * attributionResponse = [AIAttribution dataWithJsonDict:jsonAttribution]; + if ([attributionResponse isEqual:self.activityHandler.attribution]) { // TODO reset? return; diff --git a/Adjust/AIRequestHandler.h b/Adjust/AIRequestHandler.h index 18c71ce4a..e648e027a 100644 --- a/Adjust/AIRequestHandler.h +++ b/Adjust/AIRequestHandler.h @@ -7,8 +7,8 @@ // #import -#include "AIPackageHandler.h" -@class AIPackageHandler, AIActivityPackage; +#import "AIRequestHandler.h" +#import "AIPackageHandler.h" @protocol AIRequestHandler diff --git a/Adjust/AIRequestHandler.m b/Adjust/AIRequestHandler.m index bae24183d..70fcfd6b1 100644 --- a/Adjust/AIRequestHandler.m +++ b/Adjust/AIRequestHandler.m @@ -6,8 +6,6 @@ // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AIRequestHandler.h" -#import "AIPackageHandler.h" #import "AIActivityPackage.h" #import "AIResponseData.h" #import "AILogger.h" diff --git a/Adjust/AITimer.h b/Adjust/AITimer.h index a09d27e22..104dd0597 100644 --- a/Adjust/AITimer.h +++ b/Adjust/AITimer.h @@ -14,11 +14,21 @@ queue:(dispatch_queue_t)queue block:(dispatch_block_t)block; ++ (AITimer *)timerWithStart:(uint64_t)start + leeway:(uint64_t)leeway + queue:(dispatch_queue_t)queue + block:(dispatch_block_t)block; + - (id)initWithInterval:(uint64_t)interval leeway:(uint64_t)leeway queue:(dispatch_queue_t)queue block:(dispatch_block_t)block; +- (id)initWithStart:(uint64_t)start + leeway:(uint64_t)leeway + queue:(dispatch_queue_t)queue + block:(dispatch_block_t)block; + - (void)resume; - (void)suspend; diff --git a/Adjust/AITimer.m b/Adjust/AITimer.m index d513af940..bfe19587a 100644 --- a/Adjust/AITimer.m +++ b/Adjust/AITimer.m @@ -28,6 +28,11 @@ + (AITimer *)timerWithInterval:(uint64_t)interval return [[AITimer alloc] initWithInterval:interval leeway:leeway queue:queue block:block]; } ++ (AITimer *)timerWithStart:(uint64_t)start leeway:(uint64_t)leeway queue:(dispatch_queue_t)queue block:(dispatch_block_t)block +{ + return [[AITimer alloc] initWithStart:start leeway:leeway queue:queue block:block]; +} + - (id)initWithInterval:(uint64_t)interval leeway:(uint64_t)leeway queue:(dispatch_queue_t)queue @@ -46,6 +51,21 @@ - (id)initWithInterval:(uint64_t)interval return self; } +- (id)initWithStart:(uint64_t)start leeway:(uint64_t)leeway queue:(dispatch_queue_t)queue block:(dispatch_block_t)block +{ + self = [super init]; + if (self == nil) return nil; + + self.source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); + if (self.source != nil) { + dispatch_source_set_timer(self.source, dispatch_walltime(NULL, start), DISPATCH_TIME_FOREVER, leeway); + dispatch_source_set_event_handler(self.source, block); + } + self.suspended = YES; + + return self; +} + - (void)resume { if (!self.suspended) return; diff --git a/Adjust/AIUtil.h b/Adjust/AIUtil.h index a4d754e18..984554313 100644 --- a/Adjust/AIUtil.h +++ b/Adjust/AIUtil.h @@ -18,4 +18,6 @@ + (NSString *)dateFormat:(double)value; + (NSDictionary *) buildJsonDict:(NSString *)jsonString; ++ (NSString *)getFullFilename:(NSString *) baseFilename; + @end diff --git a/Adjust/AIUtil.m b/Adjust/AIUtil.m index 0ca199aee..22814118f 100644 --- a/Adjust/AIUtil.m +++ b/Adjust/AIUtil.m @@ -134,4 +134,12 @@ + (NSDictionary *)buildJsonDict:(NSString *)jsonString { return jsonDict; } ++ (NSString *)getFullFilename:(NSString *) baseFilename { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *path = [paths objectAtIndex:0]; + NSString *filename = [path stringByAppendingPathComponent:baseFilename]; + return filename; +} + + @end diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index abb6e3927..bf1b89b9c 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -153,6 +153,8 @@ static NSString * const AIEnvironmentProduction = @"production"; */ + (void)setDeviceToken:(NSData *)deviceToken; ++ (void)setAttributionMaxTime:(double)seconds; + @end @@ -172,8 +174,6 @@ static NSString * const AIEnvironmentProduction = @"production"; * @param responseData The response data containing information about the activity * and it's server response. See AIResponseData for details. */ -- (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData; - - (void)adjustAttributionChanged:(AIAttribution *)attribution; @end diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 59e29b069..9c78a2065 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -102,4 +102,8 @@ + (void)setDeviceToken:(NSData *)deviceToken { [activityHandler savePushToken:deviceToken]; } ++ (void)setAttributionMaxTime:(double)seconds { + [activityHandler setAttributionMaxTime:seconds]; +} + @end From 5f2a87655ad994ba7657943949c22bc7b3346cd7 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 31 Oct 2014 17:12:03 +0100 Subject: [PATCH 05/86] Launch time configuration --- Adjust.xcodeproj/project.pbxproj | 14 ++-- Adjust/AIActivityHandler.h | 12 +-- Adjust/AIActivityHandler.m | 103 ++++++++++-------------- Adjust/AIActivityState.h | 5 +- Adjust/AIActivityState.m | 29 ++++--- Adjust/AIAdditions/NSData+AIAdditions.h | 14 ---- Adjust/AIAdditions/NSData+AIAdditions.m | 64 --------------- Adjust/AIAdjustFactory.h | 2 +- Adjust/AIAdjustFactory.m | 6 +- Adjust/AIAttribution.m | 1 - Adjust/AIDeviceInfo.h | 9 +-- Adjust/AIDeviceInfo.m | 6 +- Adjust/AIEvent.m | 1 - Adjust/AIPackageBuilder.h | 19 +---- Adjust/AIPackageBuilder.m | 76 ++++++++++------- Adjust/Adjust.h | 83 +------------------ Adjust/Adjust.m | 58 +------------ Adjust/AdjustConfig.h | 52 ++++++++++++ Adjust/AdjustConfig.m | 93 +++++++++++++++++++++ 19 files changed, 277 insertions(+), 370 deletions(-) delete mode 100644 Adjust/AIAdditions/NSData+AIAdditions.h delete mode 100644 Adjust/AIAdditions/NSData+AIAdditions.m create mode 100644 Adjust/AdjustConfig.h create mode 100644 Adjust/AdjustConfig.m diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index 4b20e35a8..e089abe34 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 9609BC6A19EEA55800E02303 /* AIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 9609BC6919EEA55800E02303 /* AIEvent.m */; }; + 960A8BB91A029A8000F2BB95 /* AdjustConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 960A8BB81A029A8000F2BB95 /* AdjustConfig.m */; }; 96325E89190E892000A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8A190E892600A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8B190E8D6200A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; @@ -28,7 +29,6 @@ 96E5E38C18BBB48A008E7B30 /* AIActivityKind.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36518BBB48A008E7B30 /* AIActivityKind.m */; }; 96E5E38D18BBB48A008E7B30 /* AIActivityPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36718BBB48A008E7B30 /* AIActivityPackage.m */; }; 96E5E38E18BBB48A008E7B30 /* AIActivityState.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36918BBB48A008E7B30 /* AIActivityState.m */; }; - 96E5E38F18BBB48A008E7B30 /* NSData+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36C18BBB48A008E7B30 /* NSData+AIAdditions.m */; }; 96E5E39018BBB48A008E7B30 /* NSString+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36E18BBB48A008E7B30 /* NSString+AIAdditions.m */; }; 96E5E39118BBB48A008E7B30 /* UIDevice+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37018BBB48A008E7B30 /* UIDevice+AIAdditions.m */; }; 96E5E39218BBB48A008E7B30 /* AIAdjustFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37218BBB48A008E7B30 /* AIAdjustFactory.m */; }; @@ -51,7 +51,6 @@ 96E5E3B818BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3AD18BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m */; }; 96E5E3B918BBB75F008E7B30 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921E18BBAE2800394606 /* XCTest.framework */; }; 96E5E3BB18BBB989008E7B30 /* NSString+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36E18BBB48A008E7B30 /* NSString+AIAdditions.m */; }; - 96E5E3BC18BBB98C008E7B30 /* NSData+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36C18BBB48A008E7B30 /* NSData+AIAdditions.m */; }; 96E5E3BD18BBB992008E7B30 /* UIDevice+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37018BBB48A008E7B30 /* UIDevice+AIAdditions.m */; }; /* End PBXBuildFile section */ @@ -80,6 +79,8 @@ /* Begin PBXFileReference section */ 9609BC6819EEA55800E02303 /* AIEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIEvent.h; sourceTree = ""; }; 9609BC6919EEA55800E02303 /* AIEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIEvent.m; sourceTree = ""; }; + 960A8BB71A029A8000F2BB95 /* AdjustConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdjustConfig.h; sourceTree = ""; }; + 960A8BB81A029A8000F2BB95 /* AdjustConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdjustConfig.m; sourceTree = ""; }; 96325E84190E5CD900A97911 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 96325E86190E5CE400A97911 /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iAd.framework; path = System/Library/Frameworks/iAd.framework; sourceTree = SDKROOT; }; 9644B7EA19F148F3008576FC /* AIDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIDeviceInfo.h; sourceTree = ""; }; @@ -111,8 +112,6 @@ 96E5E36718BBB48A008E7B30 /* AIActivityPackage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIActivityPackage.m; sourceTree = ""; }; 96E5E36818BBB48A008E7B30 /* AIActivityState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIActivityState.h; sourceTree = ""; }; 96E5E36918BBB48A008E7B30 /* AIActivityState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIActivityState.m; sourceTree = ""; }; - 96E5E36B18BBB48A008E7B30 /* NSData+AIAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+AIAdditions.h"; sourceTree = ""; }; - 96E5E36C18BBB48A008E7B30 /* NSData+AIAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+AIAdditions.m"; sourceTree = ""; }; 96E5E36D18BBB48A008E7B30 /* NSString+AIAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+AIAdditions.h"; sourceTree = ""; }; 96E5E36E18BBB48A008E7B30 /* NSString+AIAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+AIAdditions.m"; sourceTree = ""; }; 96E5E36F18BBB48A008E7B30 /* UIDevice+AIAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+AIAdditions.h"; sourceTree = ""; }; @@ -274,6 +273,8 @@ 969952CE1A012F5300928462 /* AIAttributionHandler.m */, 969952D01A01309200928462 /* AIAttribution.h */, 969952D11A01309200928462 /* AIAttribution.m */, + 960A8BB71A029A8000F2BB95 /* AdjustConfig.h */, + 960A8BB81A029A8000F2BB95 /* AdjustConfig.m */, ); path = Adjust; sourceTree = ""; @@ -281,8 +282,6 @@ 96E5E36A18BBB48A008E7B30 /* AIAdditions */ = { isa = PBXGroup; children = ( - 96E5E36B18BBB48A008E7B30 /* NSData+AIAdditions.h */, - 96E5E36C18BBB48A008E7B30 /* NSData+AIAdditions.m */, 96E5E36D18BBB48A008E7B30 /* NSString+AIAdditions.h */, 96E5E36E18BBB48A008E7B30 /* NSString+AIAdditions.m */, 96E5E36F18BBB48A008E7B30 /* UIDevice+AIAdditions.h */, @@ -404,7 +403,6 @@ 96E5E39918BBB48A008E7B30 /* AIUtil.m in Sources */, 96E5E39818BBB48A008E7B30 /* AITimer.m in Sources */, 96E5E39718BBB48A008E7B30 /* AIResponseData.m in Sources */, - 96E5E38F18BBB48A008E7B30 /* NSData+AIAdditions.m in Sources */, 96E5E39118BBB48A008E7B30 /* UIDevice+AIAdditions.m in Sources */, 96E5E38C18BBB48A008E7B30 /* AIActivityKind.m in Sources */, 96E5E38D18BBB48A008E7B30 /* AIActivityPackage.m in Sources */, @@ -418,6 +416,7 @@ 965307F81A000DCC00107FF9 /* AIUserAgent.m in Sources */, 96E5E39318BBB48A008E7B30 /* AILogger.m in Sources */, 96E5E39418BBB48A008E7B30 /* AIPackageBuilder.m in Sources */, + 960A8BB91A029A8000F2BB95 /* AdjustConfig.m in Sources */, 96E5E39218BBB48A008E7B30 /* AIAdjustFactory.m in Sources */, 96CD4478192A546F0029A1AA /* AdjustBridge.m in Sources */, ); @@ -428,7 +427,6 @@ buildActionMask = 2147483647; files = ( 96E5E3B118BBB49E008E7B30 /* AILoggerMock.m in Sources */, - 96E5E3BC18BBB98C008E7B30 /* NSData+AIAdditions.m in Sources */, 96E5E3AF18BBB49E008E7B30 /* AIActivityHandlerMock.m in Sources */, 96E5E3BD18BBB992008E7B30 /* UIDevice+AIAdditions.m in Sources */, 96E5E3B318BBB49E008E7B30 /* AIPackageHandlerTests.m in Sources */, diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index 28209c721..a37115ac2 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -11,8 +11,7 @@ @protocol AIActivityHandler -- (id)initWithAppToken:(NSString *)appToken; -- (void)setSdkPrefix:(NSString *)sdkPrefix; +- (id)initWithConfig:(AdjustConfig *)adjustConfig; - (void)trackSubsessionStart; - (void)trackSubsessionEnd; @@ -25,13 +24,6 @@ - (void)readOpenUrl:(NSURL*)url; - (void)savePushToken:(NSData *)pushToken; -- (void)setEnvironment:(NSString *)environment; -- (void)setBufferEvents:(BOOL)bufferEvents; -- (void)setTrackMacMd5:(BOOL)trackMacMd5; -- (void)setDelegate:(NSObject *) delegate; -- (void)setIsIad:(BOOL)isIad; -- (void)setAttributionMaxTime:(double)seconds; - - (AIAttribution*) attribution; - (void) setAttribution:(AIAttribution*)attribution; @@ -41,6 +33,6 @@ @interface AIActivityHandler : NSObject -+ (id)handlerWithAppToken:(NSString *)appToken; ++ (id)handlerWithConfig:(AdjustConfig *)adjustConfig; @end diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index da49039c5..9faefba48 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -19,7 +19,6 @@ #import "AIAdjustFactory.h" #import "AIAttributionHandler.h" - static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAttributionFilename = @"AdjustIoAttribution"; static NSString * const kAdjustPrefix = @"adjust_"; @@ -40,10 +39,9 @@ @interface AIActivityHandler() @property (nonatomic, retain) NSObject *delegate; @property (nonatomic, retain) id attributionHandler; @property (nonatomic, retain) AIAttribution *attribution; +@property (nonatomic, retain) AdjustConfig *adjustConfig; @property (nonatomic, assign) BOOL enabled; -@property (nonatomic, assign) BOOL bufferEvents; -@property (nonatomic, assign) BOOL trackMacMd5; @property (nonatomic, copy) AIDeviceInfo* deviceInfo; @@ -53,40 +51,32 @@ @interface AIActivityHandler() #pragma mark - @implementation AIActivityHandler -+ (id)handlerWithAppToken:(NSString *)appToken { - return [[AIActivityHandler alloc] initWithAppToken:appToken]; ++ (id)handlerWithConfig:(AdjustConfig *)adjustConfig { + return [[AIActivityHandler alloc] initWithConfig:adjustConfig]; } -- (id)initWithAppToken:(NSString *)yourAppToken { + +- (id)initWithConfig:(AdjustConfig *)adjustConfig { self = [super init]; if (self == nil) return nil; + if (adjustConfig == nil) { + [AIAdjustFactory.logger error:@"AdjustConfig not initialized correctly"]; + return nil; + } + [self addNotificationObserver]; self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); - self.deviceInfo = [[AIDeviceInfo alloc] init]; - - self.deviceInfo.clientSdk = AIUtil.clientSdk; self.logger = AIAdjustFactory.logger; - - // default values - self.deviceInfo.environment = @"unknown"; - _trackMacMd5 = YES; _enabled = YES; - //self.attributionInternal = nil; - // todo read from file - dispatch_async(self.internalQueue, ^{ - [self initInternal:yourAppToken]; + [self initInternal:adjustConfig]; }); return self; } -- (void)setSdkPrefix:(NSString *)sdkPrefix { - self.deviceInfo.clientSdk = [NSString stringWithFormat:@"%@@%@", sdkPrefix, AIUtil.clientSdk]; -} - - (void)trackSubsessionStart { dispatch_async(self.internalQueue, ^{ [self startInternal]; @@ -161,22 +151,6 @@ - (void)savePushToken:(NSData *)pushToken { }); } -- (void)setEnvironment:(NSString *)environment { - self.deviceInfo.environment = environment; -} - -- (void)setBufferEvents:(BOOL)bufferEvents { - _bufferEvents = bufferEvents; -} - -- (void)setTrackMacMd5:(BOOL)trackMacMd5 { - _trackMacMd5 = trackMacMd5; -} - -- (void)setDelegate:(NSObject *) delegate { - _delegate = delegate; -} - - (void)setIsIad:(BOOL)isIad { self.deviceInfo.isIad = isIad; } @@ -209,14 +183,13 @@ - (void)changedAttributionDelegate:(AIAttribution *)attribution { } #pragma mark - internal -- (void)initInternal:(NSString *)yourAppToken { - if (![self checkAppTokenNotNil:yourAppToken]) return; - if (![self checkAppTokenLength:yourAppToken]) return; +- (void)initInternal:(AdjustConfig *)adjustConfig { + self.adjustConfig = adjustConfig; + self.deviceInfo = [[AIDeviceInfo alloc] init]; NSString *macAddress = UIDevice.currentDevice.aiMacAddress; NSString *macShort = macAddress.aiRemoveColons; - self.deviceInfo.appToken = yourAppToken; self.deviceInfo.macSha1 = macAddress.aiSha1; self.deviceInfo.macShortMd5 = macShort.aiMd5; self.deviceInfo.trackingEnabled = UIDevice.currentDevice.aiTrackingEnabled; @@ -225,6 +198,25 @@ - (void)initInternal:(NSString *)yourAppToken { self.deviceInfo.userAgent = AIUtil.userAgent; self.deviceInfo.vendorId = UIDevice.currentDevice.aiVendorId; + if (adjustConfig.sdkPrefix == nil) { + self.deviceInfo.clientSdk = AIUtil.clientSdk; + } else { + self.deviceInfo.clientSdk = [NSString stringWithFormat:@"%@@%@", adjustConfig.sdkPrefix, AIUtil.clientSdk]; + } + + [AIAdjustFactory.logger info:@"Tracking of macMd5 is %@", adjustConfig.macMd5TrackingEnabled ? @"enabled" : @"disabled"]; + + if (adjustConfig.eventBufferingEnabled) { + [self.logger info:@"Event buffering is enabled"]; + } + + if ([adjustConfig.environment isEqualToString:AIEnvironmentProduction]) { + [self.logger setLogLevel:AILogLevelAssert]; + } else { + [self.logger setLogLevel:adjustConfig.logLevel]; + } + + [[UIDevice currentDevice] aiSetIad:self]; self.packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:self]; @@ -236,7 +228,7 @@ - (void)initInternal:(NSString *)yourAppToken { } - (void)startInternal { - if (![self checkAppTokenNotNil:self.deviceInfo.appToken]) return; + if (![self checkAppTokenNotNil:self.adjustConfig.appToken]) return; if (self.activityState != nil && !self.activityState.enabled) { @@ -296,7 +288,7 @@ - (void)startInternal { } - (void)endInternal { - if (![self checkAppTokenNotNil:self.deviceInfo.appToken]) return; + if (![self checkAppTokenNotNil:self.adjustConfig.appToken]) return; [self.packageHandler pauseSending]; [self stopTimer]; @@ -308,7 +300,7 @@ - (void)endInternal { - (void)eventInternal:(AIEvent *)event { // check consistency - if (![self checkAppTokenNotNil:self.deviceInfo.appToken]) return; + if (![self checkAppTokenNotNil:self.adjustConfig.appToken]) return; if (![self checkActivityState:self.activityState]) return; if (![self checkEventTokenNotNil:event.eventToken]) return; if (![self checkEventTokenLength:event.eventToken]) return; @@ -328,15 +320,13 @@ - (void)eventInternal:(AIEvent *)event // create and populate event package AIPackageBuilder *eventBuilder = [[AIPackageBuilder alloc] init]; eventBuilder.event = event; - - //[self injectGeneralAttributes:eventBuilder]; eventBuilder.deviceInfo = self.deviceInfo; - eventBuilder.trackMd5 = _trackMacMd5; - [self.activityState injectEventAttributes:eventBuilder]; + eventBuilder.activityState = self.activityState; + AIActivityPackage *eventPackage = [eventBuilder buildEventPackage]; [self.packageHandler addPackage:eventPackage]; - if (_bufferEvents) { + if (self.adjustConfig.eventBufferingEnabled) { [self.logger info:@"Buffered event%@", eventPackage.suffix]; } else { [self.packageHandler sendFirstPackage]; @@ -372,9 +362,9 @@ - (void) readOpenUrlInternal:(NSURL *)url { AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init]; reattributionBuilder.deeplinkParameters = adjustDeepLinks; - //[self injectGeneralAttributes:reattributionBuilder]; reattributionBuilder.deviceInfo = self.deviceInfo; - reattributionBuilder.trackMd5 = _trackMacMd5; + reattributionBuilder.activityState = self.activityState; + AIActivityPackage *reattributionPackage = [reattributionBuilder buildReattributionPackage]; [self.packageHandler addPackage:reattributionPackage]; [self.packageHandler sendFirstPackage]; @@ -485,8 +475,7 @@ - (void)writeAttribution { - (void)transferSessionPackage { AIPackageBuilder *sessionBuilder = [[AIPackageBuilder alloc] init]; sessionBuilder.deviceInfo = self.deviceInfo; - sessionBuilder.trackMd5 = _trackMacMd5; - [self.activityState injectSessionAttributes:sessionBuilder]; + sessionBuilder.activityState = self.activityState; AIActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage]; [self.packageHandler addPackage:sessionPackage]; [self.packageHandler sendFirstPackage]; @@ -561,14 +550,6 @@ - (BOOL)checkAppTokenNotNil:(NSString *)appToken { return YES; } -- (BOOL)checkAppTokenLength:(NSString *)appToken { - if (appToken.length != 12) { - [self.logger error:@"Malformed App Token '%@'", appToken]; - return NO; - } - return YES; -} - - (BOOL)checkEventTokenNotNil:(NSString *)eventToken { if (eventToken == nil) { [self.logger error:@"Missing Event Token"]; diff --git a/Adjust/AIActivityState.h b/Adjust/AIActivityState.h index 230b823c8..cb2744bcd 100644 --- a/Adjust/AIActivityState.h +++ b/Adjust/AIActivityState.h @@ -9,7 +9,7 @@ @class AIPackageBuilder; -@interface AIActivityState : NSObject +@interface AIActivityState : NSObject // persistent data @property (nonatomic, copy) NSString *uuid; @@ -34,9 +34,6 @@ - (void)resetSessionAttributes:(double)now; -- (void)injectSessionAttributes:(AIPackageBuilder *)packageBuilder; -- (void)injectEventAttributes:(AIPackageBuilder *)packageBuilder; - // transaction ID management - (void)addTransactionId:(NSString *)transactionId; - (BOOL)findTransactionId:(NSString *)transactionId; diff --git a/Adjust/AIActivityState.m b/Adjust/AIActivityState.m index 49529a02b..10d41373d 100644 --- a/Adjust/AIActivityState.m +++ b/Adjust/AIActivityState.m @@ -46,6 +46,7 @@ - (void)resetSessionAttributes:(double)now { self.lastInterval = -1; } +/* - (void)injectSessionAttributes:(AIPackageBuilder *)builder { [self injectGeneralAttributes:builder]; builder.lastInterval = self.lastInterval; @@ -55,7 +56,7 @@ - (void)injectEventAttributes:(AIPackageBuilder *)builder { [self injectGeneralAttributes:builder]; builder.eventCount = self.eventCount; } - +*/ - (void)addTransactionId:(NSString *)transactionId { if (self.transactionIds == nil) { // create array self.transactionIds = [NSMutableArray arrayWithCapacity:kTransactionIdCount]; @@ -126,16 +127,24 @@ - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeBool:self.enabled forKey:@"enabled"]; } +-(id)copyWithZone:(NSZone *)zone +{ + AIActivityState* copy = [[[self class] allocWithZone:zone] init]; + if (copy) { + copy.sessionCount = self.sessionCount; + copy.subsessionCount = self.subsessionCount; + copy.sessionLength = self.sessionLength; + copy.timeSpent = self.timeSpent; + copy.createdAt = self.createdAt; + copy.uuid = [self.uuid copyWithZone:zone]; + copy.lastInterval = self.lastInterval; + copy.eventCount = self.eventCount; + copy.enabled = self.enabled; + copy.lastActivity = self.lastActivity; + // transactionIds not copied + } -#pragma mark private implementation - -- (void)injectGeneralAttributes:(AIPackageBuilder *)builder { - builder.sessionCount = self.sessionCount; - builder.subsessionCount = self.subsessionCount; - builder.sessionLength = self.sessionLength; - builder.timeSpent = self.timeSpent; - builder.createdAt = self.createdAt; - builder.deviceInfo.uuid = self.uuid; + return copy; } @end diff --git a/Adjust/AIAdditions/NSData+AIAdditions.h b/Adjust/AIAdditions/NSData+AIAdditions.h deleted file mode 100644 index 14010c32b..000000000 --- a/Adjust/AIAdditions/NSData+AIAdditions.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// NSData+AIAdditions.h -// Adjust -// -// Created by Christian Wellenbrock on 01.10.12. -// Copyright (c) 2012-2014 adjust GmbH. All rights reserved. -// -#import - -@interface NSData(AIAdditions) - -- (NSString *)aiEncodeBase64; - -@end diff --git a/Adjust/AIAdditions/NSData+AIAdditions.m b/Adjust/AIAdditions/NSData+AIAdditions.m deleted file mode 100644 index 30ec53ce6..000000000 --- a/Adjust/AIAdditions/NSData+AIAdditions.m +++ /dev/null @@ -1,64 +0,0 @@ -// -// NSData+AIAdditions.m -// Adjust -// -// Created by Christian Wellenbrock on 01.10.12. -// Copyright (c) 2012-2014 adjust GmbH. All rights reserved. -// - -#import "NSData+AIAdditions.h" - -@implementation NSData(AIAdditions) - -static const char _base64EncodingTable[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -// http://stackoverflow.com/a/4727124 -- (NSString *)aiEncodeBase64 { - const unsigned char * objRawData = self.bytes; - char * objPointer; - char * strResult; - - // Get the Raw Data length and ensure we actually have data - NSUInteger intLength = self.length; - if (intLength == 0) return nil; - - // Setup the String-based Result placeholder and pointer within that placeholder - strResult = (char *)calloc((((intLength + 2) / 3) * 4) + 1, sizeof(char)); - objPointer = strResult; - - // Iterate through everything - while (intLength > 2) { // keep going until we have less than 24 bits - *objPointer++ = _base64EncodingTable[objRawData[0] >> 2]; - *objPointer++ = _base64EncodingTable[((objRawData[0] & 0x03) << 4) + (objRawData[1] >> 4)]; - *objPointer++ = _base64EncodingTable[((objRawData[1] & 0x0f) << 2) + (objRawData[2] >> 6)]; - *objPointer++ = _base64EncodingTable[objRawData[2] & 0x3f]; - - // we just handled 3 octets (24 bits) of data - objRawData += 3; - intLength -= 3; - } - - // now deal with the tail end of things - if (intLength != 0) { - *objPointer++ = _base64EncodingTable[objRawData[0] >> 2]; - if (intLength > 1) { - *objPointer++ = _base64EncodingTable[((objRawData[0] & 0x03) << 4) + (objRawData[1] >> 4)]; - *objPointer++ = _base64EncodingTable[(objRawData[1] & 0x0f) << 2]; - *objPointer++ = '='; - } else { - *objPointer++ = _base64EncodingTable[(objRawData[0] & 0x03) << 4]; - *objPointer++ = '='; - *objPointer++ = '='; - } - } - - // Terminate the string-based result - *objPointer = '\0'; - - // Return the results as an NSString object - NSString *encodedString = [NSString stringWithCString:strResult encoding:NSASCIIStringEncoding]; - free(strResult); - return encodedString; -} - -@end diff --git a/Adjust/AIAdjustFactory.h b/Adjust/AIAdjustFactory.h index faad1656f..6c08e8aa1 100644 --- a/Adjust/AIAdjustFactory.h +++ b/Adjust/AIAdjustFactory.h @@ -17,7 +17,7 @@ + (id)packageHandlerForActivityHandler:(id)activityHandler; + (id)requestHandlerForPackageHandler:(id)packageHandler; -+ (id)activityHandlerWithAppToken:(NSString *)appToken; ++ (id)activityHandlerWithConfig:(AdjustConfig *)adjustConfig; + (id)logger; + (double)sessionInterval; + (double)subsessionInterval; diff --git a/Adjust/AIAdjustFactory.m b/Adjust/AIAdjustFactory.m index 79b18efa9..751857ee5 100644 --- a/Adjust/AIAdjustFactory.m +++ b/Adjust/AIAdjustFactory.m @@ -34,11 +34,11 @@ @implementation AIAdjustFactory return [internalRequestHandler initWithPackageHandler:packageHandler]; } -+ (id)activityHandlerWithAppToken:(NSString *)appToken { ++ (id)activityHandlerWithConfig:(AdjustConfig *)adjustConfig { if (internalActivityHandler == nil) { - return [AIActivityHandler handlerWithAppToken:appToken]; + return [AIActivityHandler handlerWithConfig:adjustConfig]; } - return [internalActivityHandler initWithAppToken:appToken]; + return [internalActivityHandler initWithConfig:adjustConfig]; } + (id)logger { diff --git a/Adjust/AIAttribution.m b/Adjust/AIAttribution.m index 43eb8fe12..da8013b60 100644 --- a/Adjust/AIAttribution.m +++ b/Adjust/AIAttribution.m @@ -146,5 +146,4 @@ - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:self.creative forKey:@"creative"]; } - @end diff --git a/Adjust/AIDeviceInfo.h b/Adjust/AIDeviceInfo.h index 28b49f7aa..52cf332b0 100644 --- a/Adjust/AIDeviceInfo.h +++ b/Adjust/AIDeviceInfo.h @@ -8,6 +8,8 @@ #import #import "AIUserAgent.h" +#import "AdjustConfig.h" +#import "AIActivityState.h" @interface AIDeviceInfo : NSObject @@ -19,11 +21,8 @@ @property (nonatomic, assign) BOOL isIad; @property (nonatomic, copy) NSString *vendorId; @property (nonatomic, copy) NSString *pushToken; -@property (nonatomic, copy) AIUserAgent *userAgent; - -@property (nonatomic, copy) NSString *appToken; -@property (nonatomic, copy) NSString *environment; @property (nonatomic, copy) NSString *clientSdk; -@property (nonatomic, copy) NSString *uuid; +@property (nonatomic, copy) AIUserAgent *userAgent; +@property (nonatomic, copy) AdjustConfig *adjustConfig; @end diff --git a/Adjust/AIDeviceInfo.m b/Adjust/AIDeviceInfo.m index 90de7e271..4a3af8c6a 100644 --- a/Adjust/AIDeviceInfo.m +++ b/Adjust/AIDeviceInfo.m @@ -22,11 +22,9 @@ -(id)copyWithZone:(NSZone *)zone copy.isIad = self.isIad; copy.vendorId = [self.vendorId copyWithZone:zone]; copy.pushToken = [self.pushToken copyWithZone:zone]; - copy.userAgent = [self.userAgent copyWithZone:zone]; - copy.appToken = [self.appToken copyWithZone:zone]; - copy.environment = [self.environment copyWithZone:zone]; copy.clientSdk = [self.clientSdk copyWithZone:zone]; - copy.uuid = [self.uuid copyWithZone:zone]; + copy.userAgent = [self.userAgent copyWithZone:zone]; + copy.adjustConfig = [self.adjustConfig copyWithZone:zone]; } return copy; diff --git a/Adjust/AIEvent.m b/Adjust/AIEvent.m index e1e9a9433..4a29f4a9c 100644 --- a/Adjust/AIEvent.m +++ b/Adjust/AIEvent.m @@ -37,7 +37,6 @@ - (void) addPartnerParameter:(NSString *)key } [_partnerParameters setObject:value forKey:key]; - } - (void) setRevenue:(double) amount currency:(NSString *)currency{ diff --git a/Adjust/AIPackageBuilder.h b/Adjust/AIPackageBuilder.h index be058d1d6..b9a457d1d 100644 --- a/Adjust/AIPackageBuilder.h +++ b/Adjust/AIPackageBuilder.h @@ -8,31 +8,18 @@ #import #import "AIEvent.h" #import "AIDeviceInfo.h" - -@class AIActivityPackage; +#import "AIActivityState.h" +#import "AIActivityPackage.h" @interface AIPackageBuilder : NSObject -// general @property (nonatomic, copy) AIDeviceInfo* deviceInfo; -@property (nonatomic, assign) BOOL trackMd5; - -// sessions -@property (nonatomic, assign) int sessionCount; -@property (nonatomic, assign) int subsessionCount; -@property (nonatomic, assign) double createdAt; -@property (nonatomic, assign) double sessionLength; -@property (nonatomic, assign) double timeSpent; -@property (nonatomic, assign) double lastInterval; - -// events -@property (nonatomic, assign) int eventCount; @property (nonatomic, copy) AIEvent* event; +@property (nonatomic, copy) AIActivityState *activityState; // reattributions @property (nonatomic, copy) NSDictionary* deeplinkParameters; - //- (id) initWithDeviceInfo:(AIDeviceInfo *)deviceInfo; - (AIActivityPackage *)buildSessionPackage; diff --git a/Adjust/AIPackageBuilder.m b/Adjust/AIPackageBuilder.m index e27327047..2220c0fe7 100644 --- a/Adjust/AIPackageBuilder.m +++ b/Adjust/AIPackageBuilder.m @@ -8,7 +8,6 @@ #import "AIPackageBuilder.h" #import "AIActivityPackage.h" -#import "NSData+AIAdditions.h" #import "AIUtil.h" #pragma mark - @@ -16,7 +15,9 @@ @implementation AIPackageBuilder - (AIActivityPackage *)buildSessionPackage { NSMutableDictionary *parameters = [self defaultParameters]; - [self parameters:parameters setDuration:self.lastInterval forKey:@"last_interval"]; + [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"last_interval"]; + [self parameters:parameters setDictionaryJson:self.deviceInfo.adjustConfig.callbackPermanentParameters forKey:@"callback_params"]; + [self parameters:parameters setDictionaryJson:self.deviceInfo.adjustConfig.partnerPermanentParameters forKey:@"partner_params"]; AIActivityPackage *sessionPackage = [self defaultActivityPackage]; sessionPackage.path = @"/startup"; @@ -29,11 +30,17 @@ - (AIActivityPackage *)buildSessionPackage { - (AIActivityPackage *)buildEventPackage { NSMutableDictionary *parameters = [self defaultParameters]; + [self parameters:parameters setInt:self.activityState.eventCount forKey:@"event_count"]; [self parameters:parameters setString:self.amountString forKey:@"amount"]; [self parameters:parameters setString:self.event.currency forKey:@"currency"]; - [self parameters:parameters setInt:self.eventCount forKey:@"event_count"]; [self parameters:parameters setString:self.event.eventToken forKey:@"event_token"]; - [self parameters:parameters setDictionaryBase64:self.event.callbackParameters forKey:@"params"]; + + // join the permanent parameters with the ones from the event + NSMutableDictionary * callbackParameters = [self joinParamters:self.deviceInfo.adjustConfig.callbackPermanentParameters parameters:self.event.callbackParameters]; + [self parameters:parameters setDictionaryJson:callbackParameters forKey:@"callback_params"]; + + NSMutableDictionary * partnerParamters = [self joinParamters:self.deviceInfo.adjustConfig.partnerPermanentParameters parameters:self.event.partnerParameters]; + [self parameters:parameters setDictionaryJson:partnerParamters forKey:@"partner_params"]; AIActivityPackage *eventPackage = [self defaultActivityPackage]; eventPackage.path = @"/event"; @@ -44,7 +51,6 @@ - (AIActivityPackage *)buildEventPackage { return eventPackage; } - - (AIActivityPackage *)buildReattributionPackage { NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"deeplink_parameters"]; @@ -68,22 +74,16 @@ - (AIActivityPackage *)defaultActivityPackage { - (NSMutableDictionary *)defaultParameters { NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; - [self constructDeviceInfo:self.deviceInfo toParameters:parameters trackMacMd5:self.trackMd5]; - - [self parameters:parameters setDate:self.createdAt forKey:@"created_at"]; - [self parameters:parameters setInt:self.sessionCount forKey:@"session_count"]; - [self parameters:parameters setInt:self.subsessionCount forKey:@"subsession_count"]; - [self parameters:parameters setDuration:self.sessionLength forKey:@"session_length"]; - [self parameters:parameters setDuration:self.timeSpent forKey:@"time_spent"]; + [self constructDeviceInfo:self.deviceInfo withParameter:parameters]; + [self constructActivityState:self.activityState withParamters:parameters]; return parameters; } -- (void) constructDeviceInfo: (AIDeviceInfo *) deviceInfo - toParameters: (NSMutableDictionary *) parameters - trackMacMd5: (BOOL) trackMacMd5{ +- (void) constructDeviceInfo:(AIDeviceInfo *)deviceInfo + withParameter:(NSMutableDictionary *) parameters{ - [self constructUserAgent:deviceInfo.userAgent toParameters:parameters]; + [self constructUserAgent:deviceInfo.userAgent withParameters:parameters]; [self parameters:parameters setString:deviceInfo.macSha1 forKey:@"mac_sha1"]; [self parameters:parameters setString:deviceInfo.idForAdvertisers forKey:@"idfa"]; @@ -93,18 +93,27 @@ - (void) constructDeviceInfo: (AIDeviceInfo *) deviceInfo [self parameters:parameters setString:deviceInfo.vendorId forKey:@"idfv"]; [self parameters:parameters setString:deviceInfo.pushToken forKey:@"push_token"]; - if (trackMacMd5) { - [self parameters:parameters setString:deviceInfo.macShortMd5 forKey:@"mac_md5"]; + if (deviceInfo.adjustConfig.macMd5TrackingEnabled) { + [self parameters:parameters setString:deviceInfo.macShortMd5 forKey:@"mac_md5"]; } - [self parameters:parameters setString:deviceInfo.appToken forKey:@"app_token"]; - [self parameters:parameters setString:deviceInfo.uuid forKey:@"ios_uuid"]; - [self parameters:parameters setString:deviceInfo.environment forKey:@"environment"]; + [self parameters:parameters setString:deviceInfo.adjustConfig.appToken forKey:@"app_token"]; + [self parameters:parameters setString:deviceInfo.adjustConfig.environment forKey:@"environment"]; +} + +- (void) constructActivityState:(AIActivityState *)activityState + withParamters:(NSMutableDictionary *)parameters { + [self parameters:parameters setDate:activityState.createdAt forKey:@"created_at"]; + [self parameters:parameters setInt:activityState.sessionCount forKey:@"session_count"]; + [self parameters:parameters setInt:activityState.subsessionCount forKey:@"subsession_count"]; + [self parameters:parameters setDuration:activityState.sessionLength forKey:@"session_length"]; + [self parameters:parameters setDuration:activityState.timeSpent forKey:@"time_spent"]; + [self parameters:parameters setString:activityState.uuid forKey:@"ios_uuid"]; } -- (void) constructUserAgent: (AIUserAgent *) userAgent - toParameters: (NSMutableDictionary *) parameters { +- (void) constructUserAgent:(AIUserAgent *)userAgent + withParameters:(NSMutableDictionary *) parameters { [self parameters:parameters setString:userAgent.bundeIdentifier forKey:@"bundle_identifier"]; [self parameters:parameters setString:userAgent.bundleVersion forKey:@"bundle_version"]; [self parameters:parameters setString:userAgent.deviceType forKey:@"device_type"]; @@ -162,14 +171,6 @@ - (void)parameters:(NSMutableDictionary *)parameters setDuration:(double)value f [self parameters:parameters setInt:intValue forKey:key]; } -- (void)parameters:(NSMutableDictionary *)parameters setDictionaryBase64:(NSDictionary *)dictionary forKey:(NSString *)key { - if (dictionary == nil) return; - - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil]; - NSString *dictionaryString = jsonData.aiEncodeBase64; - [self parameters:parameters setString:dictionaryString forKey:key]; -} - - (void)parameters:(NSMutableDictionary *)parameters setDictionaryJson:(NSDictionary *)dictionary forKey:(NSString *)key { if (dictionary == nil) return; @@ -185,5 +186,18 @@ - (void)parameters:(NSMutableDictionary *)parameters setBool:(BOOL)value forKey: [self parameters:parameters setInt:valueInt forKey:key]; } + +- (NSMutableDictionary *) joinParamters:(NSMutableDictionary *)permanentParameters + parameters:(NSMutableDictionary *)parameters { + if (permanentParameters == nil) { + return parameters; + } + if (parameters == nil) { + return permanentParameters; + } + [permanentParameters addEntriesFromDictionary:parameters]; + + return permanentParameters; +} @end diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index bf1b89b9c..c1939d2a7 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -10,8 +10,7 @@ #import "AIResponseData.h" #import "AIEvent.h" #import "AIAttribution.h" - -@protocol AdjustDelegate; +#import "AdjustConfig.h" /** * Constants for our supported tracking environments. @@ -37,17 +36,7 @@ static NSString * const AIEnvironmentProduction = @"production"; * be found it in your dashboard at http://adjust.com and should always * be 12 characters long. */ -+ (void)appDidLaunch:(NSString *)appToken; - -/** - * Set the optional delegate that will get informed about tracking results - * - * See the AdjustDelegate declaration below for details - * - * @param delegate The delegate that might implement the optional delegate - * methods like adjustFinishedTrackingWithResponse: - */ -+ (void)setDelegate:(id)delegate; ++ (void)appDidLaunch:(AdjustConfig *)adjustConfig; /** * Tell Adjust that a particular event has happened. @@ -69,53 +58,6 @@ static NSString * const AIEnvironmentProduction = @"production"; */ + (void)trackEvent:(AIEvent *)event; -/** - * Change the verbosity of Adjust's logs. - * - * You can increase or reduce the amount of logs from Adjust by passing - * one of the following parameters. Use Log.ASSERT to disable all logging. - * - * @param logLevel The desired minimum log level (default: info) - * Must be one of the following: - * - AILogLevelVerbose (enable all logging) - * - AILogLevelDebug (enable more logging) - * - AILogLevelInfo (the default) - * - AILogLevelWarn (disable info logging) - * - AILogLevelError (disable warnings as well) - * - AILogLevelAssert (disable errors as well) - */ -+ (void)setLogLevel:(AILogLevel)logLevel; - -/** - * Set the tracking environment to sandbox or production. - * - * Use sandbox for testing and production for the final build that you release. - * - * @param environment The new environment. Supported values: - * - AIEnvironmentSandbox - * - AIEnvironmentProduction - */ -+ (void)setEnvironment:(NSString *)environment; - -/** - * Enable or disable event buffering. - * - * Enable event buffering if your app triggers a lot of events. - * When enabled, events get buffered and only get tracked each - * minute. Buffered events are still persisted, of course. - */ -+ (void)setEventBufferingEnabled:(BOOL)enabled; - -/** - * Enable or disable tracking of the MD5 hash of the MAC address - * - * Disable macMd5 tracking if your privacy constraints require it. - */ -+ (void)setMacMd5TrackingEnabled:(BOOL)enabled; - -// Special method used by wrapper JS bridge. Do not call directly. -+ (void)setSdkPrefix:(NSString *)sdkPrefix; - /** * Tell adjust that the application resumed. * @@ -153,27 +95,6 @@ static NSString * const AIEnvironmentProduction = @"production"; */ + (void)setDeviceToken:(NSData *)deviceToken; -+ (void)setAttributionMaxTime:(double)seconds; @end - -@class AIActivityPackage; -@class AIResponseData; - -#pragma mark - -/** - * Optional delegate that will get informed about tracking results - */ -@protocol AdjustDelegate -@optional - -/** - * Optional delegate method that will get called when a tracking attempt finished - * - * @param responseData The response data containing information about the activity - * and it's server response. See AIResponseData for details. - */ -- (void)adjustAttributionChanged:(AIAttribution *)attribution; - -@end diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 9c78a2065..3fe2de6cc 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -16,68 +16,18 @@ #endif static id activityHandler; -static id logger; #pragma mark - @implementation Adjust -+ (void)appDidLaunch:(NSString *)yourAppToken { - activityHandler = [AIAdjustFactory activityHandlerWithAppToken:yourAppToken]; -} - -+ (void)setDelegate:(NSObject *)delegate { - [activityHandler setDelegate:delegate]; -} - -+ (void)setSdkPrefix:(NSString *)sdkPrefix { - [activityHandler setSdkPrefix:sdkPrefix]; ++ (void)appDidLaunch:(AdjustConfig *)adjustConfig { + activityHandler = [AIAdjustFactory activityHandlerWithConfig:adjustConfig]; } + (void)trackEvent:(AIEvent *)event { [activityHandler trackEvent:event]; } -+ (void)setLogLevel:(AILogLevel)logLevel { - [AIAdjustFactory.logger setLogLevel:logLevel]; -} - -+ (void)setEnvironment:(NSString *)environment { - id logger = AIAdjustFactory.logger; - if (activityHandler == nil) { - [logger error:@"Please call `setEnvironment` after `appDidLaunch`!"]; - } else if ([environment isEqualToString:AIEnvironmentSandbox]) { - [activityHandler setEnvironment:environment]; - [logger assert:@"SANDBOX: Adjust is running in Sandbox mode. Use this setting for testing. Don't forget to set the environment to AIEnvironmentProduction before publishing!"]; - } else if ([environment isEqualToString:AIEnvironmentProduction]) { - [activityHandler setEnvironment:environment]; - [logger assert:@"PRODUCTION: Adjust is running in Production mode. Use this setting only for the build that you want to publish. Set the environment to AIEnvironmentSandbox if you want to test your app!"]; - [logger setLogLevel:AILogLevelAssert]; - } else { - [activityHandler setEnvironment:@"malformed"]; - [logger error:@"Malformed environment '%@'", environment]; - } -} - -+ (void)setEventBufferingEnabled:(BOOL)enabled { - if (activityHandler == nil) { - [AIAdjustFactory.logger error:@"Please call `setEventBufferingEnabled` after `appDidLaunch`!"]; - return; - } - - [activityHandler setBufferEvents:enabled]; - if (enabled) [AIAdjustFactory.logger info:@"Event buffering is enabled"]; -} - -+ (void)setMacMd5TrackingEnabled:(BOOL)enabled { - if (activityHandler == nil) { - [AIAdjustFactory.logger error:@"Please call `setMacMd5TrackingEnabled` after `appDidLaunch`!"]; - return; - } - - [activityHandler setTrackMacMd5:enabled]; - [AIAdjustFactory.logger info:@"Tracking of macMd5 is %@", enabled ? @"enabled" : @"disabled"]; -} - + (void)trackSubsessionStart { [activityHandler trackSubsessionStart]; } @@ -102,8 +52,4 @@ + (void)setDeviceToken:(NSData *)deviceToken { [activityHandler savePushToken:deviceToken]; } -+ (void)setAttributionMaxTime:(double)seconds { - [activityHandler setAttributionMaxTime:seconds]; -} - @end diff --git a/Adjust/AdjustConfig.h b/Adjust/AdjustConfig.h new file mode 100644 index 000000000..f29af73f5 --- /dev/null +++ b/Adjust/AdjustConfig.h @@ -0,0 +1,52 @@ +// +// AdjustConfig.h +// adjust +// +// Created by Pedro Filipe on 30/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import +#import "AILogger.h" +#import "AIAttribution.h" + +/** + * Optional delegate that will get informed about tracking results + */ +@protocol AdjustDelegate +@optional + +/** + * Optional delegate method that will get called when a tracking attempt finished + * + * @param responseData The response data containing information about the activity + * and it's server response. See AIResponseData for details. + */ +- (void)adjustAttributionChanged:(AIAttribution *)attribution; + +@end + +@interface AdjustConfig : NSObject + +@property (nonatomic, copy) NSString *appToken; +@property (nonatomic, assign) AILogLevel logLevel; +@property (nonatomic, copy) NSString *environment; +@property (nonatomic, copy) NSString *sdkPrefix; +@property (nonatomic, assign) BOOL eventBufferingEnabled; +@property (nonatomic, assign) BOOL macMd5TrackingEnabled; +@property (nonatomic, copy) NSMutableDictionary* callbackPermanentParameters; +@property (nonatomic, copy) NSMutableDictionary* partnerPermanentParameters; +@property (nonatomic, retain) NSObject *delegate; +@property (nonatomic, assign) double attributionMaxTime; + +- (id)initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; + +- (void)addPermanentCallbackParameter:(NSString *)key + andValue:(NSString *)value; + +- (void)addPermanentPartnerParameter:(NSString *)key + andValue:(NSString *)value; + + + +@end diff --git a/Adjust/AdjustConfig.m b/Adjust/AdjustConfig.m new file mode 100644 index 000000000..5f5be97bd --- /dev/null +++ b/Adjust/AdjustConfig.m @@ -0,0 +1,93 @@ +// +// AdjustConfig.m +// adjust +// +// Created by Pedro Filipe on 30/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import "AdjustConfig.h" +#import "AIAdjustFactory.h" +#import "AILogger.h" + +@implementation AdjustConfig + +- (id) initWithAppToken:(NSString *)appToken + andEnvironment:(NSString *)environment +{ + self = [super init]; + if (self == nil) return nil; + + if (![self checkAppTokenLength:appToken]) return nil; + if (![self checkEnvironment:environment]) return nil; + + self.appToken = appToken; + self.environment = environment; + + // default values + self.logLevel = AILogLevelInfo; + self.macMd5TrackingEnabled = YES; + + return self; +} + +- (void) addPermanentCallbackParameter:(NSString *)key + andValue:(NSString *)value { + if (_callbackPermanentParameters == nil) { + _callbackPermanentParameters = [[NSMutableDictionary alloc] init]; + } + + [_callbackPermanentParameters setObject:value forKey:key]; +} + +- (void) addPermanentPartnerParameter:(NSString *)key + andValue:(NSString *)value { + if (_partnerPermanentParameters == nil) { + _partnerPermanentParameters = [[NSMutableDictionary alloc] init]; + } + + [_partnerPermanentParameters setObject:value forKey:key]; +} + +- (BOOL) checkEnvironment:(NSString *)environment +{ + id logger = AIAdjustFactory.logger; + if ([environment isEqualToString:AIEnvironmentSandbox]) { + [logger assert:@"SANDBOX: Adjust will run in Sandbox mode. Use this setting for testing. Don't forget to set the environment to AIEnvironmentProduction before publishing!"]; + return YES; + } else if ([environment isEqualToString:AIEnvironmentProduction]) { + [logger assert:@"PRODUCTION: Adjust will run in Production mode. Use this setting only for the build that you want to publish. Set the environment to AIEnvironmentSandbox if you want to test your app!"]; + return YES; + } + [logger error:@"Malformed environment '%@'", environment]; + return NO; +} + +- (BOOL)checkAppTokenLength:(NSString *)appToken { + if (appToken == nil || appToken.length != 12) { + [AIAdjustFactory.logger error:@"Malformed App Token '%@'", appToken]; + return NO; + } + return YES; +} + +-(id)copyWithZone:(NSZone *)zone +{ + AdjustConfig* copy = [[[self class] allocWithZone:zone] init]; + if (copy) { + copy.appToken = [self.appToken copyWithZone:zone]; + copy.logLevel = self.logLevel; + copy.environment = [self.environment copyWithZone:zone]; + copy.sdkPrefix = [self.environment copyWithZone:zone]; + copy.eventBufferingEnabled = self.eventBufferingEnabled; + copy.macMd5TrackingEnabled = self.macMd5TrackingEnabled; + copy.callbackPermanentParameters = [self.callbackPermanentParameters copyWithZone:zone]; + copy.partnerPermanentParameters = [self.partnerPermanentParameters copyWithZone:zone]; + // adjust delegate not copied + copy.attributionMaxTime = self.attributionMaxTime; + } + + return copy; +} + +@end From 3e852993238d0880276911e21b30c4a9e6aab8f2 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 3 Nov 2014 11:46:26 +0100 Subject: [PATCH 06/86] Click package --- Adjust/AIActivityHandler.h | 2 +- Adjust/AIActivityHandler.m | 14 ++++++++++++-- Adjust/AIPackageBuilder.h | 2 +- Adjust/AIPackageBuilder.m | 4 ++-- Adjust/AIPackageHandler.h | 2 +- Adjust/AIPackageHandler.m | 13 ++----------- Adjust/AIRequestHandler.m | 6 ++++-- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index a37115ac2..eb560380e 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -18,7 +18,7 @@ - (void)trackEvent:(AIEvent *)event; -- (void)finishedTrackingWithResponse:(AIResponseData *)response deepLink:(NSString *)deepLink; +- (void)finishedTrackingWithResponse:(NSString *)deepLink; - (void)setEnabled:(BOOL)enabled; - (BOOL)isEnabled; - (void)readOpenUrl:(NSURL*)url; diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index 9faefba48..7b27b3a94 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -96,7 +96,7 @@ - (void)trackEvent:(AIEvent *)event }); } -- (void)finishedTrackingWithResponse:(AIResponseData *)response deepLink:(NSString *)deepLink{ +- (void)finishedTrackingWithResponse:(NSString *)deepLink{ if (self.attribution == nil) { [self.attributionHandler getAttribution]; } @@ -153,6 +153,15 @@ - (void)savePushToken:(NSData *)pushToken { - (void)setIsIad:(BOOL)isIad { self.deviceInfo.isIad = isIad; + if (isIad) { + AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init]; + reattributionBuilder.deviceInfo = self.deviceInfo; + reattributionBuilder.activityState = self.activityState; + + AIActivityPackage *reattributionPackage = [reattributionBuilder buildClickPackage]; + [self.packageHandler addPackage:reattributionPackage]; + [self.packageHandler sendFirstPackage]; + } } - (void)setAttributionMaxTime:(double)seconds { @@ -364,8 +373,9 @@ - (void) readOpenUrlInternal:(NSURL *)url { reattributionBuilder.deeplinkParameters = adjustDeepLinks; reattributionBuilder.deviceInfo = self.deviceInfo; reattributionBuilder.activityState = self.activityState; + reattributionBuilder.deeplinkParameters = adjustDeepLinks; - AIActivityPackage *reattributionPackage = [reattributionBuilder buildReattributionPackage]; + AIActivityPackage *reattributionPackage = [reattributionBuilder buildClickPackage]; [self.packageHandler addPackage:reattributionPackage]; [self.packageHandler sendFirstPackage]; diff --git a/Adjust/AIPackageBuilder.h b/Adjust/AIPackageBuilder.h index b9a457d1d..41b6f77b8 100644 --- a/Adjust/AIPackageBuilder.h +++ b/Adjust/AIPackageBuilder.h @@ -24,6 +24,6 @@ - (AIActivityPackage *)buildSessionPackage; - (AIActivityPackage *)buildEventPackage; -- (AIActivityPackage *)buildReattributionPackage; +- (AIActivityPackage *)buildClickPackage; @end diff --git a/Adjust/AIPackageBuilder.m b/Adjust/AIPackageBuilder.m index 2220c0fe7..c2af92bcd 100644 --- a/Adjust/AIPackageBuilder.m +++ b/Adjust/AIPackageBuilder.m @@ -51,9 +51,10 @@ - (AIActivityPackage *)buildEventPackage { return eventPackage; } -- (AIActivityPackage *)buildReattributionPackage { +- (AIActivityPackage *)buildClickPackage { NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"deeplink_parameters"]; + [self parameters:parameters setBool:self.deviceInfo.isIad forKey:@"is_iad"]; AIActivityPackage *reattributionPackage = [self defaultActivityPackage]; reattributionPackage.path = @"/reattribute"; @@ -89,7 +90,6 @@ - (void) constructDeviceInfo:(AIDeviceInfo *)deviceInfo [self parameters:parameters setString:deviceInfo.idForAdvertisers forKey:@"idfa"]; [self parameters:parameters setString:deviceInfo.fbAttributionId forKey:@"fb_id"]; [self parameters:parameters setInt:deviceInfo.trackingEnabled forKey:@"tracking_enabled"]; - [self parameters:parameters setBool:deviceInfo.isIad forKey:@"is_iad"]; [self parameters:parameters setString:deviceInfo.vendorId forKey:@"idfv"]; [self parameters:parameters setString:deviceInfo.pushToken forKey:@"push_token"]; diff --git a/Adjust/AIPackageHandler.h b/Adjust/AIPackageHandler.h index e01aa5d45..2aed3ec69 100644 --- a/Adjust/AIPackageHandler.h +++ b/Adjust/AIPackageHandler.h @@ -22,7 +22,7 @@ - (void)pauseSending; - (void)resumeSending; -- (void)finishedTrackingActivity:(AIActivityPackage *)activityPackage withResponse:(AIResponseData *)response jsonDict:(NSDictionary *)jsonDict; +- (void)finishedTrackingActivity:(NSString *) deepLink; @end diff --git a/Adjust/AIPackageHandler.m b/Adjust/AIPackageHandler.m index 3885b85df..84ca8d6e6 100644 --- a/Adjust/AIPackageHandler.m +++ b/Adjust/AIPackageHandler.m @@ -84,17 +84,8 @@ - (void)resumeSending { self.paused = NO; } -- (void)finishedTrackingActivity:(AIActivityPackage *)activityPackage withResponse:(AIResponseData *)response jsonDict:(NSDictionary *)jsonDict{ - - response.activityKind = activityPackage.activityKind; - - NSString * deepLink = nil; - - if (jsonDict != nil) { - deepLink = [jsonDict objectForKey:@"deeplink"]; - } - - [self.activityHandler finishedTrackingWithResponse:response deepLink:deepLink]; +- (void)finishedTrackingActivity:(NSString *) deepLink{ + [self.activityHandler finishedTrackingWithResponse:deepLink]; } diff --git a/Adjust/AIRequestHandler.m b/Adjust/AIRequestHandler.m index 70fcfd6b1..f4985302f 100644 --- a/Adjust/AIRequestHandler.m +++ b/Adjust/AIRequestHandler.m @@ -70,7 +70,7 @@ - (void)sendInternal:(AIActivityPackage *)package { AIResponseData *responseData = [AIResponseData dataWithError:error.localizedDescription]; responseData.willRetry = YES; [self.logger error:@"%@. (%@) Will retry later.", package.failureMessage, responseData.error]; - [self.packageHandler finishedTrackingActivity:package withResponse:responseData jsonDict:nil]; + [self.packageHandler finishedTrackingActivity:nil]; [self.packageHandler closeFirstPackage]; return; } @@ -88,7 +88,9 @@ - (void)sendInternal:(AIActivityPackage *)package { [self.logger error:@"%@. (%@)", package.failureMessage, responseData.error]; } - [self.packageHandler finishedTrackingActivity:package withResponse:responseData jsonDict:jsonDict]; + NSString * deepLink = [jsonDict objectForKey:@"deeplink"]; + + [self.packageHandler finishedTrackingActivity:deepLink]; [self.packageHandler sendNextPackage]; } From 3eddd47d6191a310bc4dfe4c978b2ca4c7a347e2 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 3 Nov 2014 12:00:25 +0100 Subject: [PATCH 07/86] Offline mode --- Adjust/AIActivityHandler.h | 2 ++ Adjust/AIActivityHandler.m | 9 +++++++++ Adjust/AIPackageHandler.m | 1 - Adjust/Adjust.h | 2 ++ Adjust/Adjust.m | 4 ++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index eb560380e..07f2de678 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -29,6 +29,8 @@ - (void) changedAttributionDelegate:(AIAttribution*) attribution; +- (void) setOfflineMode:(BOOL)enabled; + @end @interface AIActivityHandler : NSObject diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index 7b27b3a94..cbce367ff 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -191,6 +191,15 @@ - (void)changedAttributionDelegate:(AIAttribution *)attribution { withObject:attribution waitUntilDone:NO]; } +- (void)setOfflineMode:(BOOL)enabled { + if (enabled) { + [self endInternal]; + } else { + [self.packageHandler resumeSending]; + [self startTimer]; + } +} + #pragma mark - internal - (void)initInternal:(AdjustConfig *)adjustConfig { self.adjustConfig = adjustConfig; diff --git a/Adjust/AIPackageHandler.m b/Adjust/AIPackageHandler.m index 84ca8d6e6..fd61f71e9 100644 --- a/Adjust/AIPackageHandler.m +++ b/Adjust/AIPackageHandler.m @@ -88,7 +88,6 @@ - (void)finishedTrackingActivity:(NSString *) deepLink{ [self.activityHandler finishedTrackingWithResponse:deepLink]; } - #pragma mark - internal - (void)initInternal { self.requestHandler = [AIAdjustFactory requestHandlerForPackageHandler:self]; diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index c1939d2a7..7417a0a0f 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -96,5 +96,7 @@ static NSString * const AIEnvironmentProduction = @"production"; + (void)setDeviceToken:(NSData *)deviceToken; ++ (void)setOfflineMode:(BOOL)enabled; + @end diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 3fe2de6cc..7f87dae92 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -52,4 +52,8 @@ + (void)setDeviceToken:(NSData *)deviceToken { [activityHandler savePushToken:deviceToken]; } ++ (void)setOfflineMode:(BOOL)enabled { + [activityHandler setOfflineMode:enabled]; +} + @end From 3a5eedf9a8bb1c17be238fb0d5239a4b15a9293b Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 4 Nov 2014 14:24:37 +0100 Subject: [PATCH 08/86] Adjust singleton --- Adjust/AIActivityHandler.h | 12 ++- Adjust/AIActivityHandler.m | 47 ++++++--- Adjust/AIAttributionHandler.m | 2 +- Adjust/AIDeviceInfo.h | 1 - Adjust/AIDeviceInfo.m | 1 - Adjust/AIPackageBuilder.h | 1 + Adjust/AIPackageBuilder.m | 23 ++-- Adjust/Adjust.h | 28 +++++ Adjust/Adjust.m | 151 +++++++++++++++++++++++++-- Adjust/AdjustConfig.h | 2 - AdjustTests/AIActivityHandlerMock.m | 4 +- AdjustTests/AIActivityHandlerTests.m | 16 +-- 12 files changed, 236 insertions(+), 52 deletions(-) diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index 07f2de678..28752eec3 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -21,8 +21,8 @@ - (void)finishedTrackingWithResponse:(NSString *)deepLink; - (void)setEnabled:(BOOL)enabled; - (BOOL)isEnabled; -- (void)readOpenUrl:(NSURL*)url; -- (void)savePushToken:(NSData *)pushToken; +- (void)appWillOpenUrl:(NSURL*)url; +- (void)setDeviceToken:(NSData *)deviceToken; - (AIAttribution*) attribution; - (void) setAttribution:(AIAttribution*)attribution; @@ -31,6 +31,14 @@ - (void) setOfflineMode:(BOOL)enabled; +- (void)setDelegate:(NSObject *)delegate; + +- (void)addPermanentCallbackParameter:(NSString *)key + andValue:(NSString *)value; + +- (void)addPermanentPartnerParameter:(NSString *)key + andValue:(NSString *)value; + @end @interface AIActivityHandler : NSObject diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index cbce367ff..f63d5dab1 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -33,13 +33,13 @@ @interface AIActivityHandler() @property (nonatomic) dispatch_queue_t internalQueue; @property (nonatomic, retain) id packageHandler; +@property (nonatomic, retain) id attributionHandler; @property (nonatomic, retain) AIActivityState *activityState; @property (nonatomic, retain) AITimer *timer; @property (nonatomic, retain) id logger; @property (nonatomic, retain) NSObject *delegate; -@property (nonatomic, retain) id attributionHandler; @property (nonatomic, retain) AIAttribution *attribution; -@property (nonatomic, retain) AdjustConfig *adjustConfig; +@property (nonatomic, copy) AdjustConfig *adjustConfig; @property (nonatomic, assign) BOOL enabled; @@ -97,10 +97,10 @@ - (void)trackEvent:(AIEvent *)event } - (void)finishedTrackingWithResponse:(NSString *)deepLink{ + [self launchDeepLink:deepLink]; if (self.attribution == nil) { [self.attributionHandler getAttribution]; } - [self launchDeepLink:deepLink]; } - (void)launchDeepLink:(NSString *) deepLink{ @@ -123,6 +123,7 @@ - (void)setEnabled:(BOOL)enabled { _enabled = enabled; if ([self checkActivityState:self.activityState]) { self.activityState.enabled = enabled; + [self writeActivityState]; } if (enabled) { [self trackSubsessionStart]; @@ -139,15 +140,15 @@ - (BOOL)isEnabled { } } -- (void)readOpenUrl:(NSURL*)url { +- (void)appWillOpenUrl:(NSURL*)url { dispatch_async(self.internalQueue, ^{ - [self readOpenUrlInternal:url]; + [self appWillOpenUrlInternal:url]; }); } -- (void)savePushToken:(NSData *)pushToken { +- (void)setDeviceToken:(NSData *)deviceToken { dispatch_async(self.internalQueue, ^{ - [self savePushTokenInternal:pushToken]; + [self setDeviceTokenInternal:deviceToken]; }); } @@ -156,6 +157,7 @@ - (void)setIsIad:(BOOL)isIad { if (isIad) { AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init]; reattributionBuilder.deviceInfo = self.deviceInfo; + reattributionBuilder.adjustConfig = self.adjustConfig; reattributionBuilder.activityState = self.activityState; AIActivityPackage *reattributionPackage = [reattributionBuilder buildClickPackage]; @@ -180,13 +182,15 @@ - (void) setAttribution:(AIAttribution*)attribution { - (void)changedAttributionDelegate:(AIAttribution *)attribution { - if (![self.delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { - return; - } if (attribution == nil) { return; } self.attribution = attribution; + [self writeAttribution]; + // TODO write attribution to file + if (![self.delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { + return; + } [self.delegate performSelectorOnMainThread:@selector(adjustAttributionChanged:) withObject:attribution waitUntilDone:NO]; } @@ -200,6 +204,16 @@ - (void)setOfflineMode:(BOOL)enabled { } } +- (void) addPermanentCallbackParameter:(NSString *)key + andValue:(NSString *)value { + [self.adjustConfig addPermanentCallbackParameter:key andValue:value]; +} + +- (void) addPermanentPartnerParameter:(NSString *)key + andValue:(NSString *)value { + [self.adjustConfig addPermanentPartnerParameter:key andValue:value]; +} + #pragma mark - internal - (void)initInternal:(AdjustConfig *)adjustConfig { self.adjustConfig = adjustConfig; @@ -234,6 +248,7 @@ - (void)initInternal:(AdjustConfig *)adjustConfig { [self.logger setLogLevel:adjustConfig.logLevel]; } + self.delegate = adjustConfig.delegate; [[UIDevice currentDevice] aiSetIad:self]; @@ -241,6 +256,7 @@ - (void)initInternal:(AdjustConfig *)adjustConfig { self.attributionHandler = [AIAdjustFactory attributionHandlerForActivityHandler:self]; [self readActivityState]; + [self readAttribution]; [self startInternal]; } @@ -338,6 +354,7 @@ - (void)eventInternal:(AIEvent *)event // create and populate event package AIPackageBuilder *eventBuilder = [[AIPackageBuilder alloc] init]; eventBuilder.event = event; + eventBuilder.adjustConfig = self.adjustConfig; eventBuilder.deviceInfo = self.deviceInfo; eventBuilder.activityState = self.activityState; @@ -354,7 +371,7 @@ - (void)eventInternal:(AIEvent *)event [self.logger debug:@"Event %d", self.activityState.eventCount]; } -- (void) readOpenUrlInternal:(NSURL *)url { +- (void) appWillOpenUrlInternal:(NSURL *)url { NSArray* queryArray = [url.query componentsSeparatedByString:@"&"]; NSMutableDictionary* adjustDeepLinks = [NSMutableDictionary dictionary]; @@ -380,6 +397,7 @@ - (void) readOpenUrlInternal:(NSURL *)url { AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init]; reattributionBuilder.deeplinkParameters = adjustDeepLinks; + reattributionBuilder.adjustConfig = self.adjustConfig; reattributionBuilder.deviceInfo = self.deviceInfo; reattributionBuilder.activityState = self.activityState; reattributionBuilder.deeplinkParameters = adjustDeepLinks; @@ -391,12 +409,12 @@ - (void) readOpenUrlInternal:(NSURL *)url { [self.logger debug:@"Reattribution %@", adjustDeepLinks]; } -- (void) savePushTokenInternal:(NSData *)pushToken { - if (pushToken == nil) { +- (void) setDeviceTokenInternal:(NSData *)deviceToken { + if (deviceToken == nil) { return; } - NSString *token = [pushToken.description stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]]; + NSString *token = [deviceToken.description stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]]; token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; self.deviceInfo.pushToken = token; @@ -493,6 +511,7 @@ - (void)writeAttribution { - (void)transferSessionPackage { AIPackageBuilder *sessionBuilder = [[AIPackageBuilder alloc] init]; + sessionBuilder.adjustConfig = self.adjustConfig; sessionBuilder.deviceInfo = self.deviceInfo; sessionBuilder.activityState = self.activityState; AIActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage]; diff --git a/Adjust/AIAttributionHandler.m b/Adjust/AIAttributionHandler.m index c5596161d..c565cf711 100644 --- a/Adjust/AIAttributionHandler.m +++ b/Adjust/AIAttributionHandler.m @@ -49,7 +49,7 @@ - (id)initWithActivityHandler:(id) activityHandler { // comunicate with server - (void) getAttribution { dispatch_async(self.internalQueue, ^{ - [self getAttribution]; + [self checkAttributionInternal]; }); } diff --git a/Adjust/AIDeviceInfo.h b/Adjust/AIDeviceInfo.h index 52cf332b0..9723027b2 100644 --- a/Adjust/AIDeviceInfo.h +++ b/Adjust/AIDeviceInfo.h @@ -23,6 +23,5 @@ @property (nonatomic, copy) NSString *pushToken; @property (nonatomic, copy) NSString *clientSdk; @property (nonatomic, copy) AIUserAgent *userAgent; -@property (nonatomic, copy) AdjustConfig *adjustConfig; @end diff --git a/Adjust/AIDeviceInfo.m b/Adjust/AIDeviceInfo.m index 4a3af8c6a..eea13c149 100644 --- a/Adjust/AIDeviceInfo.m +++ b/Adjust/AIDeviceInfo.m @@ -24,7 +24,6 @@ -(id)copyWithZone:(NSZone *)zone copy.pushToken = [self.pushToken copyWithZone:zone]; copy.clientSdk = [self.clientSdk copyWithZone:zone]; copy.userAgent = [self.userAgent copyWithZone:zone]; - copy.adjustConfig = [self.adjustConfig copyWithZone:zone]; } return copy; diff --git a/Adjust/AIPackageBuilder.h b/Adjust/AIPackageBuilder.h index 41b6f77b8..88927128c 100644 --- a/Adjust/AIPackageBuilder.h +++ b/Adjust/AIPackageBuilder.h @@ -16,6 +16,7 @@ @property (nonatomic, copy) AIDeviceInfo* deviceInfo; @property (nonatomic, copy) AIEvent* event; @property (nonatomic, copy) AIActivityState *activityState; +@property (nonatomic, copy) AdjustConfig *adjustConfig; // reattributions @property (nonatomic, copy) NSDictionary* deeplinkParameters; diff --git a/Adjust/AIPackageBuilder.m b/Adjust/AIPackageBuilder.m index c2af92bcd..0cd97c857 100644 --- a/Adjust/AIPackageBuilder.m +++ b/Adjust/AIPackageBuilder.m @@ -16,8 +16,8 @@ @implementation AIPackageBuilder - (AIActivityPackage *)buildSessionPackage { NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"last_interval"]; - [self parameters:parameters setDictionaryJson:self.deviceInfo.adjustConfig.callbackPermanentParameters forKey:@"callback_params"]; - [self parameters:parameters setDictionaryJson:self.deviceInfo.adjustConfig.partnerPermanentParameters forKey:@"partner_params"]; + [self parameters:parameters setDictionaryJson:self.adjustConfig.callbackPermanentParameters forKey:@"callback_params"]; + [self parameters:parameters setDictionaryJson:self.adjustConfig.partnerPermanentParameters forKey:@"partner_params"]; AIActivityPackage *sessionPackage = [self defaultActivityPackage]; sessionPackage.path = @"/startup"; @@ -36,10 +36,10 @@ - (AIActivityPackage *)buildEventPackage { [self parameters:parameters setString:self.event.eventToken forKey:@"event_token"]; // join the permanent parameters with the ones from the event - NSMutableDictionary * callbackParameters = [self joinParamters:self.deviceInfo.adjustConfig.callbackPermanentParameters parameters:self.event.callbackParameters]; + NSMutableDictionary * callbackParameters = [self joinParamters:self.adjustConfig.callbackPermanentParameters parameters:self.event.callbackParameters]; [self parameters:parameters setDictionaryJson:callbackParameters forKey:@"callback_params"]; - NSMutableDictionary * partnerParamters = [self joinParamters:self.deviceInfo.adjustConfig.partnerPermanentParameters parameters:self.event.partnerParameters]; + NSMutableDictionary * partnerParamters = [self joinParamters:self.adjustConfig.partnerPermanentParameters parameters:self.event.partnerParameters]; [self parameters:parameters setDictionaryJson:partnerParamters forKey:@"partner_params"]; AIActivityPackage *eventPackage = [self defaultActivityPackage]; @@ -53,7 +53,7 @@ - (AIActivityPackage *)buildEventPackage { - (AIActivityPackage *)buildClickPackage { NSMutableDictionary *parameters = [self defaultParameters]; - [self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"deeplink_parameters"]; + [self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"deeplink_params"]; [self parameters:parameters setBool:self.deviceInfo.isIad forKey:@"is_iad"]; AIActivityPackage *reattributionPackage = [self defaultActivityPackage]; @@ -75,14 +75,15 @@ - (AIActivityPackage *)defaultActivityPackage { - (NSMutableDictionary *)defaultParameters { NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; - [self constructDeviceInfo:self.deviceInfo withParameter:parameters]; + [self constructDeviceInfo:self.deviceInfo withParameter:parameters andConfig:self.adjustConfig]; [self constructActivityState:self.activityState withParamters:parameters]; return parameters; } - (void) constructDeviceInfo:(AIDeviceInfo *)deviceInfo - withParameter:(NSMutableDictionary *) parameters{ + withParameter:(NSMutableDictionary *) parameters + andConfig:(AdjustConfig*) adjustConfig{ [self constructUserAgent:deviceInfo.userAgent withParameters:parameters]; @@ -93,12 +94,12 @@ - (void) constructDeviceInfo:(AIDeviceInfo *)deviceInfo [self parameters:parameters setString:deviceInfo.vendorId forKey:@"idfv"]; [self parameters:parameters setString:deviceInfo.pushToken forKey:@"push_token"]; - if (deviceInfo.adjustConfig.macMd5TrackingEnabled) { - [self parameters:parameters setString:deviceInfo.macShortMd5 forKey:@"mac_md5"]; + if (adjustConfig.macMd5TrackingEnabled) { + [self parameters:parameters setString:deviceInfo.macShortMd5 forKey:@"mac_md5"]; } - [self parameters:parameters setString:deviceInfo.adjustConfig.appToken forKey:@"app_token"]; - [self parameters:parameters setString:deviceInfo.adjustConfig.environment forKey:@"environment"]; + [self parameters:parameters setString:adjustConfig.appToken forKey:@"app_token"]; + [self parameters:parameters setString:adjustConfig.environment forKey:@"environment"]; } - (void) constructActivityState:(AIActivityState *)activityState diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index 7417a0a0f..d83e03480 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -98,5 +98,33 @@ static NSString * const AIEnvironmentProduction = @"production"; + (void)setOfflineMode:(BOOL)enabled; ++ (void)setDelegate:(NSObject *)delegate; + ++ (void)addPermanentCallbackParameter:(NSString *)key + andValue:(NSString *)value; + ++ (void)addPermanentPartnerParameter:(NSString *)key + andValue:(NSString *)value; + ++ (id)getInstance; + +- (void)appDidLaunch:(AdjustConfig *)adjustConfig; + +- (void)trackEvent:(AIEvent *)event; +- (void)trackSubsessionStart; +- (void)trackSubsessionEnd; +- (void)setEnabled:(BOOL)enabled; +- (BOOL)isEnabled; +- (void)appWillOpenUrl:(NSURL *)url; +- (void)setDeviceToken:(NSData *)deviceToken; +- (void)setOfflineMode:(BOOL)enabled; +- (void)setDelegate:(NSObject *)delegate; + +- (void)addPermanentCallbackParameter:(NSString *)key + andValue:(NSString *)value; + +- (void)addPermanentPartnerParameter:(NSString *)key + andValue:(NSString *)value; + @end diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 7f87dae92..28f6c1fb9 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -9,51 +9,182 @@ #import "Adjust.h" #import "AIActivityHandler.h" #import "AIAdjustFactory.h" +#import "AILogger.h" #if !__has_feature(objc_arc) #error Adjust requires ARC // see README for details #endif +@interface Adjust() -static id activityHandler; +@property (nonatomic, retain) id activityHandler; +@property (nonatomic, retain) id logger; +@end #pragma mark - @implementation Adjust + (void)appDidLaunch:(AdjustConfig *)adjustConfig { - activityHandler = [AIAdjustFactory activityHandlerWithConfig:adjustConfig]; + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance appDidLaunch:adjustConfig]; } + (void)trackEvent:(AIEvent *)event { - [activityHandler trackEvent:event]; + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance trackEvent:event]; } + (void)trackSubsessionStart { - [activityHandler trackSubsessionStart]; + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance trackSubsessionStart]; } + (void)trackSubsessionEnd { - [activityHandler trackSubsessionEnd]; + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance trackSubsessionEnd]; } + (void)setEnabled:(BOOL)enabled { - [activityHandler setEnabled:enabled]; + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance setEnabled:enabled]; } + (BOOL)isEnabled { - return [activityHandler isEnabled]; + Adjust * defaultInstance = [Adjust getInstance]; + return [defaultInstance isEnabled]; } + (void)appWillOpenUrl:(NSURL *)url { - [activityHandler readOpenUrl:url]; + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance appWillOpenUrl:url]; } + (void)setDeviceToken:(NSData *)deviceToken { - [activityHandler savePushToken:deviceToken]; + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance setDeviceToken:deviceToken]; } + (void)setOfflineMode:(BOOL)enabled { - [activityHandler setOfflineMode:enabled]; + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance setOfflineMode:enabled]; +} + ++ (void)setDelegate:(NSObject *)delegate { + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance setDelegate:delegate]; +} + ++ (void)addPermanentCallbackParameter:(NSString *)key + andValue:(NSString *)value { + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance addPermanentCallbackParameter:key andValue:value]; +} + ++ (void)addPermanentPartnerParameter:(NSString *)key + andValue:(NSString *)value { + Adjust * defaultInstance = [Adjust getInstance]; + [defaultInstance addPermanentPartnerParameter:key andValue:value]; + +} + + ++ (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 = [AIAdjustFactory logger]; + + return self; +} + +- (void)appDidLaunch:(AdjustConfig *)adjustConfig { + if (self.activityHandler != nil) { + [self.logger error:@"Adjust already initialized"]; + return; + } + + self.activityHandler = [AIAdjustFactory activityHandlerWithConfig:adjustConfig]; +} + +- (void)trackEvent:(AIEvent *)event { + if (![self checkActivityHandler]) return; + [self.activityHandler trackEvent:event]; +} + +- (void)trackSubsessionStart { + if (![self checkActivityHandler]) return; + [self.activityHandler trackSubsessionStart]; +} + +- (void)trackSubsessionEnd { + if (![self checkActivityHandler]) return; + [self.activityHandler trackSubsessionEnd]; +} + +- (void)setEnabled:(BOOL)enabled { + if (![self checkActivityHandler]) return; + [self.activityHandler setEnabled:enabled]; +} + +- (BOOL)isEnabled { + if (![self checkActivityHandler]) return NO; + return [self.activityHandler isEnabled]; +} + +- (void)appWillOpenUrl:(NSURL *)url { + if (![self checkActivityHandler]) return; + [self.activityHandler appWillOpenUrl:url]; +} + +- (void)setDeviceToken:(NSData *)deviceToken { + if (![self checkActivityHandler]) return; + [self.activityHandler setDeviceToken:deviceToken]; +} + +- (void)setOfflineMode:(BOOL)enabled { + if (![self checkActivityHandler]) return; + [self.activityHandler setOfflineMode:enabled]; +} + +- (void)setDelegate:(NSObject *)delegate { + if (![self checkActivityHandler]) return; + [self.activityHandler setDelegate:delegate]; +} + +- (void)addPermanentCallbackParameter:(NSString *)key + andValue:(NSString *)value { + if (![self checkActivityHandler]) return; + [self.activityHandler addPermanentCallbackParameter:key andValue:value]; +} + +- (void)addPermanentPartnerParameter:(NSString *)key + andValue:(NSString *)value { + if (![self checkActivityHandler]) return; + [self.activityHandler addPermanentPartnerParameter:key andValue:value]; + +} + + +#pragma mark - private + +- (BOOL) checkActivityHandler { + if (self.activityHandler == nil) { + [self.logger error:@"Please initialize Adjust by calling 'appDidLaunch' before"]; + return NO; + } else { + return YES; + } } @end diff --git a/Adjust/AdjustConfig.h b/Adjust/AdjustConfig.h index f29af73f5..d2c498d08 100644 --- a/Adjust/AdjustConfig.h +++ b/Adjust/AdjustConfig.h @@ -47,6 +47,4 @@ - (void)addPermanentPartnerParameter:(NSString *)key andValue:(NSString *)value; - - @end diff --git a/AdjustTests/AIActivityHandlerMock.m b/AdjustTests/AIActivityHandlerMock.m index fc93c344a..efd611df1 100644 --- a/AdjustTests/AIActivityHandlerMock.m +++ b/AdjustTests/AIActivityHandlerMock.m @@ -73,11 +73,11 @@ - (BOOL)isEnabled { return YES; } -- (void)readOpenUrl:(NSURL *)url { +- (void)appWillOpenUrl:(NSURL *)url { [self.loggerMock test:[prefix stringByAppendingFormat:@"readOpenUrl"]]; } -- (void)savePushToken:(NSData *)pushToken { +- (void)setDeviceToken:(NSData *)pushToken { [self.loggerMock test:[prefix stringByAppendingFormat:@"savePushToken"]]; } diff --git a/AdjustTests/AIActivityHandlerTests.m b/AdjustTests/AIActivityHandlerTests.m index 3c272140f..2d432d1d8 100644 --- a/AdjustTests/AIActivityHandlerTests.m +++ b/AdjustTests/AIActivityHandlerTests.m @@ -201,7 +201,7 @@ - (void)testEventsBuffered { id activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"]; [activityHandler setBufferEvents:YES]; - [activityHandler savePushToken:nil]; + [activityHandler setDeviceToken:nil]; // construct the parameters of the the event NSDictionary *eventParameters = @{@"key": @"value", @"foo": @"bar" }; @@ -303,7 +303,7 @@ - (void)testEventsNotBuffered { // test push token const char bytes[] = "\xFC\x07\x21\xB6\xDF\xAD\x5E\xE1\x10\x97\x5B\xB2\xA2\x63\xDE\x00\x61\xCC\x70\x5B\x4A\x85\xA8\xAE\x3C\xCF\xBE\x7A\x66\x2F\xB1\xAB"; - [activityHandler savePushToken:[NSData dataWithBytes:bytes length:(sizeof(bytes) - 1)]]; + [activityHandler setDeviceToken:[NSData dataWithBytes:bytes length:(sizeof(bytes) - 1)]]; // the first is a normal event has parameters, the second a revenue [activityHandler trackEvent:@"abc123" withParameters:nil]; @@ -552,12 +552,12 @@ - (void)testOpenUrl { NSString* prefix = @"AdjustTests://example.com/path/inApp?adjust_=bar"; NSString* incomplete = @"AdjustTests://example.com/path/inApp?adjust_foo="; - [activityHandler readOpenUrl:[NSURL URLWithString:normal]]; - [activityHandler readOpenUrl:[NSURL URLWithString:emptyQueryString]]; - [activityHandler readOpenUrl:[NSURL URLWithString:emptyString]]; - [activityHandler readOpenUrl:[NSURL URLWithString:single]]; - [activityHandler readOpenUrl:[NSURL URLWithString:prefix]]; - [activityHandler readOpenUrl:[NSURL URLWithString:incomplete]]; + [activityHandler appWillOpenUrl:[NSURL URLWithString:normal]]; + [activityHandler appWillOpenUrl:[NSURL URLWithString:emptyQueryString]]; + [activityHandler appWillOpenUrl:[NSURL URLWithString:emptyString]]; + [activityHandler appWillOpenUrl:[NSURL URLWithString:single]]; + [activityHandler appWillOpenUrl:[NSURL URLWithString:prefix]]; + [activityHandler appWillOpenUrl:[NSURL URLWithString:incomplete]]; [NSThread sleepForTimeInterval:2]; From 8bb4e135af516cdb039ad2a122f1a7593ca45d8b Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 4 Nov 2014 16:10:09 +0100 Subject: [PATCH 09/86] Use logic from response data in attribution --- Adjust.xcodeproj/project.pbxproj | 6 -- Adjust/AIActivityHandler.h | 2 +- Adjust/AIActivityHandler.m | 16 +++-- Adjust/AIAttribution.h | 2 + Adjust/AIAttribution.m | 60 ++++++++++------- Adjust/AIAttributionHandler.h | 3 + Adjust/AIAttributionHandler.m | 56 ++++++++++------ Adjust/AIPackageHandler.h | 2 +- Adjust/AIPackageHandler.m | 5 +- Adjust/AIRequestHandler.m | 19 +++--- Adjust/AIResponseData.h | 77 ---------------------- Adjust/AIResponseData.m | 110 ------------------------------- Adjust/Adjust.h | 1 - 13 files changed, 99 insertions(+), 260 deletions(-) delete mode 100644 Adjust/AIResponseData.h delete mode 100644 Adjust/AIResponseData.m diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index e089abe34..061355746 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -36,7 +36,6 @@ 96E5E39418BBB48A008E7B30 /* AIPackageBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37618BBB48A008E7B30 /* AIPackageBuilder.m */; }; 96E5E39518BBB48A008E7B30 /* AIPackageHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37818BBB48A008E7B30 /* AIPackageHandler.m */; }; 96E5E39618BBB48A008E7B30 /* AIRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37A18BBB48A008E7B30 /* AIRequestHandler.m */; }; - 96E5E39718BBB48A008E7B30 /* AIResponseData.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37C18BBB48A008E7B30 /* AIResponseData.m */; }; 96E5E39818BBB48A008E7B30 /* AITimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37E18BBB48A008E7B30 /* AITimer.m */; }; 96E5E39918BBB48A008E7B30 /* AIUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E38018BBB48A008E7B30 /* AIUtil.m */; }; 96E5E3AF18BBB49E008E7B30 /* AIActivityHandlerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E39E18BBB49E008E7B30 /* AIActivityHandlerMock.m */; }; @@ -126,8 +125,6 @@ 96E5E37818BBB48A008E7B30 /* AIPackageHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIPackageHandler.m; sourceTree = ""; }; 96E5E37918BBB48A008E7B30 /* AIRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIRequestHandler.h; sourceTree = ""; }; 96E5E37A18BBB48A008E7B30 /* AIRequestHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIRequestHandler.m; sourceTree = ""; }; - 96E5E37B18BBB48A008E7B30 /* AIResponseData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIResponseData.h; sourceTree = ""; }; - 96E5E37C18BBB48A008E7B30 /* AIResponseData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIResponseData.m; sourceTree = ""; }; 96E5E37D18BBB48A008E7B30 /* AITimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AITimer.h; sourceTree = ""; }; 96E5E37E18BBB48A008E7B30 /* AITimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AITimer.m; sourceTree = ""; }; 96E5E37F18BBB48A008E7B30 /* AIUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIUtil.h; sourceTree = ""; }; @@ -257,8 +254,6 @@ 96E5E37818BBB48A008E7B30 /* AIPackageHandler.m */, 96E5E37918BBB48A008E7B30 /* AIRequestHandler.h */, 96E5E37A18BBB48A008E7B30 /* AIRequestHandler.m */, - 96E5E37B18BBB48A008E7B30 /* AIResponseData.h */, - 96E5E37C18BBB48A008E7B30 /* AIResponseData.m */, 96E5E37D18BBB48A008E7B30 /* AITimer.h */, 96E5E37E18BBB48A008E7B30 /* AITimer.m */, 96E5E37F18BBB48A008E7B30 /* AIUtil.h */, @@ -402,7 +397,6 @@ 96E5E39618BBB48A008E7B30 /* AIRequestHandler.m in Sources */, 96E5E39918BBB48A008E7B30 /* AIUtil.m in Sources */, 96E5E39818BBB48A008E7B30 /* AITimer.m in Sources */, - 96E5E39718BBB48A008E7B30 /* AIResponseData.m in Sources */, 96E5E39118BBB48A008E7B30 /* UIDevice+AIAdditions.m in Sources */, 96E5E38C18BBB48A008E7B30 /* AIActivityKind.m in Sources */, 96E5E38D18BBB48A008E7B30 /* AIActivityPackage.m in Sources */, diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index 28752eec3..58a1c5956 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -18,7 +18,7 @@ - (void)trackEvent:(AIEvent *)event; -- (void)finishedTrackingWithResponse:(NSString *)deepLink; +- (void)finishedTrackingWithResponse:(NSDictionary *)jsonDict; - (void)setEnabled:(BOOL)enabled; - (BOOL)isEnabled; - (void)appWillOpenUrl:(NSURL*)url; diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index f63d5dab1..cf3736ce5 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -96,14 +96,15 @@ - (void)trackEvent:(AIEvent *)event }); } -- (void)finishedTrackingWithResponse:(NSString *)deepLink{ - [self launchDeepLink:deepLink]; - if (self.attribution == nil) { - [self.attributionHandler getAttribution]; - } +- (void)finishedTrackingWithResponse:(NSDictionary *)jsonDict{ + [self launchDeepLink:jsonDict]; + [self.attributionHandler checkAttribution:jsonDict]; } -- (void)launchDeepLink:(NSString *) deepLink{ +- (void)launchDeepLink:(NSDictionary *)jsonDict{ + if (jsonDict == nil) return; + + NSString * deepLink = [jsonDict objectForKey:@"deeplink"]; if (deepLink == nil) return; NSURL* deepLinkUrl = [NSURL URLWithString:deepLink]; @@ -187,7 +188,6 @@ - (void)changedAttributionDelegate:(AIAttribution *)attribution { } self.attribution = attribution; [self writeAttribution]; - // TODO write attribution to file if (![self.delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { return; } @@ -391,6 +391,8 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { [adjustDeepLinks setObject:value forKey:keyWOutPrefix]; } + [self.attributionHandler getAttribution]; + if (adjustDeepLinks.count == 0) { return; } diff --git a/Adjust/AIAttribution.h b/Adjust/AIAttribution.h index 3147ca5e3..42430f9cb 100644 --- a/Adjust/AIAttribution.h +++ b/Adjust/AIAttribution.h @@ -31,6 +31,8 @@ // tracker creative @property (nonatomic, copy) NSString *creative; +@property (nonatomic, assign) BOOL finalAttribution; + - (BOOL)isEqualToAttribution:(AIAttribution *)attribution; + (AIAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict; diff --git a/Adjust/AIAttribution.m b/Adjust/AIAttribution.m index da8013b60..d9ec91ef9 100644 --- a/Adjust/AIAttribution.m +++ b/Adjust/AIAttribution.m @@ -10,6 +10,31 @@ @implementation AIAttribution ++ (AIAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict { + return [[AIAttribution alloc] initWithJsonDict:jsonDict]; +} + +- (id)initWithJsonDict:(NSDictionary *)jsonDict { + self = [super init]; + if (self == nil) return nil; + + if (jsonDict == nil) { + return nil; + } + + self.trackerToken = [jsonDict objectForKey:@"tracker_token"]; + self.trackerName = [jsonDict objectForKey:@"tracker_name"]; + self.network = [jsonDict objectForKey:@"network"]; + self.campaign = [jsonDict objectForKey:@"campaign"]; + self.adgroup = [jsonDict objectForKey:@"adgroup"]; + self.creative = [jsonDict objectForKey:@"creative"]; + if ([[jsonDict objectForKey:@"final"] isEqualToString:@"true"]) { + self.finalAttribution = YES; + } + + return self; +} + - (BOOL)isEqualToAttribution:(AIAttribution *)attribution { if (attribution == nil) { return NO; @@ -32,29 +57,10 @@ - (BOOL)isEqualToAttribution:(AIAttribution *)attribution { if (![self.creative isEqualToString:attribution.creative]) { return NO; } - return YES; -} - -+ (AIAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict { - return [[AIAttribution alloc] initWithJsonDict:jsonDict]; -} - -- (id)initWithJsonDict:(NSDictionary *)jsonDict { - self = [super init]; - if (self == nil) return nil; - - if (jsonDict == nil) { - return nil; + if (self.finalAttribution != attribution.finalAttribution) { + return NO; } - - self.trackerToken = [jsonDict objectForKey:@"tracker_token"]; - self.trackerName = [jsonDict objectForKey:@"tracker_name"]; - self.network = [jsonDict objectForKey:@"network"]; - self.campaign = [jsonDict objectForKey:@"campaign"]; - self.adgroup = [jsonDict objectForKey:@"adgroup"]; - self.creative = [jsonDict objectForKey:@"creative"]; - - return self; + return YES; } - (NSDictionary *)dictionary { @@ -83,7 +89,10 @@ - (NSDictionary *)dictionary { if (self.creative != nil) { [responseDataDic setObject:self.creative forKey:@"creative"]; } - + + [responseDataDic setObject:(self.finalAttribution? @"true" : @"false") forKey:@"final"]; + + return responseDataDic; } @@ -117,6 +126,7 @@ - (NSUInteger)hash { result = prime * result + [self.campaign hash]; result = prime * result + [self.adgroup hash]; result = prime * result + [self.creative hash]; + result = prime * result + self.finalAttribution; return result; } @@ -133,6 +143,9 @@ - (id)initWithCoder:(NSCoder *)decoder { self.campaign = [decoder decodeObjectForKey:@"campaign"]; self.adgroup = [decoder decodeObjectForKey:@"adgroup"]; self.creative = [decoder decodeObjectForKey:@"creative"]; + if ([[decoder decodeObjectForKey:@"final"] isEqualToString:@"true"]) { + self.finalAttribution = YES; + } return self; } @@ -144,6 +157,7 @@ - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:self.campaign forKey:@"campaign"]; [encoder encodeObject:self.adgroup forKey:@"adgroup"]; [encoder encodeObject:self.creative forKey:@"creative"]; + [encoder encodeObject:(self.finalAttribution? @"true" : @"false") forKey:@"final"]; } @end diff --git a/Adjust/AIAttributionHandler.h b/Adjust/AIAttributionHandler.h index f029632e5..dddd7f70c 100644 --- a/Adjust/AIAttributionHandler.h +++ b/Adjust/AIAttributionHandler.h @@ -13,9 +13,12 @@ - (id)initWithActivityHandler:(id) activityHandler; +- (void)checkAttribution:(NSDictionary *)jsonDict; + - (void)getAttribution; - (void)setAttributionMaxTime:(double)seconds; +// TODO @end diff --git a/Adjust/AIAttributionHandler.m b/Adjust/AIAttributionHandler.m index c565cf711..236f4bd76 100644 --- a/Adjust/AIAttributionHandler.m +++ b/Adjust/AIAttributionHandler.m @@ -38,7 +38,7 @@ - (id)initWithActivityHandler:(id) activityHandler { self = [super init]; if (self == nil) return nil; - self.internalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0); + self.internalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); self.activityHandler = activityHandler; self.logger = AIAdjustFactory.logger; self.url = [NSURL URLWithString:AIUtil.baseUrl]; @@ -46,15 +46,35 @@ - (id)initWithActivityHandler:(id) activityHandler { return self; } -// comunicate with server + +- (void) checkAttribution:(NSDictionary *)jsonDict { + dispatch_async(self.internalQueue, ^{ + [self checkAttributionInternal:jsonDict]; + }); +} + - (void) getAttribution { dispatch_async(self.internalQueue, ^{ - [self checkAttributionInternal]; + [self getAttributionInternal]; }); + } #pragma mark - internal --(void) checkAttributionInternal { +-(void) checkAttributionInternal:(NSDictionary *)jsonDict { + // compare if there is difference from current attribution at activity handler to launch the delegate + [self compareAttribution:jsonDict]; + + // check if response json contains instrunction to retry after some time + NSNumber * timer_seconds = [jsonDict objectForKey:@"timer"]; + if (timer_seconds == nil) return; + + uint64_t timer_nano = [timer_seconds intValue] * NSEC_PER_SEC; + self.timer = [AITimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self getAttributionInternal]; }]; + [self.timer resume]; +} + +-(void) getAttributionInternal { NSMutableURLRequest *request = [self request]; NSError *requestError; NSURLResponse *urlResponse = nil; @@ -69,6 +89,8 @@ -(void) checkAttributionInternal { } NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; + [self.logger verbose:@"attribution response: %@", responseString]; + NSDictionary *jsonDict = [AIUtil buildJsonDict:responseString]; if (jsonDict == nil) { @@ -76,29 +98,23 @@ -(void) checkAttributionInternal { return; } - // check if response contains attribution - NSDictionary *jsonAttribution = [jsonDict objectForKey:@"attribution"]; - if (jsonAttribution == nil) { - // read time to wait and set timer to re-try - NSNumber * timer_seconds = [jsonDict objectForKey:@"timer"]; - uint64_t timer_nano = [timer_seconds intValue] * NSEC_PER_SEC; - self.timer = [AITimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self checkAttributionInternal]; }]; - [self.timer resume]; - return; - } + [self checkAttributionInternal:jsonDict]; +} - // check if new attribution is different from previous - AIAttribution * attributionResponse = [AIAttribution dataWithJsonDict:jsonAttribution]; +-(void)compareAttribution:(NSDictionary *)jsonDict { + NSDictionary* jsonAttribution = [jsonDict objectForKey:@"attribution"]; + if (jsonAttribution == nil) return; - if ([attributionResponse isEqual:self.activityHandler.attribution]) { - // TODO reset? + AIAttribution * attribution = [AIAttribution dataWithJsonDict:jsonAttribution]; + + if ([attribution isEqual:self.activityHandler.attribution]) { return; } - // if so, launch response delegate - [self.activityHandler changedAttributionDelegate:attributionResponse]; + [self.activityHandler changedAttributionDelegate:attribution]; } + #pragma mark - private - (NSMutableURLRequest *)request { diff --git a/Adjust/AIPackageHandler.h b/Adjust/AIPackageHandler.h index 2aed3ec69..4473eb94d 100644 --- a/Adjust/AIPackageHandler.h +++ b/Adjust/AIPackageHandler.h @@ -22,7 +22,7 @@ - (void)pauseSending; - (void)resumeSending; -- (void)finishedTrackingActivity:(NSString *) deepLink; +- (void)finishedTrackingActivity:(NSDictionary *)jsonDict; @end diff --git a/Adjust/AIPackageHandler.m b/Adjust/AIPackageHandler.m index fd61f71e9..f8afdf605 100644 --- a/Adjust/AIPackageHandler.m +++ b/Adjust/AIPackageHandler.m @@ -10,7 +10,6 @@ #import "AIActivityHandler.h" #import "AIRequestHandler.h" #import "AIActivityPackage.h" -#import "AIResponseData.h" #import "AILogger.h" #import "AIUtil.h" #import "AIAdjustFactory.h" @@ -84,8 +83,8 @@ - (void)resumeSending { self.paused = NO; } -- (void)finishedTrackingActivity:(NSString *) deepLink{ - [self.activityHandler finishedTrackingWithResponse:deepLink]; +- (void)finishedTrackingActivity:(NSDictionary *)jsonDict{ + [self.activityHandler finishedTrackingWithResponse:jsonDict]; } #pragma mark - internal diff --git a/Adjust/AIRequestHandler.m b/Adjust/AIRequestHandler.m index f4985302f..e5fbc2d91 100644 --- a/Adjust/AIRequestHandler.m +++ b/Adjust/AIRequestHandler.m @@ -7,7 +7,6 @@ // #import "AIActivityPackage.h" -#import "AIResponseData.h" #import "AILogger.h" #import "AIUtil.h" #import "NSString+AIAdditions.h" @@ -67,30 +66,27 @@ - (void)sendInternal:(AIActivityPackage *)package { // connection error if (error != nil) { - AIResponseData *responseData = [AIResponseData dataWithError:error.localizedDescription]; - responseData.willRetry = YES; - [self.logger error:@"%@. (%@) Will retry later.", package.failureMessage, responseData.error]; + [self.logger error:@"%@. (%@) Will retry later.", package.failureMessage, error.localizedDescription]; [self.packageHandler finishedTrackingActivity:nil]; [self.packageHandler closeFirstPackage]; return; } NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - NSDictionary *jsonDict = [AIUtil buildJsonDict:responseString]; - AIResponseData *responseData = [AIResponseData dataWithJsonDict:jsonDict jsonString:responseString]; + [self.logger verbose:@"package response: %@", responseString]; + NSDictionary *jsonDict = [AIUtil buildJsonDict:responseString]; if (response.statusCode == 200) { - // success - responseData.success = YES; [self.logger info:@"%@", package.successMessage]; } else { // wrong status code - [self.logger error:@"%@. (%@)", package.failureMessage, responseData.error]; + NSString * errorServerMessage = [jsonDict objectForKey:@"error"]; + [self.logger error:@"%@. (%@)", package.failureMessage, errorServerMessage]; } - NSString * deepLink = [jsonDict objectForKey:@"deeplink"]; + //NSString * deepLink = [jsonDict objectForKey:@"deeplink"]; - [self.packageHandler finishedTrackingActivity:deepLink]; + [self.packageHandler finishedTrackingActivity:jsonDict]; [self.packageHandler sendNextPackage]; } @@ -127,4 +123,5 @@ - (NSData *)bodyForParameters:(NSDictionary *)parameters { NSData *body = [NSData dataWithBytes:bodyString.UTF8String length:bodyString.length]; return body; } + @end diff --git a/Adjust/AIResponseData.h b/Adjust/AIResponseData.h deleted file mode 100644 index cb70ccec6..000000000 --- a/Adjust/AIResponseData.h +++ /dev/null @@ -1,77 +0,0 @@ -// -// AIResponseData.h -// Adjust -// -// Created by Christian Wellenbrock on 07.02.14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// - -#import "AIActivityKind.h" - -@class AIActivityPackage; - -/* - * Information about the result of a tracking attempt - * - * Will be passed to the delegate function adjustFinishedTrackingWithResponse: - */ -@interface AIResponseData : NSObject - -#pragma mark set by SDK - -// the kind of activity (AIActivityKindSession etc.) -// see the AIActivityKind definition -@property (nonatomic, assign) AIActivityKind activityKind; - -// true when the activity was tracked successfully -// might be true even if response could not be parsed -@property (nonatomic, assign) BOOL success; - -// true if the server was not reachable and the request will be tried again later -@property (nonatomic, assign) BOOL willRetry; - -#pragma mark set by server or SDK -// nil if activity was tracked successfully and response could be parsed -// might be not nil even when activity was tracked successfully -@property (nonatomic, copy) NSString *error; - -#pragma mark returned by server -// the following attributes are only set when error is nil -// (when activity was tracked successfully and response could be parsed) - -// tracker token of current device -@property (nonatomic, copy) NSString *trackerToken; - -// tracker name of current device -@property (nonatomic, copy) NSString *trackerName; - -// tracker network -@property (nonatomic, copy) NSString *network; - -// tracker campaign -@property (nonatomic, copy) NSString *campaign; - -// tracker adgroup -@property (nonatomic, copy) NSString *adgroup; - -// tracker creative -@property (nonatomic, copy) NSString *creative; - - -// returns human readable version of activityKind -// (session, event, revenue), see above -- (NSString *)activityKindString; - -// returns a NSDictonary representation -- (NSDictionary *)dictionary; - - -#pragma mark internals - -+ (AIResponseData *)dataWithJsonDict:(NSDictionary *)jsonDict jsonString:(NSString *)jsonString; -+ (AIResponseData *)dataWithError:(NSString *)error; - -- (id)initWithJsonDict:(NSDictionary *)jsonDict jsonString:(NSString *)jsonString; -- (id)initWithError:(NSString *)error; - -@end diff --git a/Adjust/AIResponseData.m b/Adjust/AIResponseData.m deleted file mode 100644 index 7d4744388..000000000 --- a/Adjust/AIResponseData.m +++ /dev/null @@ -1,110 +0,0 @@ -// -// AIResponseData.m -// Adjust -// -// Created by Christian Wellenbrock on 07.02.14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// - -#import "AIResponseData.h" -#import "NSString+AIAdditions.h" - -@implementation AIResponseData - -+ (AIResponseData *)dataWithJsonDict:(NSDictionary *)jsonDict jsonString:(NSString *)jsonString { - return [[AIResponseData alloc] initWithJsonDict:jsonDict jsonString:jsonString]; -} - -+ (AIResponseData *)dataWithError:(NSString *)error { - return [[AIResponseData alloc] initWithError:error]; -} - -- (id)initWithJsonDict:(NSDictionary *)jsonDict jsonString:(NSString *)jsonString { - self = [super init]; - if (self == nil) return nil; - - if (jsonDict == nil) { - self.error = [NSString stringWithFormat:@"Failed to parse json response: %@", jsonString.aiTrim]; - return self; - } - - self.error = [jsonDict objectForKey:@"error"]; - self.trackerToken = [jsonDict objectForKey:@"tracker_token"]; - self.trackerName = [jsonDict objectForKey:@"tracker_name"]; - self.network = [jsonDict objectForKey:@"network"]; - self.campaign = [jsonDict objectForKey:@"campaign"]; - self.adgroup = [jsonDict objectForKey:@"adgroup"]; - self.creative = [jsonDict objectForKey:@"creative"]; - - return self; -} - -- (id)initWithError:(NSString *)error { - self = [super init]; - if (self == nil) return nil; - - self.success = NO; - self.error = error; - - return self; -} - -- (NSString *)activityKindString { - return AIActivityKindToString(self.activityKind); -} - -- (NSString *)description { - return [NSString stringWithFormat:@"[kind:%@ success:%d willRetry:%d " - "error:%@ trackerToken:%@ trackerName:%@ " - "network:%@ campaign:%@ adgroup:%@ creative:%@]", - self.activityKindString, - self.success, - self.willRetry, - self.error.aiQuote, - self.trackerToken, - self.trackerName.aiQuote, - self.network.aiQuote, - self.campaign.aiQuote, - self.adgroup.aiQuote, - self.creative.aiQuote]; -} - -- (NSDictionary *)dictionary { - NSMutableDictionary * responseDataDic = [NSMutableDictionary dictionaryWithDictionary:@{ - @"activityKind" : self.activityKindString, - @"success" : (self.success ? @"true" : @"false"), - @"willRetry" : (self.willRetry ? @"true" : @"false"), - }]; - - if (self.error != nil) { - [responseDataDic setObject:self.error forKey:@"error"]; - } - - if (self.trackerToken != nil) { - [responseDataDic setObject:self.trackerToken forKey:@"trackerToken"]; - } - - if (self.trackerName != nil) { - [responseDataDic setObject:self.trackerName forKey:@"trackerName"]; - } - - if (self.network != nil) { - [responseDataDic setObject:self.network forKey:@"network"]; - } - - if (self.campaign != nil) { - [responseDataDic setObject:self.campaign forKey:@"campaign"]; - } - - if (self.adgroup != nil) { - [responseDataDic setObject:self.adgroup forKey:@"adgroup"]; - } - - if (self.creative != nil) { - [responseDataDic setObject:self.creative forKey:@"creative"]; - } - - return responseDataDic; -} - -@end diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index d83e03480..178d4c843 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -7,7 +7,6 @@ // #import "AILogger.h" -#import "AIResponseData.h" #import "AIEvent.h" #import "AIAttribution.h" #import "AdjustConfig.h" From 202a4542b01f09d055c04605d40147a17d90d2f0 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 4 Nov 2014 17:24:57 +0100 Subject: [PATCH 10/86] Click package in new queue --- Adjust/AIActivityHandler.m | 32 +++++++++++++++----------------- Adjust/AIAttributionHandler.m | 1 + Adjust/AIPackageBuilder.m | 2 +- Adjust/AIPackageHandler.h | 2 +- Adjust/AIPackageHandler.m | 4 ++++ Adjust/AIRequestHandler.h | 1 + Adjust/AIRequestHandler.m | 20 ++++++++++++++------ 7 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index cf3736ce5..e049aa8e4 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -156,14 +156,13 @@ - (void)setDeviceToken:(NSData *)deviceToken { - (void)setIsIad:(BOOL)isIad { self.deviceInfo.isIad = isIad; if (isIad) { - AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init]; - reattributionBuilder.deviceInfo = self.deviceInfo; - reattributionBuilder.adjustConfig = self.adjustConfig; - reattributionBuilder.activityState = self.activityState; + AIPackageBuilder *clickBuilder = [[AIPackageBuilder alloc] init]; + clickBuilder.deviceInfo = self.deviceInfo; + clickBuilder.adjustConfig = self.adjustConfig; + clickBuilder.activityState = self.activityState; - AIActivityPackage *reattributionPackage = [reattributionBuilder buildClickPackage]; - [self.packageHandler addPackage:reattributionPackage]; - [self.packageHandler sendFirstPackage]; + AIActivityPackage *reattributionPackage = [clickBuilder buildClickPackage]; + [self.packageHandler sendClickPackage:reattributionPackage]; } } @@ -397,18 +396,17 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { return; } - AIPackageBuilder *reattributionBuilder = [[AIPackageBuilder alloc] init]; - reattributionBuilder.deeplinkParameters = adjustDeepLinks; - reattributionBuilder.adjustConfig = self.adjustConfig; - reattributionBuilder.deviceInfo = self.deviceInfo; - reattributionBuilder.activityState = self.activityState; - reattributionBuilder.deeplinkParameters = adjustDeepLinks; + AIPackageBuilder *ClickBuilder = [[AIPackageBuilder alloc] init]; + ClickBuilder.deeplinkParameters = adjustDeepLinks; + ClickBuilder.adjustConfig = self.adjustConfig; + ClickBuilder.deviceInfo = self.deviceInfo; + ClickBuilder.activityState = self.activityState; + ClickBuilder.deeplinkParameters = adjustDeepLinks; - AIActivityPackage *reattributionPackage = [reattributionBuilder buildClickPackage]; - [self.packageHandler addPackage:reattributionPackage]; - [self.packageHandler sendFirstPackage]; + AIActivityPackage *reattributionPackage = [ClickBuilder buildClickPackage]; + [self.packageHandler sendClickPackage:reattributionPackage]; - [self.logger debug:@"Reattribution %@", adjustDeepLinks]; + [self.logger debug:@"ClickPackage %@", adjustDeepLinks]; } - (void) setDeviceTokenInternal:(NSData *)deviceToken { diff --git a/Adjust/AIAttributionHandler.m b/Adjust/AIAttributionHandler.m index 236f4bd76..54e015be5 100644 --- a/Adjust/AIAttributionHandler.m +++ b/Adjust/AIAttributionHandler.m @@ -62,6 +62,7 @@ - (void) getAttribution { #pragma mark - internal -(void) checkAttributionInternal:(NSDictionary *)jsonDict { + if (jsonDict == nil) return; // compare if there is difference from current attribution at activity handler to launch the delegate [self compareAttribution:jsonDict]; diff --git a/Adjust/AIPackageBuilder.m b/Adjust/AIPackageBuilder.m index 0cd97c857..36ca813d9 100644 --- a/Adjust/AIPackageBuilder.m +++ b/Adjust/AIPackageBuilder.m @@ -15,7 +15,7 @@ @implementation AIPackageBuilder - (AIActivityPackage *)buildSessionPackage { NSMutableDictionary *parameters = [self defaultParameters]; - [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"last_interval"]; + [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"callback_params"]; [self parameters:parameters setDictionaryJson:self.adjustConfig.callbackPermanentParameters forKey:@"callback_params"]; [self parameters:parameters setDictionaryJson:self.adjustConfig.partnerPermanentParameters forKey:@"partner_params"]; diff --git a/Adjust/AIPackageHandler.h b/Adjust/AIPackageHandler.h index 4473eb94d..aad5ba4f6 100644 --- a/Adjust/AIPackageHandler.h +++ b/Adjust/AIPackageHandler.h @@ -21,8 +21,8 @@ - (void)closeFirstPackage; - (void)pauseSending; - (void)resumeSending; - - (void)finishedTrackingActivity:(NSDictionary *)jsonDict; +- (void)sendClickPackage:(AIActivityPackage *) clickPackage; @end diff --git a/Adjust/AIPackageHandler.m b/Adjust/AIPackageHandler.m index f8afdf605..617119c97 100644 --- a/Adjust/AIPackageHandler.m +++ b/Adjust/AIPackageHandler.m @@ -87,6 +87,10 @@ - (void)finishedTrackingActivity:(NSDictionary *)jsonDict{ [self.activityHandler finishedTrackingWithResponse:jsonDict]; } +- (void)sendClickPackage:(AIActivityPackage *)clickPackage { + [self.requestHandler sendClickPackage:clickPackage]; +} + #pragma mark - internal - (void)initInternal { self.requestHandler = [AIAdjustFactory requestHandlerForPackageHandler:self]; diff --git a/Adjust/AIRequestHandler.h b/Adjust/AIRequestHandler.h index e648e027a..99c1e1e1a 100644 --- a/Adjust/AIRequestHandler.h +++ b/Adjust/AIRequestHandler.h @@ -16,6 +16,7 @@ - (void)sendPackage:(AIActivityPackage *)activityPackage; +- (void)sendClickPackage:(AIActivityPackage *)clickPackage; @end diff --git a/Adjust/AIRequestHandler.m b/Adjust/AIRequestHandler.m index e5fbc2d91..be6b81b9d 100644 --- a/Adjust/AIRequestHandler.m +++ b/Adjust/AIRequestHandler.m @@ -48,13 +48,19 @@ - (id)initWithPackageHandler:(id) packageHandler { - (void)sendPackage:(AIActivityPackage *)activityPackage { dispatch_async(self.internalQueue, ^{ - [self sendInternal:activityPackage]; + [self sendInternal:activityPackage sendToPackageHandler:YES]; + }); +} + +- (void)sendClickPackage:(AIActivityPackage *)clickPackage { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + [self sendInternal:clickPackage sendToPackageHandler:NO]; }); } #pragma mark - internal -- (void)sendInternal:(AIActivityPackage *)package { +- (void)sendInternal:(AIActivityPackage *)package sendToPackageHandler:(BOOL)sendToPackageHandler{ if (self.packageHandler == nil) return; NSMutableURLRequest *request = [self requestForPackage:package]; @@ -68,7 +74,9 @@ - (void)sendInternal:(AIActivityPackage *)package { if (error != nil) { [self.logger error:@"%@. (%@) Will retry later.", package.failureMessage, error.localizedDescription]; [self.packageHandler finishedTrackingActivity:nil]; - [self.packageHandler closeFirstPackage]; + if (sendToPackageHandler) { + [self.packageHandler closeFirstPackage]; + } return; } @@ -84,10 +92,10 @@ - (void)sendInternal:(AIActivityPackage *)package { [self.logger error:@"%@. (%@)", package.failureMessage, errorServerMessage]; } - //NSString * deepLink = [jsonDict objectForKey:@"deeplink"]; - [self.packageHandler finishedTrackingActivity:jsonDict]; - [self.packageHandler sendNextPackage]; + if (sendToPackageHandler) { + [self.packageHandler sendNextPackage]; + } } #pragma mark - private From 935a8010d7d9970ec0a82c9a3a682444074e7288 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 10 Nov 2014 16:51:18 +0100 Subject: [PATCH 11/86] Response message and errors --- Adjust/AIActivityHandler.h | 2 -- Adjust/AIActivityHandler.m | 57 ++++++++++++++------------------------ Adjust/AIPackageBuilder.h | 6 +++- Adjust/AIPackageBuilder.m | 23 ++++++++++++++- Adjust/AIRequestHandler.m | 26 ++++++++++++----- Adjust/AIUtil.m | 2 +- Adjust/Adjust.h | 3 -- Adjust/AdjustConfig.h | 1 - 8 files changed, 68 insertions(+), 52 deletions(-) diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index 58a1c5956..93f25faf7 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -31,8 +31,6 @@ - (void) setOfflineMode:(BOOL)enabled; -- (void)setDelegate:(NSObject *)delegate; - - (void)addPermanentCallbackParameter:(NSString *)key andValue:(NSString *)value; diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index e049aa8e4..fab56a71c 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -65,6 +65,7 @@ - (id)initWithConfig:(AdjustConfig *)adjustConfig { return nil; } + self.logger = AIAdjustFactory.logger; [self addNotificationObserver]; self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); self.logger = AIAdjustFactory.logger; @@ -156,10 +157,9 @@ - (void)setDeviceToken:(NSData *)deviceToken { - (void)setIsIad:(BOOL)isIad { self.deviceInfo.isIad = isIad; if (isIad) { - AIPackageBuilder *clickBuilder = [[AIPackageBuilder alloc] init]; - clickBuilder.deviceInfo = self.deviceInfo; - clickBuilder.adjustConfig = self.adjustConfig; - clickBuilder.activityState = self.activityState; + AIPackageBuilder *clickBuilder = [[AIPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + andActivityState:self.activityState + andConfig:self.adjustConfig]; AIActivityPackage *reattributionPackage = [clickBuilder buildClickPackage]; [self.packageHandler sendClickPackage:reattributionPackage]; @@ -170,17 +170,6 @@ - (void)setAttributionMaxTime:(double)seconds { [self.attributionHandler setAttributionMaxTime:seconds]; } -/* -- (AIAttribution*) attribution { - return self.attribution; -} - -- (void) setAttribution:(AIAttribution*)attribution { - _attribution = attribution; -} -*/ - - - (void)changedAttributionDelegate:(AIAttribution *)attribution { if (attribution == nil) { return; @@ -218,6 +207,12 @@ - (void)initInternal:(AdjustConfig *)adjustConfig { self.adjustConfig = adjustConfig; self.deviceInfo = [[AIDeviceInfo alloc] init]; + if ([adjustConfig.environment isEqualToString:AIEnvironmentProduction]) { + [self.logger setLogLevel:AILogLevelAssert]; + } else { + [self.logger setLogLevel:adjustConfig.logLevel]; + } + NSString *macAddress = UIDevice.currentDevice.aiMacAddress; NSString *macShort = macAddress.aiRemoveColons; @@ -235,18 +230,12 @@ - (void)initInternal:(AdjustConfig *)adjustConfig { self.deviceInfo.clientSdk = [NSString stringWithFormat:@"%@@%@", adjustConfig.sdkPrefix, AIUtil.clientSdk]; } - [AIAdjustFactory.logger info:@"Tracking of macMd5 is %@", adjustConfig.macMd5TrackingEnabled ? @"enabled" : @"disabled"]; + [self.logger info:@"Tracking of macMd5 is %@", adjustConfig.macMd5TrackingEnabled ? @"enabled" : @"disabled"]; if (adjustConfig.eventBufferingEnabled) { [self.logger info:@"Event buffering is enabled"]; } - if ([adjustConfig.environment isEqualToString:AIEnvironmentProduction]) { - [self.logger setLogLevel:AILogLevelAssert]; - } else { - [self.logger setLogLevel:adjustConfig.logLevel]; - } - self.delegate = adjustConfig.delegate; [[UIDevice currentDevice] aiSetIad:self]; @@ -351,11 +340,10 @@ - (void)eventInternal:(AIEvent *)event self.activityState.eventCount++; // create and populate event package - AIPackageBuilder *eventBuilder = [[AIPackageBuilder alloc] init]; + AIPackageBuilder *eventBuilder = [[AIPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + andActivityState:self.activityState + andConfig:self.adjustConfig]; eventBuilder.event = event; - eventBuilder.adjustConfig = self.adjustConfig; - eventBuilder.deviceInfo = self.deviceInfo; - eventBuilder.activityState = self.activityState; AIActivityPackage *eventPackage = [eventBuilder buildEventPackage]; [self.packageHandler addPackage:eventPackage]; @@ -396,13 +384,11 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { return; } - AIPackageBuilder *ClickBuilder = [[AIPackageBuilder alloc] init]; + AIPackageBuilder *ClickBuilder = [[AIPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + andActivityState:self.activityState + andConfig:self.adjustConfig]; ClickBuilder.deeplinkParameters = adjustDeepLinks; - ClickBuilder.adjustConfig = self.adjustConfig; - ClickBuilder.deviceInfo = self.deviceInfo; - ClickBuilder.activityState = self.activityState; - ClickBuilder.deeplinkParameters = adjustDeepLinks; - + AIActivityPackage *reattributionPackage = [ClickBuilder buildClickPackage]; [self.packageHandler sendClickPackage:reattributionPackage]; @@ -510,10 +496,9 @@ - (void)writeAttribution { - (void)transferSessionPackage { - AIPackageBuilder *sessionBuilder = [[AIPackageBuilder alloc] init]; - sessionBuilder.adjustConfig = self.adjustConfig; - sessionBuilder.deviceInfo = self.deviceInfo; - sessionBuilder.activityState = self.activityState; + AIPackageBuilder *sessionBuilder = [[AIPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + andActivityState:self.activityState + andConfig:self.adjustConfig]; AIActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage]; [self.packageHandler addPackage:sessionPackage]; [self.packageHandler sendFirstPackage]; diff --git a/Adjust/AIPackageBuilder.h b/Adjust/AIPackageBuilder.h index 88927128c..e20710685 100644 --- a/Adjust/AIPackageBuilder.h +++ b/Adjust/AIPackageBuilder.h @@ -10,6 +10,7 @@ #import "AIDeviceInfo.h" #import "AIActivityState.h" #import "AIActivityPackage.h" +#import "AdjustConfig.h" @interface AIPackageBuilder : NSObject @@ -17,11 +18,14 @@ @property (nonatomic, copy) AIEvent* event; @property (nonatomic, copy) AIActivityState *activityState; @property (nonatomic, copy) AdjustConfig *adjustConfig; +@property (nonatomic, assign) BOOL hasDelegate; // reattributions @property (nonatomic, copy) NSDictionary* deeplinkParameters; -//- (id) initWithDeviceInfo:(AIDeviceInfo *)deviceInfo; +- (id) initWithDeviceInfo:(AIDeviceInfo *)deviceInfo + andActivityState:(AIActivityState *)activityState + andConfig:(AdjustConfig *)adjustConfig; - (AIActivityPackage *)buildSessionPackage; - (AIActivityPackage *)buildEventPackage; diff --git a/Adjust/AIPackageBuilder.m b/Adjust/AIPackageBuilder.m index 36ca813d9..0df45f1aa 100644 --- a/Adjust/AIPackageBuilder.m +++ b/Adjust/AIPackageBuilder.m @@ -13,6 +13,26 @@ #pragma mark - @implementation AIPackageBuilder +- (id)initWithDeviceInfo:(AIDeviceInfo *)deviceInfo + andActivityState:(AIActivityState *)activityState + andConfig:(AdjustConfig *)adjustConfig +{ + self = [super init]; + if (self == nil) return nil; + + self.deviceInfo = deviceInfo; + self.activityState = activityState; + self.adjustConfig = adjustConfig; + + if (adjustConfig.delegate) { + self.hasDelegate = YES; + } else { + self.hasDelegate = NO; + } + + return self; +} + - (AIActivityPackage *)buildSessionPackage { NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"callback_params"]; @@ -20,7 +40,7 @@ - (AIActivityPackage *)buildSessionPackage { [self parameters:parameters setDictionaryJson:self.adjustConfig.partnerPermanentParameters forKey:@"partner_params"]; AIActivityPackage *sessionPackage = [self defaultActivityPackage]; - sessionPackage.path = @"/startup"; + sessionPackage.path = @"/session"; sessionPackage.activityKind = AIActivityKindSession; sessionPackage.suffix = @""; sessionPackage.parameters = parameters; @@ -77,6 +97,7 @@ - (NSMutableDictionary *)defaultParameters { [self constructDeviceInfo:self.deviceInfo withParameter:parameters andConfig:self.adjustConfig]; [self constructActivityState:self.activityState withParamters:parameters]; + [self parameters:parameters setBool:self.hasDelegate forKey:@"has_delegate"]; return parameters; } diff --git a/Adjust/AIRequestHandler.m b/Adjust/AIRequestHandler.m index be6b81b9d..03722cd12 100644 --- a/Adjust/AIRequestHandler.m +++ b/Adjust/AIRequestHandler.m @@ -82,15 +82,9 @@ - (void)sendInternal:(AIActivityPackage *)package sendToPackageHandler:(BOOL)sen NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; [self.logger verbose:@"package response: %@", responseString]; + [self.logger verbose:@"status code: %d", response.statusCode]; NSDictionary *jsonDict = [AIUtil buildJsonDict:responseString]; - if (response.statusCode == 200) { - [self.logger info:@"%@", package.successMessage]; - } else { - // wrong status code - NSString * errorServerMessage = [jsonDict objectForKey:@"error"]; - [self.logger error:@"%@. (%@)", package.failureMessage, errorServerMessage]; - } [self.packageHandler finishedTrackingActivity:jsonDict]; if (sendToPackageHandler) { @@ -132,4 +126,22 @@ - (NSData *)bodyForParameters:(NSDictionary *)parameters { return body; } +- (void) checkMessageResponse:(NSDictionary *)jsonDict { + if (jsonDict == nil) return; + + NSString* messageResponse = [jsonDict objectForKey:@"message"]; + if (messageResponse != nil) { + [self.logger info:messageResponse]; + } +} + +- (void)checkErrorResponse:(NSDictionary *)jsonDict { + if (jsonDict == nil) return; + + NSString* errorResponse = [jsonDict objectForKey:@"error"]; + if (errorResponse != nil) { + [self.logger error:errorResponse]; + } +} + @end diff --git a/Adjust/AIUtil.m b/Adjust/AIUtil.m index 22814118f..803144f7d 100644 --- a/Adjust/AIUtil.m +++ b/Adjust/AIUtil.m @@ -17,7 +17,7 @@ static NSString * const kBaseUrl = @"https://app.adjust.io"; static NSString * const kClientSdk = @"ios4.0.0"; -static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'Z"; +static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss:SSS'Z'Z"; static NSDateFormatter * dateFormat; diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index 178d4c843..5f3a8a610 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -97,8 +97,6 @@ static NSString * const AIEnvironmentProduction = @"production"; + (void)setOfflineMode:(BOOL)enabled; -+ (void)setDelegate:(NSObject *)delegate; - + (void)addPermanentCallbackParameter:(NSString *)key andValue:(NSString *)value; @@ -117,7 +115,6 @@ static NSString * const AIEnvironmentProduction = @"production"; - (void)appWillOpenUrl:(NSURL *)url; - (void)setDeviceToken:(NSData *)deviceToken; - (void)setOfflineMode:(BOOL)enabled; -- (void)setDelegate:(NSObject *)delegate; - (void)addPermanentCallbackParameter:(NSString *)key andValue:(NSString *)value; diff --git a/Adjust/AdjustConfig.h b/Adjust/AdjustConfig.h index d2c498d08..bb0f09d73 100644 --- a/Adjust/AdjustConfig.h +++ b/Adjust/AdjustConfig.h @@ -37,7 +37,6 @@ @property (nonatomic, copy) NSMutableDictionary* callbackPermanentParameters; @property (nonatomic, copy) NSMutableDictionary* partnerPermanentParameters; @property (nonatomic, retain) NSObject *delegate; -@property (nonatomic, assign) double attributionMaxTime; - (id)initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; From a46ffb75fa315afa16c57da030036abef5c2a238 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 11 Nov 2014 11:41:44 +0100 Subject: [PATCH 12/86] Attribution max time --- Adjust/AIActivityHandler.h | 3 +- Adjust/AIActivityHandler.m | 10 +++++-- Adjust/AIAttributionHandler.m | 56 +++++++++++++++++++---------------- Adjust/Adjust.m | 10 ------- Adjust/AdjustConfig.h | 3 ++ Adjust/AdjustConfig.m | 6 +++- 6 files changed, 49 insertions(+), 39 deletions(-) diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index 93f25faf7..9d72fbece 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -27,7 +27,8 @@ - (AIAttribution*) attribution; - (void) setAttribution:(AIAttribution*)attribution; -- (void) changedAttributionDelegate:(AIAttribution*) attribution; +- (void) tryUpdateAttribution:(AIAttribution*) attribution; +- (void) launchAttributionDelegate; - (void) setOfflineMode:(BOOL)enabled; diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index fab56a71c..9aef1019a 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -170,17 +170,23 @@ - (void)setAttributionMaxTime:(double)seconds { [self.attributionHandler setAttributionMaxTime:seconds]; } -- (void)changedAttributionDelegate:(AIAttribution *)attribution { +- (void)tryUpdateAttribution:(AIAttribution *)attribution { if (attribution == nil) { return; } + if ([attribution isEqual:self.attribution]) { + return; + } self.attribution = attribution; [self writeAttribution]; +} + +- (void)launchAttributionDelegate{ if (![self.delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { return; } [self.delegate performSelectorOnMainThread:@selector(adjustAttributionChanged:) - withObject:attribution waitUntilDone:NO]; + withObject:self.attribution waitUntilDone:NO]; } - (void)setOfflineMode:(BOOL)enabled { diff --git a/Adjust/AIAttributionHandler.m b/Adjust/AIAttributionHandler.m index 54e015be5..ac0631514 100644 --- a/Adjust/AIAttributionHandler.m +++ b/Adjust/AIAttributionHandler.m @@ -21,8 +21,8 @@ @interface AIAttributionHandler() @property (nonatomic, assign) id activityHandler; @property (nonatomic, assign) id logger; @property (nonatomic, retain) NSURL *url; -@property (nonatomic, retain) AITimer *timer; -@property (nonatomic, assign) double attributionMaxTime; +@property (nonatomic, retain) AITimer *askInTimer; +@property (nonatomic, retain) AITimer *maxDelayTimer; @end @@ -34,7 +34,8 @@ @implementation AIAttributionHandler return [[AIAttributionHandler alloc] initWithActivityHandler:activityHandler]; } -- (id)initWithActivityHandler:(id) activityHandler { +- (id)initWithActivityHandler:(id) activityHandler + withMaxDelay:(NSNumber* )milliseconds{ self = [super init]; if (self == nil) return nil; @@ -44,6 +45,12 @@ - (id)initWithActivityHandler:(id) activityHandler { self.url = [NSURL URLWithString:AIUtil.baseUrl]; //TODO change baseURL + if (milliseconds != nil) { + uint64_t timer_nano = [milliseconds intValue] * NSEC_PER_MSEC; + self.maxDelayTimer = [AITimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self.activityHandler launchAttributionDelegate]; }]; + [self.maxDelayTimer resume]; + } + return self; } @@ -63,16 +70,29 @@ - (void) getAttribution { #pragma mark - internal -(void) checkAttributionInternal:(NSDictionary *)jsonDict { if (jsonDict == nil) return; - // compare if there is difference from current attribution at activity handler to launch the delegate - [self compareAttribution:jsonDict]; - // check if response json contains instrunction to retry after some time - NSNumber * timer_seconds = [jsonDict objectForKey:@"timer"]; - if (timer_seconds == nil) return; + NSDictionary* jsonAttribution = [jsonDict objectForKey:@"attribution"]; + AIAttribution * attribution; + if (jsonAttribution != nil) { + attribution = [AIAttribution dataWithJsonDict:jsonAttribution]; + } + + NSNumber * timer_milliseconds = [jsonDict objectForKey:@"ask_in"]; + + if (attribution != nil && timer_milliseconds == nil) { + attribution.finalAttribution = YES; + } + + [self.activityHandler tryUpdateAttribution:attribution]; + + if (timer_milliseconds == nil) { + [self.activityHandler launchAttributionDelegate]; + return; + }; - uint64_t timer_nano = [timer_seconds intValue] * NSEC_PER_SEC; - self.timer = [AITimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self getAttributionInternal]; }]; - [self.timer resume]; + uint64_t timer_nano = [timer_milliseconds intValue] * NSEC_PER_MSEC; + self.askInTimer = [AITimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self getAttributionInternal]; }]; + [self.askInTimer resume]; } -(void) getAttributionInternal { @@ -102,20 +122,6 @@ -(void) getAttributionInternal { [self checkAttributionInternal:jsonDict]; } --(void)compareAttribution:(NSDictionary *)jsonDict { - NSDictionary* jsonAttribution = [jsonDict objectForKey:@"attribution"]; - if (jsonAttribution == nil) return; - - AIAttribution * attribution = [AIAttribution dataWithJsonDict:jsonAttribution]; - - if ([attribution isEqual:self.activityHandler.attribution]) { - return; - } - - [self.activityHandler changedAttributionDelegate:attribution]; -} - - #pragma mark - private - (NSMutableURLRequest *)request { diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 28f6c1fb9..e3368827a 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -69,11 +69,6 @@ + (void)setOfflineMode:(BOOL)enabled { [defaultInstance setOfflineMode:enabled]; } -+ (void)setDelegate:(NSObject *)delegate { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance setDelegate:delegate]; -} - + (void)addPermanentCallbackParameter:(NSString *)key andValue:(NSString *)value { Adjust * defaultInstance = [Adjust getInstance]; @@ -157,11 +152,6 @@ - (void)setOfflineMode:(BOOL)enabled { [self.activityHandler setOfflineMode:enabled]; } -- (void)setDelegate:(NSObject *)delegate { - if (![self checkActivityHandler]) return; - [self.activityHandler setDelegate:delegate]; -} - - (void)addPermanentCallbackParameter:(NSString *)key andValue:(NSString *)value { if (![self checkActivityHandler]) return; diff --git a/Adjust/AdjustConfig.h b/Adjust/AdjustConfig.h index bb0f09d73..de87f2cd5 100644 --- a/Adjust/AdjustConfig.h +++ b/Adjust/AdjustConfig.h @@ -37,6 +37,7 @@ @property (nonatomic, copy) NSMutableDictionary* callbackPermanentParameters; @property (nonatomic, copy) NSMutableDictionary* partnerPermanentParameters; @property (nonatomic, retain) NSObject *delegate; +@property (nonatomic, copy) NSNumber* attributionMaxTimeMilliseconds; - (id)initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; @@ -46,4 +47,6 @@ - (void)addPermanentPartnerParameter:(NSString *)key andValue:(NSString *)value; +- (void)setAttributionMaxTime:(double)milliseconds; + @end diff --git a/Adjust/AdjustConfig.m b/Adjust/AdjustConfig.m index 5f5be97bd..5efb3e140 100644 --- a/Adjust/AdjustConfig.m +++ b/Adjust/AdjustConfig.m @@ -49,6 +49,10 @@ - (void) addPermanentPartnerParameter:(NSString *)key [_partnerPermanentParameters setObject:value forKey:key]; } +- (void) setAttributionMaxTime:(int)milliseconds { + self.attributionMaxTimeMilliseconds = [NSNumber numberWithInt:milliseconds]; +} + - (BOOL) checkEnvironment:(NSString *)environment { id logger = AIAdjustFactory.logger; @@ -84,7 +88,7 @@ -(id)copyWithZone:(NSZone *)zone copy.callbackPermanentParameters = [self.callbackPermanentParameters copyWithZone:zone]; copy.partnerPermanentParameters = [self.partnerPermanentParameters copyWithZone:zone]; // adjust delegate not copied - copy.attributionMaxTime = self.attributionMaxTime; + copy.attributionMaxTimeMilliseconds = [self.attributionMaxTimeMilliseconds copyWithZone:zone]; } return copy; From 2c90bfc282f763e96871207ee79519489ad1ba8b Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 11 Nov 2014 18:19:23 +0100 Subject: [PATCH 13/86] Attribution max delay --- Adjust/AIActivityHandler.h | 2 +- Adjust/AIActivityHandler.m | 8 ++------ Adjust/AIAdjustFactory.h | 2 +- Adjust/AIAdjustFactory.m | 6 +++--- Adjust/AIAttributionHandler.h | 8 +++----- Adjust/AIAttributionHandler.m | 12 ++++-------- 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Adjust/AIActivityHandler.h b/Adjust/AIActivityHandler.h index 9d72fbece..4153ac129 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/AIActivityHandler.h @@ -27,7 +27,7 @@ - (AIAttribution*) attribution; - (void) setAttribution:(AIAttribution*)attribution; -- (void) tryUpdateAttribution:(AIAttribution*) attribution; +- (void) updateAttribution:(AIAttribution*) attribution; - (void) launchAttributionDelegate; - (void) setOfflineMode:(BOOL)enabled; diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index 9aef1019a..5e5e21892 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -166,11 +166,7 @@ - (void)setIsIad:(BOOL)isIad { } } -- (void)setAttributionMaxTime:(double)seconds { - [self.attributionHandler setAttributionMaxTime:seconds]; -} - -- (void)tryUpdateAttribution:(AIAttribution *)attribution { +- (void)updateAttribution:(AIAttribution *)attribution { if (attribution == nil) { return; } @@ -247,7 +243,7 @@ - (void)initInternal:(AdjustConfig *)adjustConfig { [[UIDevice currentDevice] aiSetIad:self]; self.packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:self]; - self.attributionHandler = [AIAdjustFactory attributionHandlerForActivityHandler:self]; + self.attributionHandler = [AIAdjustFactory attributionHandlerForActivityHandler:self withMaxDelay:adjustConfig.attributionMaxTimeMilliseconds]; [self readActivityState]; [self readAttribution]; diff --git a/Adjust/AIAdjustFactory.h b/Adjust/AIAdjustFactory.h index 6c08e8aa1..139f0d80a 100644 --- a/Adjust/AIAdjustFactory.h +++ b/Adjust/AIAdjustFactory.h @@ -21,7 +21,7 @@ + (id)logger; + (double)sessionInterval; + (double)subsessionInterval; -+ (id)attributionHandlerForActivityHandler:(id)activityHandler; ++ (id)attributionHandlerForActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds; + (void)setPackageHandler:(id)packageHandler; + (void)setRequestHandler:(id)requestHandler; diff --git a/Adjust/AIAdjustFactory.m b/Adjust/AIAdjustFactory.m index 751857ee5..576599e60 100644 --- a/Adjust/AIAdjustFactory.m +++ b/Adjust/AIAdjustFactory.m @@ -63,12 +63,12 @@ + (double)subsessionInterval { return intervalSubsessionInterval; } -+ (id)attributionHandlerForActivityHandler:(id)activityHandler { ++ (id)attributionHandlerForActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds{ if (internalAttributionHandler == nil) { - return [AIAttributionHandler handlerWithActivityHandler:activityHandler]; + return [AIAttributionHandler handlerWithActivityHandler:activityHandler withMaxDelay:milliseconds]; } - return [internalAttributionHandler initWithActivityHandler:activityHandler]; + return [internalAttributionHandler initWithActivityHandler:activityHandler withMaxDelay:milliseconds]; } + (void)setPackageHandler:(id)packageHandler { diff --git a/Adjust/AIAttributionHandler.h b/Adjust/AIAttributionHandler.h index dddd7f70c..784f53abd 100644 --- a/Adjust/AIAttributionHandler.h +++ b/Adjust/AIAttributionHandler.h @@ -11,19 +11,17 @@ @protocol AIAttributionHandler -- (id)initWithActivityHandler:(id) activityHandler; +- (id)initWithActivityHandler:(id) activityHandler withMaxDelay:(NSNumber* )milliseconds; - (void)checkAttribution:(NSDictionary *)jsonDict; - (void)getAttribution; -- (void)setAttributionMaxTime:(double)seconds; -// TODO - @end @interface AIAttributionHandler : NSObject -+ (id)handlerWithActivityHandler:(id)activityHandler; ++ (id)handlerWithActivityHandler:(id)activityHandler + withMaxDelay:(NSNumber* )milliseconds; @end diff --git a/Adjust/AIAttributionHandler.m b/Adjust/AIAttributionHandler.m index ac0631514..9dbdfef21 100644 --- a/Adjust/AIAttributionHandler.m +++ b/Adjust/AIAttributionHandler.m @@ -30,8 +30,8 @@ @interface AIAttributionHandler() @implementation AIAttributionHandler -+ (id)handlerWithActivityHandler:(id)activityHandler { - return [[AIAttributionHandler alloc] initWithActivityHandler:activityHandler]; ++ (id)handlerWithActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds{ + return [[AIAttributionHandler alloc] initWithActivityHandler:activityHandler withMaxDelay:milliseconds]; } - (id)initWithActivityHandler:(id) activityHandler @@ -64,7 +64,6 @@ - (void) getAttribution { dispatch_async(self.internalQueue, ^{ [self getAttributionInternal]; }); - } #pragma mark - internal @@ -72,10 +71,7 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { if (jsonDict == nil) return; NSDictionary* jsonAttribution = [jsonDict objectForKey:@"attribution"]; - AIAttribution * attribution; - if (jsonAttribution != nil) { - attribution = [AIAttribution dataWithJsonDict:jsonAttribution]; - } + AIAttribution * attribution = [AIAttribution dataWithJsonDict:jsonAttribution]; NSNumber * timer_milliseconds = [jsonDict objectForKey:@"ask_in"]; @@ -83,7 +79,7 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { attribution.finalAttribution = YES; } - [self.activityHandler tryUpdateAttribution:attribution]; + [self.activityHandler updateAttribution:attribution]; if (timer_milliseconds == nil) { [self.activityHandler launchAttributionDelegate]; From df072051bcae9334a2db3c94c11c30ef2894db1f Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 12 Nov 2014 16:39:36 +0100 Subject: [PATCH 14/86] Read and Write object --- Adjust/AIActivityHandler.m | 99 +++++--------------------------- Adjust/AIRequestHandler.m | 10 +++- Adjust/AIUtil.h | 7 +++ Adjust/AIUtil.m | 36 ++++++++++++ Adjust/AdjustConfig.h | 2 +- AdjustBridge/AdjustBridge.h | 5 +- AdjustBridge/AdjustBridge.js.txt | 13 +---- AdjustBridge/AdjustBridge.m | 27 ++------- 8 files changed, 77 insertions(+), 122 deletions(-) diff --git a/Adjust/AIActivityHandler.m b/Adjust/AIActivityHandler.m index 5e5e21892..14d5461cb 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/AIActivityHandler.m @@ -21,6 +21,8 @@ static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAttributionFilename = @"AdjustIoAttribution"; +static NSString * const kActivityStateName = @"activity state"; +static NSString * const kAttributionName = @"attributionlo"; static NSString * const kAdjustPrefix = @"adjust_"; static const char * const kInternalQueueName = "io.adjust.ActivityQueue"; @@ -125,7 +127,7 @@ - (void)setEnabled:(BOOL)enabled { _enabled = enabled; if ([self checkActivityState:self.activityState]) { self.activityState.enabled = enabled; - [self writeActivityState]; + [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; } if (enabled) { [self trackSubsessionStart]; @@ -174,14 +176,14 @@ - (void)updateAttribution:(AIAttribution *)attribution { return; } self.attribution = attribution; - [self writeAttribution]; + [AIUtil writeObject:self.attribution filename:kAttributionFilename objectName:kAttributionName]; } - (void)launchAttributionDelegate{ - if (![self.delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { + if (![self.delegate respondsToSelector:@selector(adjustAttributionCallback:)]) { return; } - [self.delegate performSelectorOnMainThread:@selector(adjustAttributionChanged:) + [self.delegate performSelectorOnMainThread:@selector(adjustAttributionCallback:) withObject:self.attribution waitUntilDone:NO]; } @@ -245,8 +247,8 @@ - (void)initInternal:(AdjustConfig *)adjustConfig { self.packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:self]; self.attributionHandler = [AIAdjustFactory attributionHandlerForActivityHandler:self withMaxDelay:adjustConfig.attributionMaxTimeMilliseconds]; - [self readActivityState]; - [self readAttribution]; + self.activityState = [AIUtil readObject:kActivityStateFilename objectName:kActivityStateName]; + self.attribution = [AIUtil readObject:kAttributionFilename objectName:kAttributionName]; [self startInternal]; } @@ -273,8 +275,7 @@ - (void)startInternal { [self transferSessionPackage]; [self.activityState resetSessionAttributes:now]; self.activityState.enabled = _enabled; - [self writeActivityState]; - [self.logger info:@"First session"]; + [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; return; } @@ -282,7 +283,7 @@ - (void)startInternal { if (lastInterval < 0) { [self.logger error:@"Time travel!"]; self.activityState.lastActivity = now; - [self writeActivityState]; + [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; return; } @@ -294,8 +295,7 @@ - (void)startInternal { [self transferSessionPackage]; [self.activityState resetSessionAttributes:now]; - [self writeActivityState]; - [self.logger debug:@"Session %d", self.activityState.sessionCount]; + [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; return; } @@ -304,7 +304,7 @@ - (void)startInternal { self.activityState.subsessionCount++; self.activityState.sessionLength += lastInterval; self.activityState.lastActivity = now; - [self writeActivityState]; + [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; [self.logger info:@"Processed Subsession %d of Session %d", self.activityState.subsessionCount, self.activityState.sessionCount]; @@ -318,7 +318,7 @@ - (void)endInternal { [self stopTimer]; double now = [NSDate.date timeIntervalSince1970]; [self updateActivityState:now]; - [self writeActivityState]; + [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; } - (void)eventInternal:(AIEvent *)event @@ -356,8 +356,7 @@ - (void)eventInternal:(AIEvent *)event [self.packageHandler sendFirstPackage]; } - [self writeActivityState]; - [self.logger debug:@"Event %d", self.activityState.eventCount]; + [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; } - (void) appWillOpenUrlInternal:(NSURL *)url { @@ -393,8 +392,6 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { AIActivityPackage *reattributionPackage = [ClickBuilder buildClickPackage]; [self.packageHandler sendClickPackage:reattributionPackage]; - - [self.logger debug:@"ClickPackage %@", adjustDeepLinks]; } - (void) setDeviceTokenInternal:(NSData *)deviceToken { @@ -431,72 +428,6 @@ - (BOOL)updateActivityState:(double)now { return (lastInterval > AIAdjustFactory.subsessionInterval); } -- (void)readActivityState { - @try { - NSString *filename = [AIUtil getFullFilename:kActivityStateFilename]; - id object = [NSKeyedUnarchiver unarchiveObjectWithFile:filename]; - if ([object isKindOfClass:[AIActivityState class]]) { - self.activityState = object; - [self.logger debug:@"Read activity state: %@ uuid:%@", self.activityState, self.activityState.uuid]; - return; - } else if (object == nil) { - [self.logger verbose:@"Activity state file not found"]; - } else { - [self.logger error:@"Failed to read activity state"]; - } - } @catch (NSException *ex ) { - [self.logger error:@"Failed to read activity state (%@)", ex]; - } - - // start with a fresh activity state in case of any exception - self.activityState = nil; -} - -- (void)writeActivityState { - NSString *filename = [AIUtil getFullFilename:kActivityStateFilename]; - BOOL result = [NSKeyedArchiver archiveRootObject:self.activityState toFile:filename]; - if (result == YES) { - [AIUtil excludeFromBackup:filename]; - [self.logger debug:@"Wrote activity state: %@", self.activityState]; - } else { - [self.logger error:@"Failed to write activity state"]; - } -} - - -- (void)readAttribution { - @try { - NSString *filename = [AIUtil getFullFilename:kAttributionFilename]; - id object = [NSKeyedUnarchiver unarchiveObjectWithFile:filename]; - if ([object isKindOfClass:[AIAttribution class]]) { - self.activityState = object; - [self.logger debug:@"Read attribution: %@", self.attribution]; - return; - } else if (object == nil) { - [self.logger verbose:@"Attribution file not found"]; - } else { - [self.logger error:@"Failed to read attribution file"]; - } - } @catch (NSException *ex ) { - [self.logger error:@"Failed to read attribution file (%@)", ex]; - } - - // start with a fresh activity state in case of any exception - self.attribution = nil; -} - -- (void)writeAttribution { - NSString *filename = [AIUtil getFullFilename:kAttributionFilename]; - BOOL result = [NSKeyedArchiver archiveRootObject:self.attribution toFile:filename]; - if (result == YES) { - [AIUtil excludeFromBackup:filename]; - [self.logger debug:@"Wrote attribution: %@", self.attribution]; - } else { - [self.logger error:@"Failed to write attribution file"]; - } -} - - - (void)transferSessionPackage { AIPackageBuilder *sessionBuilder = [[AIPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState @@ -529,7 +460,7 @@ - (void)timerFired { [self.packageHandler sendFirstPackage]; double now = [NSDate.date timeIntervalSince1970]; if ([self updateActivityState:now]) { - [self writeActivityState]; + [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; } } diff --git a/Adjust/AIRequestHandler.m b/Adjust/AIRequestHandler.m index 03722cd12..3850e491c 100644 --- a/Adjust/AIRequestHandler.m +++ b/Adjust/AIRequestHandler.m @@ -82,9 +82,17 @@ - (void)sendInternal:(AIActivityPackage *)package sendToPackageHandler:(BOOL)sen NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; [self.logger verbose:@"package response: %@", responseString]; - [self.logger verbose:@"status code: %d", response.statusCode]; NSDictionary *jsonDict = [AIUtil buildJsonDict:responseString]; + NSString* messageResponse = [jsonDict objectForKey:@"message"]; + + NSInteger statusCode = response.statusCode; + if (statusCode == 200) { + [self.logger info:@"status code %d with message %@", statusCode, messageResponse]; + } else { + [self.logger error:@"status code %d with message %@", statusCode, messageResponse]; + } + [self.packageHandler finishedTrackingActivity:jsonDict]; if (sendToPackageHandler) { diff --git a/Adjust/AIUtil.h b/Adjust/AIUtil.h index 984554313..cfd0a65b4 100644 --- a/Adjust/AIUtil.h +++ b/Adjust/AIUtil.h @@ -20,4 +20,11 @@ + (NSString *)getFullFilename:(NSString *) baseFilename; ++ (id)readObject:(NSString *)filename + objectName:(NSString *)objectName; + ++ (void)writeObject:(id)object + filename:(NSString *)filename + objectName:(NSString *)objectName; + @end diff --git a/Adjust/AIUtil.m b/Adjust/AIUtil.m index 803144f7d..18a644e97 100644 --- a/Adjust/AIUtil.m +++ b/Adjust/AIUtil.m @@ -141,5 +141,41 @@ + (NSString *)getFullFilename:(NSString *) baseFilename { return filename; } ++ (id)readObject:(NSString *)filename + objectName:(NSString *)objectName{ + id logger = [AIAdjustFactory logger]; + @try { + NSString *fullFilename = [AIUtil getFullFilename:filename]; + id object = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFilename]; + if ([object isKindOfClass:[AIAttribution class]]) { + [logger debug:@"Read %@: %@", objectName, object]; + return object; + } else if (object == nil) { + [logger verbose:@"%@ not found", objectName]; + } else { + [logger error:@"Failed to read %@ file", objectName]; + } + } @catch (NSException *ex ) { + [logger error:@"Failed to read %@ file (%@)", objectName, ex]; + } + + return nil; +} + ++ (void)writeObject:(id)object + filename:(NSString *)filename + objectName:(NSString *)objectName { + id logger = [AIAdjustFactory logger]; + NSString *fullFilename = [AIUtil getFullFilename:filename]; + BOOL result = [NSKeyedArchiver archiveRootObject:object toFile:fullFilename]; + if (result == YES) { + [AIUtil excludeFromBackup:fullFilename]; + [logger debug:@"Wrote %@: %@", objectName, object]; + } else { + [logger error:@"Failed to write %@ file", objectName]; + } + +} + @end diff --git a/Adjust/AdjustConfig.h b/Adjust/AdjustConfig.h index de87f2cd5..ad1a28310 100644 --- a/Adjust/AdjustConfig.h +++ b/Adjust/AdjustConfig.h @@ -22,7 +22,7 @@ * @param responseData The response data containing information about the activity * and it's server response. See AIResponseData for details. */ -- (void)adjustAttributionChanged:(AIAttribution *)attribution; +- (void)adjustAttributionCallback:(AIAttribution *)attribution; @end diff --git a/AdjustBridge/AdjustBridge.h b/AdjustBridge/AdjustBridge.h index 702eafa90..442bd66e3 100644 --- a/AdjustBridge/AdjustBridge.h +++ b/AdjustBridge/AdjustBridge.h @@ -7,12 +7,9 @@ // #import -#import "Adjust.h" #import -@interface AdjustBridge : NSObject - -- (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData; +@interface AdjustBridge : NSObject + (void)loadBridge:(NSObject *) webViewDelegate webView:(UIWebView *) webView; diff --git a/AdjustBridge/AdjustBridge.js.txt b/AdjustBridge/AdjustBridge.js.txt index c7bb877f1..8a3f2c6dc 100644 --- a/AdjustBridge/AdjustBridge.js.txt +++ b/AdjustBridge/AdjustBridge.js.txt @@ -9,19 +9,11 @@ window.AdjustBridge = (function () { bridge.init(function(message, callback) { }); } - function trackEventPrivate (eventToken, parameters) { + function trackEventPrivate (event) { bridge.callHandler(adjustPrefix + 'trackEvent', - {'eventToken': eventToken, 'parameters': parameters, 'revenue': revenue}, + {'event': event}, function(response) {}) }; - - function setResponseDelegatePrivate(responseDelegate) { - bridge.callHandler(adjustPrefix + 'setResponseDelegate', {}, function(response) {}); - - bridge.registerHandler('responseDelegate', function(data, responseCallback) { - responseDelegate(data) - }); - }; function setEnabledPrivate(enabled) { bridge.callHandler(adjustPrefix + 'setEnabled', {'enabled': enabled}, function(response) { }); @@ -40,7 +32,6 @@ window.AdjustBridge = (function () { return { setBridge: setBridgePrivate, trackEvent: trackEventPrivate, - setResponseDelegate: setResponseDelegatePrivate, setEnabled: setEnabledPrivate, isEnabled: isEnabledPrivate, openUrl: openUrlPrivate diff --git a/AdjustBridge/AdjustBridge.m b/AdjustBridge/AdjustBridge.m index 0c0905900..32f1a3fee 100644 --- a/AdjustBridge/AdjustBridge.m +++ b/AdjustBridge/AdjustBridge.m @@ -8,6 +8,8 @@ #import "AdjustBridge.h" #import "WebViewJavascriptBridge.h" +#import "AIEvent.h" +#import "Adjust.h" static NSString * const kAdjustJsPrefix = @"adjust_"; @@ -30,6 +32,9 @@ + (void) loadBridge:(NSObject *) webViewDelegate [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@trackEvent", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { + // TODO, test + AIEvent * event= [data objectForKey:@"event"]; + /* NSString* eventToken = [data objectForKey:@"eventToken"]; NSDictionary* parameters = [data objectForKey:@"parameters"]; NSNumber* revenue = [data objectForKey:@"revenue"]; @@ -47,16 +52,10 @@ + (void) loadBridge:(NSObject *) webViewDelegate if (revenue != nil) { [event setRevenue:[revenue doubleValue] currency:currency]; } - + */ [Adjust trackEvent:event]; }]; - [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@setResponseDelegate", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { - - adjustBridgeInstance = [[AdjustBridge alloc] init]; - [Adjust setDelegate:adjustBridgeInstance]; - }]; - [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@setEnabled", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { BOOL enabled = [[data objectForKey:@"enabled"] boolValue]; @@ -82,19 +81,5 @@ + (void) loadBridge:(NSObject *) webViewDelegate NSString *js = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; [webView stringByEvaluatingJavaScriptFromString:js]; } - - [Adjust setSdkPrefix:@"bridge"]; -} - -- (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData { - NSMutableDictionary* dicResponseData = (NSMutableDictionary*) [responseData dictionary]; - - [dicResponseData removeObjectForKey:@"success"]; - [dicResponseData setObject:[NSNumber numberWithBool:responseData.success] forKey:@"success"]; - - [dicResponseData removeObjectForKey:@"willRetry"]; - [dicResponseData setObject:[NSNumber numberWithBool:responseData.willRetry] forKey:@"willRetry"]; - - [_AdjustBridge callHandler:@"responseDelegate" data:dicResponseData responseCallback:^(id response) {}]; } @end From 1aa4ede9d1e8de2f59f7187debf1c84d1a0112c1 Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 12 Nov 2014 17:30:45 +0100 Subject: [PATCH 15/86] Renamed AI to ADJ --- Adjust.xcodeproj/project.pbxproj | 248 +++++++++--------- ...ActivityHandler.h => ADJActivityHandler.h} | 20 +- ...ActivityHandler.m => ADJActivityHandler.m} | 132 +++++----- Adjust/ADJActivityKind.h | 20 ++ Adjust/ADJActivityKind.m | 33 +++ ...ActivityPackage.h => ADJActivityPackage.h} | 8 +- ...ActivityPackage.m => ADJActivityPackage.m} | 18 +- .../{AIActivityState.h => ADJActivityState.h} | 6 +- .../{AIActivityState.m => ADJActivityState.m} | 23 +- .../NSString+ADJAdditions.h} | 4 +- .../NSString+ADJAdditions.m} | 6 +- .../UIDevice+ADJAdditions.h} | 8 +- .../UIDevice+ADJAdditions.m} | 10 +- Adjust/ADJAdjustFactory.h | 34 +++ .../{AIAdjustFactory.m => ADJAdjustFactory.m} | 46 ++-- Adjust/{AIAttribution.h => ADJAttribution.h} | 8 +- Adjust/{AIAttribution.m => ADJAttribution.m} | 16 +- Adjust/ADJAttributionHandler.h | 27 ++ ...utionHandler.m => ADJAttributionHandler.m} | 44 ++-- Adjust/{AdjustConfig.h => ADJConfig.h} | 14 +- Adjust/{AdjustConfig.m => ADJConfig.m} | 16 +- Adjust/{AIDeviceInfo.h => ADJDeviceInfo.h} | 10 +- Adjust/{AIDeviceInfo.m => ADJDeviceInfo.m} | 8 +- Adjust/{AIEvent.h => ADJEvent.h} | 4 +- Adjust/{AIEvent.m => ADJEvent.m} | 8 +- Adjust/{AILogger.h => ADJLogger.h} | 24 +- Adjust/{AILogger.m => ADJLogger.m} | 40 +-- Adjust/ADJPackageBuilder.h | 34 +++ ...AIPackageBuilder.m => ADJPackageBuilder.m} | 48 ++-- Adjust/ADJPackageHandler.h | 33 +++ ...AIPackageHandler.m => ADJPackageHandler.m} | 46 ++-- Adjust/ADJRequestHandler.h | 27 ++ ...AIRequestHandler.m => ADJRequestHandler.m} | 42 +-- Adjust/{AITimer.h => ADJTimer.h} | 8 +- Adjust/{AITimer.m => ADJTimer.m} | 16 +- Adjust/{AIUserAgent.h => ADJUserAgent.h} | 4 +- Adjust/{AIUserAgent.m => ADJUserAgent.m} | 8 +- Adjust/{AIUtil.h => ADJUtil.h} | 8 +- Adjust/{AIUtil.m => ADJUtil.m} | 32 +-- Adjust/AIActivityKind.h | 20 -- Adjust/AIActivityKind.m | 33 --- Adjust/AIAdjustFactory.h | 34 --- Adjust/AIAttributionHandler.h | 27 -- Adjust/AIPackageBuilder.h | 34 --- Adjust/AIPackageHandler.h | 33 --- Adjust/AIRequestHandler.h | 27 -- Adjust/Adjust.h | 16 +- Adjust/Adjust.m | 22 +- AdjustBridge/AdjustBridge.m | 4 +- AdjustTests/AIActivityHandlerMock.h | 4 +- AdjustTests/AIActivityHandlerMock.m | 4 +- AdjustTests/AIActivityHandlerTests.m | 180 ++++++------- AdjustTests/AILoggerMock.h | 6 +- AdjustTests/AILoggerMock.m | 16 +- AdjustTests/AIPackageHandlerMock.h | 6 +- AdjustTests/AIPackageHandlerMock.m | 14 +- AdjustTests/AIPackageHandlerTests.m | 50 ++-- AdjustTests/AIRequestHandlerMock.h | 4 +- AdjustTests/AIRequestHandlerMock.m | 10 +- AdjustTests/AIRequestHandlerTests.m | 34 +-- AdjustTests/AITestsUtil.h | 4 +- AdjustTests/AITestsUtil.m | 12 +- ...NSURLConnectionSynchronousLoadingMocking.m | 4 +- 63 files changed, 858 insertions(+), 881 deletions(-) rename Adjust/{AIActivityHandler.h => ADJActivityHandler.h} (61%) rename Adjust/{AIActivityHandler.m => ADJActivityHandler.m} (77%) create mode 100644 Adjust/ADJActivityKind.h create mode 100644 Adjust/ADJActivityKind.m rename Adjust/{AIActivityPackage.h => ADJActivityPackage.h} (72%) rename Adjust/{AIActivityPackage.m => ADJActivityPackage.m} (81%) rename Adjust/{AIActivityState.h => ADJActivityState.h} (91%) rename Adjust/{AIActivityState.m => ADJActivityState.m} (89%) rename Adjust/{AIAdditions/NSString+AIAdditions.h => ADJAdditions/NSString+ADJAdditions.h} (85%) rename Adjust/{AIAdditions/NSString+AIAdditions.m => ADJAdditions/NSString+ADJAdditions.m} (95%) rename Adjust/{AIAdditions/UIDevice+AIAdditions.h => ADJAdditions/UIDevice+ADJAdditions.h} (74%) rename Adjust/{AIAdditions/UIDevice+AIAdditions.m => ADJAdditions/UIDevice+ADJAdditions.m} (96%) create mode 100644 Adjust/ADJAdjustFactory.h rename Adjust/{AIAdjustFactory.m => ADJAdjustFactory.m} (51%) rename Adjust/{AIAttribution.h => ADJAttribution.h} (81%) rename Adjust/{AIAttribution.m => ADJAttribution.m} (91%) create mode 100644 Adjust/ADJAttributionHandler.h rename Adjust/{AIAttributionHandler.m => ADJAttributionHandler.m} (67%) rename Adjust/{AdjustConfig.h => ADJConfig.h} (83%) rename Adjust/{AdjustConfig.m => ADJConfig.m} (89%) rename Adjust/{AIDeviceInfo.h => ADJDeviceInfo.h} (75%) rename Adjust/{AIDeviceInfo.m => ADJDeviceInfo.m} (84%) rename Adjust/{AIEvent.h => ADJEvent.h} (93%) rename Adjust/{AIEvent.m => ADJEvent.m} (92%) rename Adjust/{AILogger.h => ADJLogger.h} (57%) rename Adjust/{AILogger.m => ADJLogger.m} (71%) create mode 100644 Adjust/ADJPackageBuilder.h rename Adjust/{AIPackageBuilder.m => ADJPackageBuilder.m} (86%) create mode 100644 Adjust/ADJPackageHandler.h rename Adjust/{AIPackageHandler.m => ADJPackageHandler.m} (77%) create mode 100644 Adjust/ADJRequestHandler.h rename Adjust/{AIRequestHandler.m => ADJRequestHandler.m} (78%) rename Adjust/{AITimer.h => ADJTimer.h} (85%) rename Adjust/{AITimer.m => ADJTimer.m} (79%) rename Adjust/{AIUserAgent.h => ADJUserAgent.h} (89%) rename Adjust/{AIUserAgent.m => ADJUserAgent.m} (83%) rename Adjust/{AIUtil.h => ADJUtil.h} (86%) rename Adjust/{AIUtil.m => ADJUtil.m} (88%) delete mode 100644 Adjust/AIActivityKind.h delete mode 100644 Adjust/AIActivityKind.m delete mode 100644 Adjust/AIAdjustFactory.h delete mode 100644 Adjust/AIAttributionHandler.h delete mode 100644 Adjust/AIPackageBuilder.h delete mode 100644 Adjust/AIPackageHandler.h delete mode 100644 Adjust/AIRequestHandler.h diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index 061355746..47846bd1e 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -7,37 +7,37 @@ objects = { /* Begin PBXBuildFile section */ - 9609BC6A19EEA55800E02303 /* AIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 9609BC6919EEA55800E02303 /* AIEvent.m */; }; - 960A8BB91A029A8000F2BB95 /* AdjustConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 960A8BB81A029A8000F2BB95 /* AdjustConfig.m */; }; + 9609BC6A19EEA55800E02303 /* ADJEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 9609BC6919EEA55800E02303 /* ADJEvent.m */; }; + 960A8BB91A029A8000F2BB95 /* ADJConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 960A8BB81A029A8000F2BB95 /* ADJConfig.m */; }; 96325E89190E892000A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8A190E892600A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8B190E8D6200A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8C190E8D6B00A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; - 965307F61A000DA400107FF9 /* AIDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 965307F51A000DA400107FF9 /* AIDeviceInfo.m */; }; - 965307F81A000DCC00107FF9 /* AIUserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 965307F71A000DCC00107FF9 /* AIUserAgent.m */; }; + 965307F61A000DA400107FF9 /* ADJDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 965307F51A000DA400107FF9 /* ADJDeviceInfo.m */; }; + 965307F81A000DCC00107FF9 /* ADJUserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 965307F71A000DCC00107FF9 /* ADJUserAgent.m */; }; 9679921118BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; }; 9679921F18BBAE2800394606 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921E18BBAE2800394606 /* XCTest.framework */; }; 9679922018BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; }; 9679922218BBAE2800394606 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679922118BBAE2800394606 /* UIKit.framework */; }; 9679922518BBAE2800394606 /* libAdjust.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679920D18BBAE2800394606 /* libAdjust.a */; }; - 969952CF1A012F5300928462 /* AIAttributionHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 969952CE1A012F5300928462 /* AIAttributionHandler.m */; }; - 969952D21A01309200928462 /* AIAttribution.m in Sources */ = {isa = PBXBuildFile; fileRef = 969952D11A01309200928462 /* AIAttribution.m */; }; + 969952CF1A012F5300928462 /* ADJAttributionHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 969952CE1A012F5300928462 /* ADJAttributionHandler.m */; }; + 969952D21A01309200928462 /* ADJAttribution.m in Sources */ = {isa = PBXBuildFile; fileRef = 969952D11A01309200928462 /* ADJAttribution.m */; }; + 96CD2BE01A13BFC600A40AFB /* NSString+ADJAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD2BDD1A13BFC600A40AFB /* NSString+ADJAdditions.m */; }; + 96CD2BE11A13BFC600A40AFB /* UIDevice+ADJAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD2BDF1A13BFC600A40AFB /* UIDevice+ADJAdditions.m */; }; 96CD4478192A546F0029A1AA /* AdjustBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD4473192A546F0029A1AA /* AdjustBridge.m */; }; 96CD4479192A546F0029A1AA /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD4477192A546F0029A1AA /* WebViewJavascriptBridge.m */; }; 96E5E38118BBB48A008E7B30 /* Adjust.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E34D18BBB48A008E7B30 /* Adjust.m */; }; - 96E5E38B18BBB48A008E7B30 /* AIActivityHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36318BBB48A008E7B30 /* AIActivityHandler.m */; }; - 96E5E38C18BBB48A008E7B30 /* AIActivityKind.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36518BBB48A008E7B30 /* AIActivityKind.m */; }; - 96E5E38D18BBB48A008E7B30 /* AIActivityPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36718BBB48A008E7B30 /* AIActivityPackage.m */; }; - 96E5E38E18BBB48A008E7B30 /* AIActivityState.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36918BBB48A008E7B30 /* AIActivityState.m */; }; - 96E5E39018BBB48A008E7B30 /* NSString+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36E18BBB48A008E7B30 /* NSString+AIAdditions.m */; }; - 96E5E39118BBB48A008E7B30 /* UIDevice+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37018BBB48A008E7B30 /* UIDevice+AIAdditions.m */; }; - 96E5E39218BBB48A008E7B30 /* AIAdjustFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37218BBB48A008E7B30 /* AIAdjustFactory.m */; }; - 96E5E39318BBB48A008E7B30 /* AILogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37418BBB48A008E7B30 /* AILogger.m */; }; - 96E5E39418BBB48A008E7B30 /* AIPackageBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37618BBB48A008E7B30 /* AIPackageBuilder.m */; }; - 96E5E39518BBB48A008E7B30 /* AIPackageHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37818BBB48A008E7B30 /* AIPackageHandler.m */; }; - 96E5E39618BBB48A008E7B30 /* AIRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37A18BBB48A008E7B30 /* AIRequestHandler.m */; }; - 96E5E39818BBB48A008E7B30 /* AITimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37E18BBB48A008E7B30 /* AITimer.m */; }; - 96E5E39918BBB48A008E7B30 /* AIUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E38018BBB48A008E7B30 /* AIUtil.m */; }; + 96E5E38B18BBB48A008E7B30 /* ADJActivityHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36318BBB48A008E7B30 /* ADJActivityHandler.m */; }; + 96E5E38C18BBB48A008E7B30 /* ADJActivityKind.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36518BBB48A008E7B30 /* ADJActivityKind.m */; }; + 96E5E38D18BBB48A008E7B30 /* ADJActivityPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36718BBB48A008E7B30 /* ADJActivityPackage.m */; }; + 96E5E38E18BBB48A008E7B30 /* ADJActivityState.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36918BBB48A008E7B30 /* ADJActivityState.m */; }; + 96E5E39218BBB48A008E7B30 /* ADJAdjustFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37218BBB48A008E7B30 /* ADJAdjustFactory.m */; }; + 96E5E39318BBB48A008E7B30 /* ADJLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37418BBB48A008E7B30 /* ADJLogger.m */; }; + 96E5E39418BBB48A008E7B30 /* ADJPackageBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37618BBB48A008E7B30 /* ADJPackageBuilder.m */; }; + 96E5E39518BBB48A008E7B30 /* ADJPackageHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37818BBB48A008E7B30 /* ADJPackageHandler.m */; }; + 96E5E39618BBB48A008E7B30 /* ADJRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37A18BBB48A008E7B30 /* ADJRequestHandler.m */; }; + 96E5E39818BBB48A008E7B30 /* ADJTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37E18BBB48A008E7B30 /* ADJTimer.m */; }; + 96E5E39918BBB48A008E7B30 /* ADJUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E38018BBB48A008E7B30 /* ADJUtil.m */; }; 96E5E3AF18BBB49E008E7B30 /* AIActivityHandlerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E39E18BBB49E008E7B30 /* AIActivityHandlerMock.m */; }; 96E5E3B018BBB49E008E7B30 /* AIActivityHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E39F18BBB49E008E7B30 /* AIActivityHandlerTests.m */; }; 96E5E3B118BBB49E008E7B30 /* AILoggerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A118BBB49E008E7B30 /* AILoggerMock.m */; }; @@ -49,8 +49,6 @@ 96E5E3B718BBB49E008E7B30 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E5E3AA18BBB49E008E7B30 /* InfoPlist.strings */; }; 96E5E3B818BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3AD18BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m */; }; 96E5E3B918BBB75F008E7B30 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921E18BBAE2800394606 /* XCTest.framework */; }; - 96E5E3BB18BBB989008E7B30 /* NSString+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36E18BBB48A008E7B30 /* NSString+AIAdditions.m */; }; - 96E5E3BD18BBB992008E7B30 /* UIDevice+AIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37018BBB48A008E7B30 /* UIDevice+AIAdditions.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -76,26 +74,30 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 9609BC6819EEA55800E02303 /* AIEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIEvent.h; sourceTree = ""; }; - 9609BC6919EEA55800E02303 /* AIEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIEvent.m; sourceTree = ""; }; - 960A8BB71A029A8000F2BB95 /* AdjustConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdjustConfig.h; sourceTree = ""; }; - 960A8BB81A029A8000F2BB95 /* AdjustConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdjustConfig.m; sourceTree = ""; }; + 9609BC6819EEA55800E02303 /* ADJEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJEvent.h; sourceTree = ""; }; + 9609BC6919EEA55800E02303 /* ADJEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJEvent.m; sourceTree = ""; }; + 960A8BB71A029A8000F2BB95 /* ADJConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJConfig.h; sourceTree = ""; }; + 960A8BB81A029A8000F2BB95 /* ADJConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJConfig.m; sourceTree = ""; }; 96325E84190E5CD900A97911 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 96325E86190E5CE400A97911 /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iAd.framework; path = System/Library/Frameworks/iAd.framework; sourceTree = SDKROOT; }; - 9644B7EA19F148F3008576FC /* AIDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIDeviceInfo.h; sourceTree = ""; }; - 9653078119FFD56900107FF9 /* AIUserAgent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AIUserAgent.h; sourceTree = ""; }; - 965307F51A000DA400107FF9 /* AIDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIDeviceInfo.m; sourceTree = ""; }; - 965307F71A000DCC00107FF9 /* AIUserAgent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIUserAgent.m; sourceTree = ""; }; + 9644B7EA19F148F3008576FC /* ADJDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJDeviceInfo.h; sourceTree = ""; }; + 9653078119FFD56900107FF9 /* ADJUserAgent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADJUserAgent.h; sourceTree = ""; }; + 965307F51A000DA400107FF9 /* ADJDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJDeviceInfo.m; sourceTree = ""; }; + 965307F71A000DCC00107FF9 /* ADJUserAgent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserAgent.m; sourceTree = ""; }; 9679920D18BBAE2800394606 /* libAdjust.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAdjust.a; sourceTree = BUILT_PRODUCTS_DIR; }; 9679921018BBAE2800394606 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 9679921D18BBAE2800394606 /* AdjustTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AdjustTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 9679921E18BBAE2800394606 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 9679922118BBAE2800394606 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; - 969952CD1A012F5300928462 /* AIAttributionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIAttributionHandler.h; sourceTree = ""; }; - 969952CE1A012F5300928462 /* AIAttributionHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIAttributionHandler.m; sourceTree = ""; }; - 969952D01A01309200928462 /* AIAttribution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIAttribution.h; sourceTree = ""; }; - 969952D11A01309200928462 /* AIAttribution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIAttribution.m; sourceTree = ""; }; + 969952CD1A012F5300928462 /* ADJAttributionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJAttributionHandler.h; sourceTree = ""; }; + 969952CE1A012F5300928462 /* ADJAttributionHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAttributionHandler.m; sourceTree = ""; }; + 969952D01A01309200928462 /* ADJAttribution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJAttribution.h; sourceTree = ""; }; + 969952D11A01309200928462 /* ADJAttribution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAttribution.m; sourceTree = ""; }; 96ADB109192E0175006E1D9D /* AdjustBridge.js.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AdjustBridge.js.txt; sourceTree = ""; }; + 96CD2BDC1A13BFC600A40AFB /* NSString+ADJAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+ADJAdditions.h"; sourceTree = ""; }; + 96CD2BDD1A13BFC600A40AFB /* NSString+ADJAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+ADJAdditions.m"; sourceTree = ""; }; + 96CD2BDE1A13BFC600A40AFB /* UIDevice+ADJAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+ADJAdditions.h"; sourceTree = ""; }; + 96CD2BDF1A13BFC600A40AFB /* UIDevice+ADJAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+ADJAdditions.m"; sourceTree = ""; }; 96CD4472192A546F0029A1AA /* AdjustBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdjustBridge.h; sourceTree = ""; }; 96CD4473192A546F0029A1AA /* AdjustBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdjustBridge.m; sourceTree = ""; }; 96CD4475192A546F0029A1AA /* WebViewJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridge.h; sourceTree = ""; }; @@ -103,32 +105,28 @@ 96CD4477192A546F0029A1AA /* WebViewJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge.m; sourceTree = ""; }; 96E5E34C18BBB48A008E7B30 /* Adjust.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Adjust.h; sourceTree = ""; }; 96E5E34D18BBB48A008E7B30 /* Adjust.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Adjust.m; sourceTree = ""; }; - 96E5E36218BBB48A008E7B30 /* AIActivityHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIActivityHandler.h; sourceTree = ""; }; - 96E5E36318BBB48A008E7B30 /* AIActivityHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIActivityHandler.m; sourceTree = ""; }; - 96E5E36418BBB48A008E7B30 /* AIActivityKind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIActivityKind.h; sourceTree = ""; }; - 96E5E36518BBB48A008E7B30 /* AIActivityKind.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIActivityKind.m; sourceTree = ""; }; - 96E5E36618BBB48A008E7B30 /* AIActivityPackage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIActivityPackage.h; sourceTree = ""; }; - 96E5E36718BBB48A008E7B30 /* AIActivityPackage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIActivityPackage.m; sourceTree = ""; }; - 96E5E36818BBB48A008E7B30 /* AIActivityState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIActivityState.h; sourceTree = ""; }; - 96E5E36918BBB48A008E7B30 /* AIActivityState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIActivityState.m; sourceTree = ""; }; - 96E5E36D18BBB48A008E7B30 /* NSString+AIAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+AIAdditions.h"; sourceTree = ""; }; - 96E5E36E18BBB48A008E7B30 /* NSString+AIAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+AIAdditions.m"; sourceTree = ""; }; - 96E5E36F18BBB48A008E7B30 /* UIDevice+AIAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+AIAdditions.h"; sourceTree = ""; }; - 96E5E37018BBB48A008E7B30 /* UIDevice+AIAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+AIAdditions.m"; sourceTree = ""; }; - 96E5E37118BBB48A008E7B30 /* AIAdjustFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIAdjustFactory.h; sourceTree = ""; }; - 96E5E37218BBB48A008E7B30 /* AIAdjustFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIAdjustFactory.m; sourceTree = ""; }; - 96E5E37318BBB48A008E7B30 /* AILogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AILogger.h; sourceTree = ""; }; - 96E5E37418BBB48A008E7B30 /* AILogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AILogger.m; sourceTree = ""; }; - 96E5E37518BBB48A008E7B30 /* AIPackageBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIPackageBuilder.h; sourceTree = ""; }; - 96E5E37618BBB48A008E7B30 /* AIPackageBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIPackageBuilder.m; sourceTree = ""; }; - 96E5E37718BBB48A008E7B30 /* AIPackageHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIPackageHandler.h; sourceTree = ""; }; - 96E5E37818BBB48A008E7B30 /* AIPackageHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIPackageHandler.m; sourceTree = ""; }; - 96E5E37918BBB48A008E7B30 /* AIRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIRequestHandler.h; sourceTree = ""; }; - 96E5E37A18BBB48A008E7B30 /* AIRequestHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIRequestHandler.m; sourceTree = ""; }; - 96E5E37D18BBB48A008E7B30 /* AITimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AITimer.h; sourceTree = ""; }; - 96E5E37E18BBB48A008E7B30 /* AITimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AITimer.m; sourceTree = ""; }; - 96E5E37F18BBB48A008E7B30 /* AIUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIUtil.h; sourceTree = ""; }; - 96E5E38018BBB48A008E7B30 /* AIUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIUtil.m; sourceTree = ""; }; + 96E5E36218BBB48A008E7B30 /* ADJActivityHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityHandler.h; sourceTree = ""; }; + 96E5E36318BBB48A008E7B30 /* ADJActivityHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityHandler.m; sourceTree = ""; }; + 96E5E36418BBB48A008E7B30 /* ADJActivityKind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityKind.h; sourceTree = ""; }; + 96E5E36518BBB48A008E7B30 /* ADJActivityKind.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityKind.m; sourceTree = ""; }; + 96E5E36618BBB48A008E7B30 /* ADJActivityPackage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityPackage.h; sourceTree = ""; }; + 96E5E36718BBB48A008E7B30 /* ADJActivityPackage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityPackage.m; sourceTree = ""; }; + 96E5E36818BBB48A008E7B30 /* ADJActivityState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityState.h; sourceTree = ""; }; + 96E5E36918BBB48A008E7B30 /* ADJActivityState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityState.m; sourceTree = ""; }; + 96E5E37118BBB48A008E7B30 /* ADJAdjustFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJAdjustFactory.h; sourceTree = ""; }; + 96E5E37218BBB48A008E7B30 /* ADJAdjustFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAdjustFactory.m; sourceTree = ""; }; + 96E5E37318BBB48A008E7B30 /* ADJLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJLogger.h; sourceTree = ""; }; + 96E5E37418BBB48A008E7B30 /* ADJLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJLogger.m; sourceTree = ""; }; + 96E5E37518BBB48A008E7B30 /* ADJPackageBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJPackageBuilder.h; sourceTree = ""; }; + 96E5E37618BBB48A008E7B30 /* ADJPackageBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJPackageBuilder.m; sourceTree = ""; }; + 96E5E37718BBB48A008E7B30 /* ADJPackageHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJPackageHandler.h; sourceTree = ""; }; + 96E5E37818BBB48A008E7B30 /* ADJPackageHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJPackageHandler.m; sourceTree = ""; }; + 96E5E37918BBB48A008E7B30 /* ADJRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJRequestHandler.h; sourceTree = ""; }; + 96E5E37A18BBB48A008E7B30 /* ADJRequestHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJRequestHandler.m; sourceTree = ""; }; + 96E5E37D18BBB48A008E7B30 /* ADJTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJTimer.h; sourceTree = ""; }; + 96E5E37E18BBB48A008E7B30 /* ADJTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJTimer.m; sourceTree = ""; }; + 96E5E37F18BBB48A008E7B30 /* ADJUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUtil.h; sourceTree = ""; }; + 96E5E38018BBB48A008E7B30 /* ADJUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUtil.m; sourceTree = ""; }; 96E5E39B18BBB49E008E7B30 /* Adjust-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Adjust-Prefix.pch"; sourceTree = ""; }; 96E5E39C18BBB49E008E7B30 /* AdjustTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "AdjustTests-Info.plist"; sourceTree = ""; }; 96E5E39D18BBB49E008E7B30 /* AIActivityHandlerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIActivityHandlerMock.h; sourceTree = ""; }; @@ -209,6 +207,17 @@ name = Frameworks; sourceTree = ""; }; + 96CD2BDB1A13BFC600A40AFB /* ADJAdditions */ = { + isa = PBXGroup; + children = ( + 96CD2BDC1A13BFC600A40AFB /* NSString+ADJAdditions.h */, + 96CD2BDD1A13BFC600A40AFB /* NSString+ADJAdditions.m */, + 96CD2BDE1A13BFC600A40AFB /* UIDevice+ADJAdditions.h */, + 96CD2BDF1A13BFC600A40AFB /* UIDevice+ADJAdditions.m */, + ); + path = ADJAdditions; + sourceTree = ""; + }; 96CD4471192A546F0029A1AA /* AdjustBridge */ = { isa = PBXGroup; children = ( @@ -233,58 +242,47 @@ 96E5E34B18BBB48A008E7B30 /* Adjust */ = { isa = PBXGroup; children = ( + 96CD2BDB1A13BFC600A40AFB /* ADJAdditions */, 96E5E34C18BBB48A008E7B30 /* Adjust.h */, 96E5E34D18BBB48A008E7B30 /* Adjust.m */, - 96E5E36218BBB48A008E7B30 /* AIActivityHandler.h */, - 96E5E36318BBB48A008E7B30 /* AIActivityHandler.m */, - 96E5E36418BBB48A008E7B30 /* AIActivityKind.h */, - 96E5E36518BBB48A008E7B30 /* AIActivityKind.m */, - 96E5E36618BBB48A008E7B30 /* AIActivityPackage.h */, - 96E5E36718BBB48A008E7B30 /* AIActivityPackage.m */, - 96E5E36818BBB48A008E7B30 /* AIActivityState.h */, - 96E5E36918BBB48A008E7B30 /* AIActivityState.m */, - 96E5E36A18BBB48A008E7B30 /* AIAdditions */, - 96E5E37118BBB48A008E7B30 /* AIAdjustFactory.h */, - 96E5E37218BBB48A008E7B30 /* AIAdjustFactory.m */, - 96E5E37318BBB48A008E7B30 /* AILogger.h */, - 96E5E37418BBB48A008E7B30 /* AILogger.m */, - 96E5E37518BBB48A008E7B30 /* AIPackageBuilder.h */, - 96E5E37618BBB48A008E7B30 /* AIPackageBuilder.m */, - 96E5E37718BBB48A008E7B30 /* AIPackageHandler.h */, - 96E5E37818BBB48A008E7B30 /* AIPackageHandler.m */, - 96E5E37918BBB48A008E7B30 /* AIRequestHandler.h */, - 96E5E37A18BBB48A008E7B30 /* AIRequestHandler.m */, - 96E5E37D18BBB48A008E7B30 /* AITimer.h */, - 96E5E37E18BBB48A008E7B30 /* AITimer.m */, - 96E5E37F18BBB48A008E7B30 /* AIUtil.h */, - 96E5E38018BBB48A008E7B30 /* AIUtil.m */, - 9609BC6819EEA55800E02303 /* AIEvent.h */, - 9609BC6919EEA55800E02303 /* AIEvent.m */, - 9644B7EA19F148F3008576FC /* AIDeviceInfo.h */, - 965307F51A000DA400107FF9 /* AIDeviceInfo.m */, - 9653078119FFD56900107FF9 /* AIUserAgent.h */, - 965307F71A000DCC00107FF9 /* AIUserAgent.m */, - 969952CD1A012F5300928462 /* AIAttributionHandler.h */, - 969952CE1A012F5300928462 /* AIAttributionHandler.m */, - 969952D01A01309200928462 /* AIAttribution.h */, - 969952D11A01309200928462 /* AIAttribution.m */, - 960A8BB71A029A8000F2BB95 /* AdjustConfig.h */, - 960A8BB81A029A8000F2BB95 /* AdjustConfig.m */, + 96E5E36218BBB48A008E7B30 /* ADJActivityHandler.h */, + 96E5E36318BBB48A008E7B30 /* ADJActivityHandler.m */, + 96E5E36418BBB48A008E7B30 /* ADJActivityKind.h */, + 96E5E36518BBB48A008E7B30 /* ADJActivityKind.m */, + 96E5E36618BBB48A008E7B30 /* ADJActivityPackage.h */, + 96E5E36718BBB48A008E7B30 /* ADJActivityPackage.m */, + 96E5E36818BBB48A008E7B30 /* ADJActivityState.h */, + 96E5E36918BBB48A008E7B30 /* ADJActivityState.m */, + 96E5E37118BBB48A008E7B30 /* ADJAdjustFactory.h */, + 96E5E37218BBB48A008E7B30 /* ADJAdjustFactory.m */, + 96E5E37318BBB48A008E7B30 /* ADJLogger.h */, + 96E5E37418BBB48A008E7B30 /* ADJLogger.m */, + 96E5E37518BBB48A008E7B30 /* ADJPackageBuilder.h */, + 96E5E37618BBB48A008E7B30 /* ADJPackageBuilder.m */, + 96E5E37718BBB48A008E7B30 /* ADJPackageHandler.h */, + 96E5E37818BBB48A008E7B30 /* ADJPackageHandler.m */, + 96E5E37918BBB48A008E7B30 /* ADJRequestHandler.h */, + 96E5E37A18BBB48A008E7B30 /* ADJRequestHandler.m */, + 96E5E37D18BBB48A008E7B30 /* ADJTimer.h */, + 96E5E37E18BBB48A008E7B30 /* ADJTimer.m */, + 96E5E37F18BBB48A008E7B30 /* ADJUtil.h */, + 96E5E38018BBB48A008E7B30 /* ADJUtil.m */, + 9609BC6819EEA55800E02303 /* ADJEvent.h */, + 9609BC6919EEA55800E02303 /* ADJEvent.m */, + 9644B7EA19F148F3008576FC /* ADJDeviceInfo.h */, + 965307F51A000DA400107FF9 /* ADJDeviceInfo.m */, + 9653078119FFD56900107FF9 /* ADJUserAgent.h */, + 965307F71A000DCC00107FF9 /* ADJUserAgent.m */, + 969952CD1A012F5300928462 /* ADJAttributionHandler.h */, + 969952CE1A012F5300928462 /* ADJAttributionHandler.m */, + 969952D01A01309200928462 /* ADJAttribution.h */, + 969952D11A01309200928462 /* ADJAttribution.m */, + 960A8BB71A029A8000F2BB95 /* ADJConfig.h */, + 960A8BB81A029A8000F2BB95 /* ADJConfig.m */, ); path = Adjust; sourceTree = ""; }; - 96E5E36A18BBB48A008E7B30 /* AIAdditions */ = { - isa = PBXGroup; - children = ( - 96E5E36D18BBB48A008E7B30 /* NSString+AIAdditions.h */, - 96E5E36E18BBB48A008E7B30 /* NSString+AIAdditions.m */, - 96E5E36F18BBB48A008E7B30 /* UIDevice+AIAdditions.h */, - 96E5E37018BBB48A008E7B30 /* UIDevice+AIAdditions.m */, - ); - path = AIAdditions; - sourceTree = ""; - }; 96E5E39A18BBB49E008E7B30 /* AdjustTests */ = { isa = PBXGroup; children = ( @@ -393,25 +391,23 @@ files = ( 96E5E38118BBB48A008E7B30 /* Adjust.m in Sources */, 96CD4479192A546F0029A1AA /* WebViewJavascriptBridge.m in Sources */, - 96E5E38B18BBB48A008E7B30 /* AIActivityHandler.m in Sources */, - 96E5E39618BBB48A008E7B30 /* AIRequestHandler.m in Sources */, - 96E5E39918BBB48A008E7B30 /* AIUtil.m in Sources */, - 96E5E39818BBB48A008E7B30 /* AITimer.m in Sources */, - 96E5E39118BBB48A008E7B30 /* UIDevice+AIAdditions.m in Sources */, - 96E5E38C18BBB48A008E7B30 /* AIActivityKind.m in Sources */, - 96E5E38D18BBB48A008E7B30 /* AIActivityPackage.m in Sources */, - 965307F61A000DA400107FF9 /* AIDeviceInfo.m in Sources */, - 969952D21A01309200928462 /* AIAttribution.m in Sources */, - 969952CF1A012F5300928462 /* AIAttributionHandler.m in Sources */, - 96E5E38E18BBB48A008E7B30 /* AIActivityState.m in Sources */, - 96E5E39018BBB48A008E7B30 /* NSString+AIAdditions.m in Sources */, - 9609BC6A19EEA55800E02303 /* AIEvent.m in Sources */, - 96E5E39518BBB48A008E7B30 /* AIPackageHandler.m in Sources */, - 965307F81A000DCC00107FF9 /* AIUserAgent.m in Sources */, - 96E5E39318BBB48A008E7B30 /* AILogger.m in Sources */, - 96E5E39418BBB48A008E7B30 /* AIPackageBuilder.m in Sources */, - 960A8BB91A029A8000F2BB95 /* AdjustConfig.m in Sources */, - 96E5E39218BBB48A008E7B30 /* AIAdjustFactory.m in Sources */, + 96E5E38B18BBB48A008E7B30 /* ADJActivityHandler.m in Sources */, + 96E5E39618BBB48A008E7B30 /* ADJRequestHandler.m in Sources */, + 96E5E39918BBB48A008E7B30 /* ADJUtil.m in Sources */, + 96E5E39818BBB48A008E7B30 /* ADJTimer.m in Sources */, + 96E5E38C18BBB48A008E7B30 /* ADJActivityKind.m in Sources */, + 96E5E38D18BBB48A008E7B30 /* ADJActivityPackage.m in Sources */, + 965307F61A000DA400107FF9 /* ADJDeviceInfo.m in Sources */, + 969952D21A01309200928462 /* ADJAttribution.m in Sources */, + 969952CF1A012F5300928462 /* ADJAttributionHandler.m in Sources */, + 96E5E38E18BBB48A008E7B30 /* ADJActivityState.m in Sources */, + 9609BC6A19EEA55800E02303 /* ADJEvent.m in Sources */, + 96E5E39518BBB48A008E7B30 /* ADJPackageHandler.m in Sources */, + 965307F81A000DCC00107FF9 /* ADJUserAgent.m in Sources */, + 96E5E39318BBB48A008E7B30 /* ADJLogger.m in Sources */, + 96E5E39418BBB48A008E7B30 /* ADJPackageBuilder.m in Sources */, + 960A8BB91A029A8000F2BB95 /* ADJConfig.m in Sources */, + 96E5E39218BBB48A008E7B30 /* ADJAdjustFactory.m in Sources */, 96CD4478192A546F0029A1AA /* AdjustBridge.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -422,11 +418,11 @@ files = ( 96E5E3B118BBB49E008E7B30 /* AILoggerMock.m in Sources */, 96E5E3AF18BBB49E008E7B30 /* AIActivityHandlerMock.m in Sources */, - 96E5E3BD18BBB992008E7B30 /* UIDevice+AIAdditions.m in Sources */, 96E5E3B318BBB49E008E7B30 /* AIPackageHandlerTests.m in Sources */, 96E5E3B618BBB49E008E7B30 /* AITestsUtil.m in Sources */, + 96CD2BE11A13BFC600A40AFB /* UIDevice+ADJAdditions.m in Sources */, 96E5E3B018BBB49E008E7B30 /* AIActivityHandlerTests.m in Sources */, - 96E5E3BB18BBB989008E7B30 /* NSString+AIAdditions.m in Sources */, + 96CD2BE01A13BFC600A40AFB /* NSString+ADJAdditions.m in Sources */, 96E5E3B818BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m in Sources */, 96E5E3B418BBB49E008E7B30 /* AIRequestHandlerMock.m in Sources */, 96E5E3B518BBB49E008E7B30 /* AIRequestHandlerTests.m in Sources */, diff --git a/Adjust/AIActivityHandler.h b/Adjust/ADJActivityHandler.h similarity index 61% rename from Adjust/AIActivityHandler.h rename to Adjust/ADJActivityHandler.h index 4153ac129..0e096c2f9 100644 --- a/Adjust/AIActivityHandler.h +++ b/Adjust/ADJActivityHandler.h @@ -1,5 +1,5 @@ // -// AIActivityHandler.h +// ADJActivityHandler.h // Adjust // // Created by Christian Wellenbrock on 2013-07-01. @@ -7,16 +7,16 @@ // #import "Adjust.h" -#import "AIAttribution.h" +#import "ADJAttribution.h" -@protocol AIActivityHandler +@protocol ADJActivityHandler -- (id)initWithConfig:(AdjustConfig *)adjustConfig; +- (id)initWithConfig:(ADJConfig *)adjustConfig; - (void)trackSubsessionStart; - (void)trackSubsessionEnd; -- (void)trackEvent:(AIEvent *)event; +- (void)trackEvent:(ADJEvent *)event; - (void)finishedTrackingWithResponse:(NSDictionary *)jsonDict; - (void)setEnabled:(BOOL)enabled; @@ -24,10 +24,10 @@ - (void)appWillOpenUrl:(NSURL*)url; - (void)setDeviceToken:(NSData *)deviceToken; -- (AIAttribution*) attribution; -- (void) setAttribution:(AIAttribution*)attribution; +- (ADJAttribution*) attribution; +- (void) setAttribution:(ADJAttribution*)attribution; -- (void) updateAttribution:(AIAttribution*) attribution; +- (void) updateAttribution:(ADJAttribution*) attribution; - (void) launchAttributionDelegate; - (void) setOfflineMode:(BOOL)enabled; @@ -40,8 +40,8 @@ @end -@interface AIActivityHandler : NSObject +@interface ADJActivityHandler : NSObject -+ (id)handlerWithConfig:(AdjustConfig *)adjustConfig; ++ (id)handlerWithConfig:(ADJConfig *)adjustConfig; @end diff --git a/Adjust/AIActivityHandler.m b/Adjust/ADJActivityHandler.m similarity index 77% rename from Adjust/AIActivityHandler.m rename to Adjust/ADJActivityHandler.m index 14d5461cb..e8611c0dc 100644 --- a/Adjust/AIActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -1,23 +1,23 @@ // -// AIActivityHandler.m +// ADJActivityHandler.m // Adjust // // Created by Christian Wellenbrock on 2013-07-01. // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AIActivityPackage.h" -#import "AIActivityHandler.h" -#import "AIActivityState.h" -#import "AIPackageBuilder.h" -#import "AIPackageHandler.h" -#import "AILogger.h" -#import "AITimer.h" -#import "AIUtil.h" -#import "UIDevice+AIAdditions.h" -#import "NSString+AIAdditions.h" -#import "AIAdjustFactory.h" -#import "AIAttributionHandler.h" +#import "ADJActivityPackage.h" +#import "ADJActivityHandler.h" +#import "ADJActivityState.h" +#import "ADJPackageBuilder.h" +#import "ADJPackageHandler.h" +#import "ADJLogger.h" +#import "ADJTimer.h" +#import "ADJUtil.h" +#import "UIDevice+ADJAdditions.h" +#import "NSString+ADJAdditions.h" +#import "ADJAdjustFactory.h" +#import "ADJAttributionHandler.h" static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAttributionFilename = @"AdjustIoAttribution"; @@ -31,46 +31,46 @@ #pragma mark - -@interface AIActivityHandler() +@interface ADJActivityHandler() @property (nonatomic) dispatch_queue_t internalQueue; -@property (nonatomic, retain) id packageHandler; -@property (nonatomic, retain) id attributionHandler; -@property (nonatomic, retain) AIActivityState *activityState; -@property (nonatomic, retain) AITimer *timer; -@property (nonatomic, retain) id logger; +@property (nonatomic, retain) id packageHandler; +@property (nonatomic, retain) id attributionHandler; +@property (nonatomic, retain) ADJActivityState *activityState; +@property (nonatomic, retain) ADJTimer *timer; +@property (nonatomic, retain) id logger; @property (nonatomic, retain) NSObject *delegate; -@property (nonatomic, retain) AIAttribution *attribution; -@property (nonatomic, copy) AdjustConfig *adjustConfig; +@property (nonatomic, retain) ADJAttribution *attribution; +@property (nonatomic, copy) ADJConfig *adjustConfig; @property (nonatomic, assign) BOOL enabled; -@property (nonatomic, copy) AIDeviceInfo* deviceInfo; +@property (nonatomic, copy) ADJDeviceInfo* deviceInfo; @end #pragma mark - -@implementation AIActivityHandler +@implementation ADJActivityHandler -+ (id)handlerWithConfig:(AdjustConfig *)adjustConfig { - return [[AIActivityHandler alloc] initWithConfig:adjustConfig]; ++ (id)handlerWithConfig:(ADJConfig *)adjustConfig { + return [[ADJActivityHandler alloc] initWithConfig:adjustConfig]; } -- (id)initWithConfig:(AdjustConfig *)adjustConfig { +- (id)initWithConfig:(ADJConfig *)adjustConfig { self = [super init]; if (self == nil) return nil; if (adjustConfig == nil) { - [AIAdjustFactory.logger error:@"AdjustConfig not initialized correctly"]; + [ADJAdjustFactory.logger error:@"AdjustConfig not initialized correctly"]; return nil; } - self.logger = AIAdjustFactory.logger; + self.logger = ADJAdjustFactory.logger; [self addNotificationObserver]; self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); - self.logger = AIAdjustFactory.logger; + self.logger = ADJAdjustFactory.logger; _enabled = YES; dispatch_async(self.internalQueue, ^{ @@ -92,7 +92,7 @@ - (void)trackSubsessionEnd { }); } -- (void)trackEvent:(AIEvent *)event +- (void)trackEvent:(ADJEvent *)event { dispatch_async(self.internalQueue, ^{ [self eventInternal:event]; @@ -127,7 +127,7 @@ - (void)setEnabled:(BOOL)enabled { _enabled = enabled; if ([self checkActivityState:self.activityState]) { self.activityState.enabled = enabled; - [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; } if (enabled) { [self trackSubsessionStart]; @@ -159,16 +159,16 @@ - (void)setDeviceToken:(NSData *)deviceToken { - (void)setIsIad:(BOOL)isIad { self.deviceInfo.isIad = isIad; if (isIad) { - AIPackageBuilder *clickBuilder = [[AIPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState andConfig:self.adjustConfig]; - AIActivityPackage *reattributionPackage = [clickBuilder buildClickPackage]; + ADJActivityPackage *reattributionPackage = [clickBuilder buildClickPackage]; [self.packageHandler sendClickPackage:reattributionPackage]; } } -- (void)updateAttribution:(AIAttribution *)attribution { +- (void)updateAttribution:(ADJAttribution *)attribution { if (attribution == nil) { return; } @@ -176,7 +176,7 @@ - (void)updateAttribution:(AIAttribution *)attribution { return; } self.attribution = attribution; - [AIUtil writeObject:self.attribution filename:kAttributionFilename objectName:kAttributionName]; + [ADJUtil writeObject:self.attribution filename:kAttributionFilename objectName:kAttributionName]; } - (void)launchAttributionDelegate{ @@ -207,12 +207,12 @@ - (void) addPermanentPartnerParameter:(NSString *)key } #pragma mark - internal -- (void)initInternal:(AdjustConfig *)adjustConfig { +- (void)initInternal:(ADJConfig *)adjustConfig { self.adjustConfig = adjustConfig; - self.deviceInfo = [[AIDeviceInfo alloc] init]; + self.deviceInfo = [[ADJDeviceInfo alloc] init]; if ([adjustConfig.environment isEqualToString:AIEnvironmentProduction]) { - [self.logger setLogLevel:AILogLevelAssert]; + [self.logger setLogLevel:ADJLogLevelAssert]; } else { [self.logger setLogLevel:adjustConfig.logLevel]; } @@ -225,13 +225,13 @@ - (void)initInternal:(AdjustConfig *)adjustConfig { self.deviceInfo.trackingEnabled = UIDevice.currentDevice.aiTrackingEnabled; self.deviceInfo.idForAdvertisers = UIDevice.currentDevice.aiIdForAdvertisers; self.deviceInfo.fbAttributionId = UIDevice.currentDevice.aiFbAttributionId; - self.deviceInfo.userAgent = AIUtil.userAgent; + self.deviceInfo.userAgent = ADJUtil.userAgent; self.deviceInfo.vendorId = UIDevice.currentDevice.aiVendorId; if (adjustConfig.sdkPrefix == nil) { - self.deviceInfo.clientSdk = AIUtil.clientSdk; + self.deviceInfo.clientSdk = ADJUtil.clientSdk; } else { - self.deviceInfo.clientSdk = [NSString stringWithFormat:@"%@@%@", adjustConfig.sdkPrefix, AIUtil.clientSdk]; + self.deviceInfo.clientSdk = [NSString stringWithFormat:@"%@@%@", adjustConfig.sdkPrefix, ADJUtil.clientSdk]; } [self.logger info:@"Tracking of macMd5 is %@", adjustConfig.macMd5TrackingEnabled ? @"enabled" : @"disabled"]; @@ -244,11 +244,11 @@ - (void)initInternal:(AdjustConfig *)adjustConfig { [[UIDevice currentDevice] aiSetIad:self]; - self.packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:self]; - self.attributionHandler = [AIAdjustFactory attributionHandlerForActivityHandler:self withMaxDelay:adjustConfig.attributionMaxTimeMilliseconds]; + self.packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:self]; + self.attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self withMaxDelay:adjustConfig.attributionMaxTimeMilliseconds]; - self.activityState = [AIUtil readObject:kActivityStateFilename objectName:kActivityStateName]; - self.attribution = [AIUtil readObject:kAttributionFilename objectName:kAttributionName]; + self.activityState = [ADJUtil readObject:kActivityStateFilename objectName:kActivityStateName]; + self.attribution = [ADJUtil readObject:kAttributionFilename objectName:kAttributionName]; [self startInternal]; } @@ -268,14 +268,14 @@ - (void)startInternal { // very first session if (self.activityState == nil) { - self.activityState = [[AIActivityState alloc] init]; + self.activityState = [[ADJActivityState alloc] init]; self.activityState.sessionCount = 1; // this is the first session self.activityState.createdAt = now; // starting now [self transferSessionPackage]; [self.activityState resetSessionAttributes:now]; self.activityState.enabled = _enabled; - [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; return; } @@ -283,28 +283,28 @@ - (void)startInternal { if (lastInterval < 0) { [self.logger error:@"Time travel!"]; self.activityState.lastActivity = now; - [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; return; } // new session - if (lastInterval > AIAdjustFactory.sessionInterval) { + if (lastInterval > ADJAdjustFactory.sessionInterval) { self.activityState.sessionCount++; self.activityState.createdAt = now; self.activityState.lastInterval = lastInterval; [self transferSessionPackage]; [self.activityState resetSessionAttributes:now]; - [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; return; } // new subsession - if (lastInterval > AIAdjustFactory.subsessionInterval) { + if (lastInterval > ADJAdjustFactory.subsessionInterval) { self.activityState.subsessionCount++; self.activityState.sessionLength += lastInterval; self.activityState.lastActivity = now; - [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; [self.logger info:@"Processed Subsession %d of Session %d", self.activityState.subsessionCount, self.activityState.sessionCount]; @@ -318,10 +318,10 @@ - (void)endInternal { [self stopTimer]; double now = [NSDate.date timeIntervalSince1970]; [self updateActivityState:now]; - [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; } -- (void)eventInternal:(AIEvent *)event +- (void)eventInternal:(ADJEvent *)event { // check consistency if (![self checkAppTokenNotNil:self.adjustConfig.appToken]) return; @@ -342,12 +342,12 @@ - (void)eventInternal:(AIEvent *)event self.activityState.eventCount++; // create and populate event package - AIPackageBuilder *eventBuilder = [[AIPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + ADJPackageBuilder *eventBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState andConfig:self.adjustConfig]; eventBuilder.event = event; - AIActivityPackage *eventPackage = [eventBuilder buildEventPackage]; + ADJActivityPackage *eventPackage = [eventBuilder buildEventPackage]; [self.packageHandler addPackage:eventPackage]; if (self.adjustConfig.eventBufferingEnabled) { @@ -356,7 +356,7 @@ - (void)eventInternal:(AIEvent *)event [self.packageHandler sendFirstPackage]; } - [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; } - (void) appWillOpenUrlInternal:(NSURL *)url { @@ -385,12 +385,12 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { return; } - AIPackageBuilder *ClickBuilder = [[AIPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + ADJPackageBuilder *ClickBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState andConfig:self.adjustConfig]; ClickBuilder.deeplinkParameters = adjustDeepLinks; - AIActivityPackage *reattributionPackage = [ClickBuilder buildClickPackage]; + ADJActivityPackage *reattributionPackage = [ClickBuilder buildClickPackage]; [self.packageHandler sendClickPackage:reattributionPackage]; } @@ -419,20 +419,20 @@ - (BOOL)updateActivityState:(double)now { } // ignore late updates - if (lastInterval > AIAdjustFactory.sessionInterval) return NO; + if (lastInterval > ADJAdjustFactory.sessionInterval) return NO; self.activityState.sessionLength += lastInterval; self.activityState.timeSpent += lastInterval; self.activityState.lastActivity = now; - return (lastInterval > AIAdjustFactory.subsessionInterval); + return (lastInterval > ADJAdjustFactory.subsessionInterval); } - (void)transferSessionPackage { - AIPackageBuilder *sessionBuilder = [[AIPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + ADJPackageBuilder *sessionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState andConfig:self.adjustConfig]; - AIActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage]; + ADJActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage]; [self.packageHandler addPackage:sessionPackage]; [self.packageHandler sendFirstPackage]; } @@ -440,7 +440,7 @@ - (void)transferSessionPackage { # pragma mark - timer - (void)startTimer { if (self.timer == nil) { - self.timer = [AITimer timerWithInterval:kTimerInterval + self.timer = [ADJTimer timerWithInterval:kTimerInterval leeway:kTimerLeeway queue:self.internalQueue block:^{ [self timerFired]; }]; @@ -460,7 +460,7 @@ - (void)timerFired { [self.packageHandler sendFirstPackage]; double now = [NSDate.date timeIntervalSince1970]; if ([self updateActivityState:now]) { - [AIUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; } } @@ -490,7 +490,7 @@ - (void)removeNotificationObserver { } #pragma mark - checks -- (BOOL)checkActivityState:(AIActivityState *)activityState { +- (BOOL)checkActivityState:(ADJActivityState *)activityState { if (activityState == nil) { [self.logger error:@"Missing activity state"]; return NO; diff --git a/Adjust/ADJActivityKind.h b/Adjust/ADJActivityKind.h new file mode 100644 index 000000000..6e3bb89dc --- /dev/null +++ b/Adjust/ADJActivityKind.h @@ -0,0 +1,20 @@ +// +// ADJActivityKind.h +// Adjust +// +// Created by Christian Wellenbrock on 11.02.14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import + +typedef enum { + ADJActivityKindUnknown = 0, + ADJActivityKindSession = 1, + ADJActivityKindEvent = 2, + ADJActivityKindRevenue = 3, + ADJActivityKindReattribution = 4, +} ADJActivityKind; + +ADJActivityKind ADJActivityKindFromString(NSString *string); +NSString* ADJActivityKindToString(ADJActivityKind activityKind); diff --git a/Adjust/ADJActivityKind.m b/Adjust/ADJActivityKind.m new file mode 100644 index 000000000..aaf774b5d --- /dev/null +++ b/Adjust/ADJActivityKind.m @@ -0,0 +1,33 @@ +// +// ADJActivityKind.m +// Adjust +// +// Created by Christian Wellenbrock on 11.02.14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import "ADJActivityKind.h" + +ADJActivityKind ADJActivityKindFromString(NSString *string) { + if ([@"session" isEqualToString:string]) { + return ADJActivityKindSession; + } else if ([@"event" isEqualToString:string]) { + return ADJActivityKindEvent; + } else if ([@"revenue" isEqualToString:string]) { + return ADJActivityKindRevenue; + } else if ([@"reattribution" isEqualToString:string]) { + return ADJActivityKindReattribution; + } else { + return ADJActivityKindUnknown; + } +} + +NSString* ADJActivityKindToString(ADJActivityKind activityKind) { + switch (activityKind) { + case ADJActivityKindSession: return @"session"; + case ADJActivityKindEvent: return @"event"; + case ADJActivityKindRevenue: return @"revenue"; + case ADJActivityKindReattribution: return @"reattribution"; + case ADJActivityKindUnknown: return @"unknown"; + } +} diff --git a/Adjust/AIActivityPackage.h b/Adjust/ADJActivityPackage.h similarity index 72% rename from Adjust/AIActivityPackage.h rename to Adjust/ADJActivityPackage.h index 7079d6ef4..a6b84a84e 100644 --- a/Adjust/AIActivityPackage.h +++ b/Adjust/ADJActivityPackage.h @@ -1,14 +1,14 @@ // -// AIActivityPackage.h +// ADJActivityPackage.h // Adjust // // Created by Christian Wellenbrock on 2013-07-03. // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AIActivityKind.h" +#import "ADJActivityKind.h" -@interface AIActivityPackage : NSObject +@interface ADJActivityPackage : NSObject // data @property (nonatomic, copy) NSString *path; @@ -16,7 +16,7 @@ @property (nonatomic, retain) NSDictionary *parameters; // logs -@property (nonatomic, assign) AIActivityKind activityKind; +@property (nonatomic, assign) ADJActivityKind activityKind; @property (nonatomic, copy) NSString *suffix; - (NSString *)extendedString; diff --git a/Adjust/AIActivityPackage.m b/Adjust/ADJActivityPackage.m similarity index 81% rename from Adjust/AIActivityPackage.m rename to Adjust/ADJActivityPackage.m index c0de84e2d..db2a9257f 100644 --- a/Adjust/AIActivityPackage.m +++ b/Adjust/ADJActivityPackage.m @@ -1,20 +1,20 @@ // -// AIActivityPackage.m +// ADJActivityPackage.m // Adjust // // Created by Christian Wellenbrock on 2013-07-03. // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AIActivityPackage.h" -#import "AIActivityKind.h" +#import "ADJActivityPackage.h" +#import "ADJActivityKind.h" #pragma mark - -@implementation AIActivityPackage +@implementation ADJActivityPackage - (NSString *)description { return [NSString stringWithFormat:@"%@%@", - AIActivityKindToString(self.activityKind), + ADJActivityKindToString(self.activityKind), self.suffix]; } @@ -36,13 +36,13 @@ - (NSString *)extendedString { - (NSString *)successMessage { return [NSString stringWithFormat:@"Tracked %@%@", - AIActivityKindToString(self.activityKind), + ADJActivityKindToString(self.activityKind), self.suffix]; } - (NSString *)failureMessage { return [NSString stringWithFormat:@"Failed to track %@%@", - AIActivityKindToString(self.activityKind), + ADJActivityKindToString(self.activityKind), self.suffix]; } @@ -57,13 +57,13 @@ - (id)initWithCoder:(NSCoder *)decoder { NSString *kindString = [decoder decodeObjectForKey:@"kind"]; self.suffix = [decoder decodeObjectForKey:@"suffix"]; - self.activityKind = AIActivityKindFromString(kindString); + self.activityKind = ADJActivityKindFromString(kindString); return self; } - (void)encodeWithCoder:(NSCoder *)encoder { - NSString *kindString = AIActivityKindToString(self.activityKind); + NSString *kindString = ADJActivityKindToString(self.activityKind); [encoder encodeObject:self.path forKey:@"path"]; [encoder encodeObject:self.clientSdk forKey:@"clientSdk"]; diff --git a/Adjust/AIActivityState.h b/Adjust/ADJActivityState.h similarity index 91% rename from Adjust/AIActivityState.h rename to Adjust/ADJActivityState.h index cb2744bcd..64e04d568 100644 --- a/Adjust/AIActivityState.h +++ b/Adjust/ADJActivityState.h @@ -1,5 +1,5 @@ // -// AIActivityState.h +// ADJActivityState.h // Adjust // // Created by Christian Wellenbrock on 2013-07-02. @@ -7,9 +7,7 @@ // #import -@class AIPackageBuilder; - -@interface AIActivityState : NSObject +@interface ADJActivityState : NSObject // persistent data @property (nonatomic, copy) NSString *uuid; diff --git a/Adjust/AIActivityState.m b/Adjust/ADJActivityState.m similarity index 89% rename from Adjust/AIActivityState.m rename to Adjust/ADJActivityState.m index 10d41373d..ba131c088 100644 --- a/Adjust/AIActivityState.m +++ b/Adjust/ADJActivityState.m @@ -1,20 +1,18 @@ // -// AIActivityState.m +// ADJActivityState.m // Adjust // // Created by Christian Wellenbrock on 2013-07-02. // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AIActivityState.h" -#import "AIPackageBuilder.h" -#import "UIDevice+AIAdditions.h" - +#import "ADJActivityState.h" +#import "UIDevice+ADJAdditions.h" static const int kTransactionIdCount = 10; #pragma mark public implementation -@implementation AIActivityState +@implementation ADJActivityState - (id)init { self = [super init]; @@ -46,17 +44,6 @@ - (void)resetSessionAttributes:(double)now { self.lastInterval = -1; } -/* -- (void)injectSessionAttributes:(AIPackageBuilder *)builder { - [self injectGeneralAttributes:builder]; - builder.lastInterval = self.lastInterval; -} - -- (void)injectEventAttributes:(AIPackageBuilder *)builder { - [self injectGeneralAttributes:builder]; - builder.eventCount = self.eventCount; -} -*/ - (void)addTransactionId:(NSString *)transactionId { if (self.transactionIds == nil) { // create array self.transactionIds = [NSMutableArray arrayWithCapacity:kTransactionIdCount]; @@ -129,7 +116,7 @@ - (void)encodeWithCoder:(NSCoder *)encoder { -(id)copyWithZone:(NSZone *)zone { - AIActivityState* copy = [[[self class] allocWithZone:zone] init]; + ADJActivityState* copy = [[[self class] allocWithZone:zone] init]; if (copy) { copy.sessionCount = self.sessionCount; copy.subsessionCount = self.subsessionCount; diff --git a/Adjust/AIAdditions/NSString+AIAdditions.h b/Adjust/ADJAdditions/NSString+ADJAdditions.h similarity index 85% rename from Adjust/AIAdditions/NSString+AIAdditions.h rename to Adjust/ADJAdditions/NSString+ADJAdditions.h index 75157b68c..9829d4fb4 100644 --- a/Adjust/AIAdditions/NSString+AIAdditions.h +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.h @@ -1,5 +1,5 @@ // -// NSString+AIAdditions.h +// NSString+ADJAdditions.h // Adjust // // Created by Christian Wellenbrock on 23.07.12. @@ -7,7 +7,7 @@ // #import -@interface NSString(AIAdditions) +@interface NSString(ADJAdditions) - (NSString *)aiTrim; - (NSString *)aiQuote; diff --git a/Adjust/AIAdditions/NSString+AIAdditions.m b/Adjust/ADJAdditions/NSString+ADJAdditions.m similarity index 95% rename from Adjust/AIAdditions/NSString+AIAdditions.m rename to Adjust/ADJAdditions/NSString+ADJAdditions.m index 183cf327c..337bc5ec2 100644 --- a/Adjust/AIAdditions/NSString+AIAdditions.m +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.m @@ -1,16 +1,16 @@ // -// NSString+AIAdditions.m +// NSString+ADJAdditions.m // Adjust // // Created by Christian Wellenbrock on 23.07.12. // Copyright (c) 2012-2014 adjust GmbH. All rights reserved. // -#import "NSString+AIAdditions.h" +#import "NSString+ADJAdditions.h" #import "CommonCrypto/CommonDigest.h" -@implementation NSString(AIAdditions) +@implementation NSString(ADJAdditions) - (NSString *)aiTrim { return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; diff --git a/Adjust/AIAdditions/UIDevice+AIAdditions.h b/Adjust/ADJAdditions/UIDevice+ADJAdditions.h similarity index 74% rename from Adjust/AIAdditions/UIDevice+AIAdditions.h rename to Adjust/ADJAdditions/UIDevice+ADJAdditions.h index 615e49c5b..413828bc7 100644 --- a/Adjust/AIAdditions/UIDevice+AIAdditions.h +++ b/Adjust/ADJAdditions/UIDevice+ADJAdditions.h @@ -1,5 +1,5 @@ // -// UIDevice+AIAdditions.h +// UIDevice+ADJAdditions.h // Adjust // // Created by Christian Wellenbrock on 23.07.12. @@ -7,9 +7,9 @@ // #import #import -#import "AIActivityHandler.h" +#import "ADJActivityHandler.h" -@interface UIDevice(AIAdditions) +@interface UIDevice(ADJAdditions) - (BOOL)aiTrackingEnabled; - (NSString *)aiIdForAdvertisers; @@ -19,5 +19,5 @@ - (NSString *)aiDeviceName; - (NSString *)aiCreateUuid; - (NSString *)aiVendorId; -- (void)aiSetIad:(AIActivityHandler *)activityHandler; +- (void)aiSetIad:(ADJActivityHandler *)activityHandler; @end diff --git a/Adjust/AIAdditions/UIDevice+AIAdditions.m b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m similarity index 96% rename from Adjust/AIAdditions/UIDevice+AIAdditions.m rename to Adjust/ADJAdditions/UIDevice+ADJAdditions.m index 810811529..7697b3248 100644 --- a/Adjust/AIAdditions/UIDevice+AIAdditions.m +++ b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m @@ -1,13 +1,13 @@ // -// UIDevice+AIAdditions.m +// UIDevice+ADJAdditions.m // Adjust // // Created by Christian Wellenbrock on 23.07.12. // Copyright (c) 2012-2014 adjust GmbH. All rights reserved. // -#import "UIDevice+AIAdditions.h" -#import "NSString+AIAdditions.h" +#import "UIDevice+ADJAdditions.h" +#import "NSString+ADJAdditions.h" #import #import @@ -22,7 +22,7 @@ #import #endif -@implementation UIDevice(AIAdditions) +@implementation UIDevice(ADJAdditions) - (BOOL)aiTrackingEnabled { #if !ADJUST_NO_IDFA @@ -169,7 +169,7 @@ - (NSString *)aiVendorId { return @""; } -- (void) aiSetIad:(AIActivityHandler *) activityHandler{ +- (void) aiSetIad:(ADJActivityHandler *) activityHandler{ #if !ADJUST_NO_IDA Class ADClientClass = NSClassFromString(@"ADClient"); if (ADClientClass) { diff --git a/Adjust/ADJAdjustFactory.h b/Adjust/ADJAdjustFactory.h new file mode 100644 index 000000000..f0aedf0cf --- /dev/null +++ b/Adjust/ADJAdjustFactory.h @@ -0,0 +1,34 @@ +// +// ADJAdjustFactory.h +// Adjust +// +// Created by Pedro Filipe on 07/02/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// +#import + +#import "ADJActivityHandler.h" +#import "ADJPackageHandler.h" +#import "ADJRequestHandler.h" +#import "ADJLogger.h" +#import "ADJAttributionHandler.h" + +@interface ADJAdjustFactory : NSObject + ++ (id)packageHandlerForActivityHandler:(id)activityHandler; ++ (id)requestHandlerForPackageHandler:(id)packageHandler; ++ (id)activityHandlerWithConfig:(ADJConfig *)adjustConfig; ++ (id)logger; ++ (double)sessionInterval; ++ (double)subsessionInterval; ++ (id)attributionHandlerForActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds; + ++ (void)setPackageHandler:(id)packageHandler; ++ (void)setRequestHandler:(id)requestHandler; ++ (void)setActivityHandler:(id)activityHandler; ++ (void)setLogger:(id)logger; ++ (void)setSessionInterval:(double)sessionInterval; ++ (void)setSubsessionInterval:(double)subsessionInterval; ++ (void)setAttributionHandler:(id)attributionHandler; + +@end diff --git a/Adjust/AIAdjustFactory.m b/Adjust/ADJAdjustFactory.m similarity index 51% rename from Adjust/AIAdjustFactory.m rename to Adjust/ADJAdjustFactory.m index 576599e60..7ef358a45 100644 --- a/Adjust/AIAdjustFactory.m +++ b/Adjust/ADJAdjustFactory.m @@ -1,50 +1,50 @@ // -// AIAdjustFactory.m +// ADJAdjustFactory.m // Adjust // // Created by Pedro Filipe on 07/02/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIAdjustFactory.h" +#import "ADJAdjustFactory.h" -static id internalPackageHandler = nil; -static id internalRequestHandler = nil; -static id internalActivityHandler = nil; -static id internalLogger = nil; -static id internalAttributionHandler = nil; +static id internalPackageHandler = nil; +static id internalRequestHandler = nil; +static id internalActivityHandler = nil; +static id internalLogger = nil; +static id internalAttributionHandler = nil; static double internalSessionInterval = -1; static double intervalSubsessionInterval = -1; -@implementation AIAdjustFactory +@implementation ADJAdjustFactory -+ (id)packageHandlerForActivityHandler:(id)activityHandler { ++ (id)packageHandlerForActivityHandler:(id)activityHandler { if (internalPackageHandler == nil) { - return [AIPackageHandler handlerWithActivityHandler:activityHandler]; + return [ADJPackageHandler handlerWithActivityHandler:activityHandler]; } return [internalPackageHandler initWithActivityHandler:activityHandler]; } -+ (id)requestHandlerForPackageHandler:(id)packageHandler { ++ (id)requestHandlerForPackageHandler:(id)packageHandler { if (internalRequestHandler == nil) { - return [AIRequestHandler handlerWithPackageHandler:packageHandler]; + return [ADJRequestHandler handlerWithPackageHandler:packageHandler]; } return [internalRequestHandler initWithPackageHandler:packageHandler]; } -+ (id)activityHandlerWithConfig:(AdjustConfig *)adjustConfig { ++ (id)activityHandlerWithConfig:(ADJConfig *)adjustConfig { if (internalActivityHandler == nil) { - return [AIActivityHandler handlerWithConfig:adjustConfig]; + return [ADJActivityHandler handlerWithConfig:adjustConfig]; } return [internalActivityHandler initWithConfig:adjustConfig]; } -+ (id)logger { ++ (id)logger { if (internalLogger == nil) { // same instance of logger - internalLogger = [[AILogger alloc] init]; + internalLogger = [[ADJLogger alloc] init]; } return internalLogger; } @@ -63,27 +63,27 @@ + (double)subsessionInterval { return intervalSubsessionInterval; } -+ (id)attributionHandlerForActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds{ ++ (id)attributionHandlerForActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds{ if (internalAttributionHandler == nil) { - return [AIAttributionHandler handlerWithActivityHandler:activityHandler withMaxDelay:milliseconds]; + return [ADJAttributionHandler handlerWithActivityHandler:activityHandler withMaxDelay:milliseconds]; } return [internalAttributionHandler initWithActivityHandler:activityHandler withMaxDelay:milliseconds]; } -+ (void)setPackageHandler:(id)packageHandler { ++ (void)setPackageHandler:(id)packageHandler { internalPackageHandler = packageHandler; } -+ (void)setRequestHandler:(id)requestHandler { ++ (void)setRequestHandler:(id)requestHandler { internalRequestHandler = requestHandler; } -+ (void)setActivityHandler:(id)activityHandler { ++ (void)setActivityHandler:(id)activityHandler { internalActivityHandler = activityHandler; } -+ (void)setLogger:(id)logger { ++ (void)setLogger:(id)logger { internalLogger = logger; } @@ -95,7 +95,7 @@ + (void)setSubsessionInterval:(double)subsessionInterval { intervalSubsessionInterval = subsessionInterval; } -+ (void)setAttributionHandler:(id)attributionHandler { ++ (void)setAttributionHandler:(id)attributionHandler { internalAttributionHandler = attributionHandler; } @end diff --git a/Adjust/AIAttribution.h b/Adjust/ADJAttribution.h similarity index 81% rename from Adjust/AIAttribution.h rename to Adjust/ADJAttribution.h index 42430f9cb..9d4ca45c7 100644 --- a/Adjust/AIAttribution.h +++ b/Adjust/ADJAttribution.h @@ -1,5 +1,5 @@ // -// AIAttribution.h +// ADJAttribution.h // adjust // // Created by Pedro Filipe on 29/10/14. @@ -8,7 +8,7 @@ #import -@interface AIAttribution : NSObject +@interface ADJAttribution : NSObject // the following attributes are only set when error is nil // (when activity was tracked successfully and response could be parsed) @@ -33,9 +33,9 @@ @property (nonatomic, assign) BOOL finalAttribution; -- (BOOL)isEqualToAttribution:(AIAttribution *)attribution; +- (BOOL)isEqualToAttribution:(ADJAttribution *)attribution; -+ (AIAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict; ++ (ADJAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict; - (id)initWithJsonDict:(NSDictionary *)jsonDict; - (NSDictionary *)dictionary; diff --git a/Adjust/AIAttribution.m b/Adjust/ADJAttribution.m similarity index 91% rename from Adjust/AIAttribution.m rename to Adjust/ADJAttribution.m index d9ec91ef9..48d697e49 100644 --- a/Adjust/AIAttribution.m +++ b/Adjust/ADJAttribution.m @@ -1,17 +1,17 @@ // -// AIAttribution.m +// ADJAttribution.m // adjust // // Created by Pedro Filipe on 29/10/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIAttribution.h" +#import "ADJAttribution.h" -@implementation AIAttribution +@implementation ADJAttribution -+ (AIAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict { - return [[AIAttribution alloc] initWithJsonDict:jsonDict]; ++ (ADJAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict { + return [[ADJAttribution alloc] initWithJsonDict:jsonDict]; } - (id)initWithJsonDict:(NSDictionary *)jsonDict { @@ -35,7 +35,7 @@ - (id)initWithJsonDict:(NSDictionary *)jsonDict { return self; } -- (BOOL)isEqualToAttribution:(AIAttribution *)attribution { +- (BOOL)isEqualToAttribution:(ADJAttribution *)attribution { if (attribution == nil) { return NO; } @@ -109,11 +109,11 @@ - (BOOL)isEqual:(id)object { return YES; } - if (![object isKindOfClass:[AIAttribution class]]) { + if (![object isKindOfClass:[ADJAttribution class]]) { return NO; } - return [self isEqualToAttribution:(AIAttribution *)object]; + return [self isEqualToAttribution:(ADJAttribution *)object]; } - (NSUInteger)hash { diff --git a/Adjust/ADJAttributionHandler.h b/Adjust/ADJAttributionHandler.h new file mode 100644 index 000000000..0b0f61a16 --- /dev/null +++ b/Adjust/ADJAttributionHandler.h @@ -0,0 +1,27 @@ +// +// ADJAttributionHandler.h +// adjust +// +// Created by Pedro Filipe on 29/10/14. +// Copyright (c) 2014 adjust GmbH. All rights reserved. +// + +#import +#import "ADJActivityHandler.h" + +@protocol ADJAttributionHandler + +- (id)initWithActivityHandler:(id) activityHandler withMaxDelay:(NSNumber* )milliseconds; + +- (void)checkAttribution:(NSDictionary *)jsonDict; + +- (void)getAttribution; + +@end + +@interface ADJAttributionHandler : NSObject + ++ (id)handlerWithActivityHandler:(id)activityHandler + withMaxDelay:(NSNumber* )milliseconds; + +@end diff --git a/Adjust/AIAttributionHandler.m b/Adjust/ADJAttributionHandler.m similarity index 67% rename from Adjust/AIAttributionHandler.m rename to Adjust/ADJAttributionHandler.m index 9dbdfef21..a259686d8 100644 --- a/Adjust/AIAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -1,53 +1,53 @@ // -// AIAttributionHandler.m +// ADJAttributionHandler.m // adjust // // Created by Pedro Filipe on 29/10/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIAttributionHandler.h" -#import "AIAdjustFactory.h" -#import "AIUtil.h" -#import "AIActivityHandler.h" -#import "NSString+AIAdditions.h" -#import "AITimer.h" +#import "ADJAttributionHandler.h" +#import "ADJAdjustFactory.h" +#import "ADJUtil.h" +#import "ADJActivityHandler.h" +#import "NSString+ADJAdditions.h" +#import "ADJTimer.h" static const uint64_t kTimerLeeway = 1 * NSEC_PER_SEC; // 1 second -@interface AIAttributionHandler() +@interface ADJAttributionHandler() @property (nonatomic) dispatch_queue_t internalQueue; -@property (nonatomic, assign) id activityHandler; -@property (nonatomic, assign) id logger; +@property (nonatomic, assign) id activityHandler; +@property (nonatomic, assign) id logger; @property (nonatomic, retain) NSURL *url; -@property (nonatomic, retain) AITimer *askInTimer; -@property (nonatomic, retain) AITimer *maxDelayTimer; +@property (nonatomic, retain) ADJTimer *askInTimer; +@property (nonatomic, retain) ADJTimer *maxDelayTimer; @end static const double kRequestTimeout = 60; // 60 seconds -@implementation AIAttributionHandler +@implementation ADJAttributionHandler -+ (id)handlerWithActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds{ - return [[AIAttributionHandler alloc] initWithActivityHandler:activityHandler withMaxDelay:milliseconds]; ++ (id)handlerWithActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds{ + return [[ADJAttributionHandler alloc] initWithActivityHandler:activityHandler withMaxDelay:milliseconds]; } -- (id)initWithActivityHandler:(id) activityHandler +- (id)initWithActivityHandler:(id) activityHandler withMaxDelay:(NSNumber* )milliseconds{ self = [super init]; if (self == nil) return nil; self.internalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); self.activityHandler = activityHandler; - self.logger = AIAdjustFactory.logger; - self.url = [NSURL URLWithString:AIUtil.baseUrl]; + self.logger = ADJAdjustFactory.logger; + self.url = [NSURL URLWithString:ADJUtil.baseUrl]; //TODO change baseURL if (milliseconds != nil) { uint64_t timer_nano = [milliseconds intValue] * NSEC_PER_MSEC; - self.maxDelayTimer = [AITimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self.activityHandler launchAttributionDelegate]; }]; + self.maxDelayTimer = [ADJTimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self.activityHandler launchAttributionDelegate]; }]; [self.maxDelayTimer resume]; } @@ -71,7 +71,7 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { if (jsonDict == nil) return; NSDictionary* jsonAttribution = [jsonDict objectForKey:@"attribution"]; - AIAttribution * attribution = [AIAttribution dataWithJsonDict:jsonAttribution]; + ADJAttribution * attribution = [ADJAttribution dataWithJsonDict:jsonAttribution]; NSNumber * timer_milliseconds = [jsonDict objectForKey:@"ask_in"]; @@ -87,7 +87,7 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { }; uint64_t timer_nano = [timer_milliseconds intValue] * NSEC_PER_MSEC; - self.askInTimer = [AITimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self getAttributionInternal]; }]; + self.askInTimer = [ADJTimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self getAttributionInternal]; }]; [self.askInTimer resume]; } @@ -108,7 +108,7 @@ -(void) getAttributionInternal { NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; [self.logger verbose:@"attribution response: %@", responseString]; - NSDictionary *jsonDict = [AIUtil buildJsonDict:responseString]; + NSDictionary *jsonDict = [ADJUtil buildJsonDict:responseString]; if (jsonDict == nil) { [self.logger error:@"Failed to parse json attribution response: %@", responseString.aiTrim]; diff --git a/Adjust/AdjustConfig.h b/Adjust/ADJConfig.h similarity index 83% rename from Adjust/AdjustConfig.h rename to Adjust/ADJConfig.h index ad1a28310..fd7df4e56 100644 --- a/Adjust/AdjustConfig.h +++ b/Adjust/ADJConfig.h @@ -1,5 +1,5 @@ // -// AdjustConfig.h +// ADJConfig.h // adjust // // Created by Pedro Filipe on 30/10/14. @@ -7,8 +7,8 @@ // #import -#import "AILogger.h" -#import "AIAttribution.h" +#import "ADJLogger.h" +#import "ADJAttribution.h" /** * Optional delegate that will get informed about tracking results @@ -22,14 +22,14 @@ * @param responseData The response data containing information about the activity * and it's server response. See AIResponseData for details. */ -- (void)adjustAttributionCallback:(AIAttribution *)attribution; +- (void)adjustAttributionCallback:(ADJAttribution *)attribution; @end -@interface AdjustConfig : NSObject +@interface ADJConfig : NSObject @property (nonatomic, copy) NSString *appToken; -@property (nonatomic, assign) AILogLevel logLevel; +@property (nonatomic, assign) ADJLogLevel logLevel; @property (nonatomic, copy) NSString *environment; @property (nonatomic, copy) NSString *sdkPrefix; @property (nonatomic, assign) BOOL eventBufferingEnabled; @@ -47,6 +47,6 @@ - (void)addPermanentPartnerParameter:(NSString *)key andValue:(NSString *)value; -- (void)setAttributionMaxTime:(double)milliseconds; +- (void)setAttributionMaxTime:(int)milliseconds; @end diff --git a/Adjust/AdjustConfig.m b/Adjust/ADJConfig.m similarity index 89% rename from Adjust/AdjustConfig.m rename to Adjust/ADJConfig.m index 5efb3e140..b46d4905b 100644 --- a/Adjust/AdjustConfig.m +++ b/Adjust/ADJConfig.m @@ -6,11 +6,11 @@ // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AdjustConfig.h" -#import "AIAdjustFactory.h" -#import "AILogger.h" +#import "ADJConfig.h" +#import "ADJAdjustFactory.h" +#import "ADJLogger.h" -@implementation AdjustConfig +@implementation ADJConfig - (id) initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment @@ -25,7 +25,7 @@ - (id) initWithAppToken:(NSString *)appToken self.environment = environment; // default values - self.logLevel = AILogLevelInfo; + self.logLevel = ADJLogLevelInfo; self.macMd5TrackingEnabled = YES; return self; @@ -55,7 +55,7 @@ - (void) setAttributionMaxTime:(int)milliseconds { - (BOOL) checkEnvironment:(NSString *)environment { - id logger = AIAdjustFactory.logger; + id logger = ADJAdjustFactory.logger; if ([environment isEqualToString:AIEnvironmentSandbox]) { [logger assert:@"SANDBOX: Adjust will run in Sandbox mode. Use this setting for testing. Don't forget to set the environment to AIEnvironmentProduction before publishing!"]; return YES; @@ -69,7 +69,7 @@ - (BOOL) checkEnvironment:(NSString *)environment - (BOOL)checkAppTokenLength:(NSString *)appToken { if (appToken == nil || appToken.length != 12) { - [AIAdjustFactory.logger error:@"Malformed App Token '%@'", appToken]; + [ADJAdjustFactory.logger error:@"Malformed App Token '%@'", appToken]; return NO; } return YES; @@ -77,7 +77,7 @@ - (BOOL)checkAppTokenLength:(NSString *)appToken { -(id)copyWithZone:(NSZone *)zone { - AdjustConfig* copy = [[[self class] allocWithZone:zone] init]; + ADJConfig* copy = [[[self class] allocWithZone:zone] init]; if (copy) { copy.appToken = [self.appToken copyWithZone:zone]; copy.logLevel = self.logLevel; diff --git a/Adjust/AIDeviceInfo.h b/Adjust/ADJDeviceInfo.h similarity index 75% rename from Adjust/AIDeviceInfo.h rename to Adjust/ADJDeviceInfo.h index 9723027b2..6fe950e82 100644 --- a/Adjust/AIDeviceInfo.h +++ b/Adjust/ADJDeviceInfo.h @@ -1,5 +1,5 @@ // -// AIDeviceInfo.h +// ADJDeviceInfo.h // adjust // // Created by Pedro Filipe on 17/10/14. @@ -7,11 +7,9 @@ // #import -#import "AIUserAgent.h" -#import "AdjustConfig.h" -#import "AIActivityState.h" +#import "ADJUserAgent.h" -@interface AIDeviceInfo : NSObject +@interface ADJDeviceInfo : NSObject @property (nonatomic, copy) NSString *macSha1; @property (nonatomic, copy) NSString *macShortMd5; @@ -22,6 +20,6 @@ @property (nonatomic, copy) NSString *vendorId; @property (nonatomic, copy) NSString *pushToken; @property (nonatomic, copy) NSString *clientSdk; -@property (nonatomic, copy) AIUserAgent *userAgent; +@property (nonatomic, copy) ADJUserAgent *userAgent; @end diff --git a/Adjust/AIDeviceInfo.m b/Adjust/ADJDeviceInfo.m similarity index 84% rename from Adjust/AIDeviceInfo.m rename to Adjust/ADJDeviceInfo.m index eea13c149..2d26d6fc4 100644 --- a/Adjust/AIDeviceInfo.m +++ b/Adjust/ADJDeviceInfo.m @@ -1,18 +1,18 @@ // -// AIDeviceInfo.m +// ADJDeviceInfo.m // adjust // // Created by Pedro Filipe on 17/10/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIDeviceInfo.h" +#import "ADJDeviceInfo.h" -@implementation AIDeviceInfo +@implementation ADJDeviceInfo -(id)copyWithZone:(NSZone *)zone { - AIDeviceInfo* copy = [[[self class] allocWithZone:zone] init]; + ADJDeviceInfo* copy = [[[self class] allocWithZone:zone] init]; if (copy) { copy.macSha1 = [self.macSha1 copyWithZone:zone]; copy.macShortMd5 = [self.macShortMd5 copyWithZone:zone]; diff --git a/Adjust/AIEvent.h b/Adjust/ADJEvent.h similarity index 93% rename from Adjust/AIEvent.h rename to Adjust/ADJEvent.h index 1f84bf5cf..ab4ddb109 100644 --- a/Adjust/AIEvent.h +++ b/Adjust/ADJEvent.h @@ -1,5 +1,5 @@ // -// AITrackOption.h +// ADJEvent.h // adjust // // Created by Pedro Filipe on 15/10/14. @@ -8,7 +8,7 @@ #import -@interface AIEvent : NSObject +@interface ADJEvent : NSObject @property (nonatomic, copy) NSString* eventToken; @property (nonatomic, copy) NSNumber* revenue; diff --git a/Adjust/AIEvent.m b/Adjust/ADJEvent.m similarity index 92% rename from Adjust/AIEvent.m rename to Adjust/ADJEvent.m index 4a29f4a9c..f699bc5c3 100644 --- a/Adjust/AIEvent.m +++ b/Adjust/ADJEvent.m @@ -1,16 +1,16 @@ // -// AITrackOption.m +// ADJEvent.m // adjust // // Created by Pedro Filipe on 15/10/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIEvent.h" +#import "ADJEvent.h" #pragma mark - -@implementation AIEvent +@implementation ADJEvent - (id) initWithEventToken:(NSString *)eventToken { self = [super init]; @@ -50,7 +50,7 @@ - (void) setTransactionId:(NSString *)transactionId { -(id)copyWithZone:(NSZone *)zone { - AIEvent* copy = [[[self class] allocWithZone:zone] init]; + ADJEvent* copy = [[[self class] allocWithZone:zone] init]; if (copy) { copy.eventToken = [self.eventToken copyWithZone:zone]; copy.revenue = [self.revenue copyWithZone:zone]; diff --git a/Adjust/AILogger.h b/Adjust/ADJLogger.h similarity index 57% rename from Adjust/AILogger.h rename to Adjust/ADJLogger.h index 6ad221b04..ea003c724 100644 --- a/Adjust/AILogger.h +++ b/Adjust/ADJLogger.h @@ -1,5 +1,5 @@ // -// AILogger.h +// ADJLogger.h // Adjust // // Created by Christian Wellenbrock on 2012-11-15. @@ -8,18 +8,18 @@ #import typedef enum { - AILogLevelVerbose = 1, - AILogLevelDebug = 2, - AILogLevelInfo = 3, - AILogLevelWarn = 4, - AILogLevelError = 5, - AILogLevelAssert = 6 -} AILogLevel; + ADJLogLevelVerbose = 1, + ADJLogLevelDebug = 2, + ADJLogLevelInfo = 3, + ADJLogLevelWarn = 4, + ADJLogLevelError = 5, + ADJLogLevelAssert = 6 +} ADJLogLevel; // A simple logger with multiple log levels. -@protocol AILogger +@protocol ADJLogger -- (void)setLogLevel:(AILogLevel)logLevel; +- (void)setLogLevel:(ADJLogLevel)logLevel; - (void)verbose:(NSString *)message, ...; - (void)debug: (NSString *)message, ...; @@ -30,8 +30,8 @@ typedef enum { @end -@interface AILogger : NSObject +@interface ADJLogger : NSObject -+ (AILogLevel) LogLevelFromString: (NSString *) logLevelString; ++ (ADJLogLevel) LogLevelFromString: (NSString *) logLevelString; @end diff --git a/Adjust/AILogger.m b/Adjust/ADJLogger.m similarity index 71% rename from Adjust/AILogger.m rename to Adjust/ADJLogger.m index 4e06b632e..745e46a5b 100644 --- a/Adjust/AILogger.m +++ b/Adjust/ADJLogger.m @@ -1,61 +1,61 @@ // -// AILogger.m +// ADJLogger.m // Adjust // // Created by Christian Wellenbrock on 2012-11-15. // Copyright (c) 2012-2014 adjust GmbH. All rights reserved. // -#import "AILogger.h" +#import "ADJLogger.h" static NSString * const kLogTag = @"Adjust"; -@interface AILogger() +@interface ADJLogger() -@property (nonatomic, assign) AILogLevel loglevel; +@property (nonatomic, assign) ADJLogLevel loglevel; @end #pragma mark - -@implementation AILogger +@implementation ADJLogger -- (void)setLogLevel:(AILogLevel)logLevel { +- (void)setLogLevel:(ADJLogLevel)logLevel { self.loglevel = logLevel; } - (void)verbose:(NSString *)format, ... { - if (self.loglevel > AILogLevelVerbose) return; + if (self.loglevel > ADJLogLevelVerbose) return; va_list parameters; va_start(parameters, format); [self logLevel:@"v" format:format parameters:parameters]; } - (void)debug:(NSString *)format, ... { - if (self.loglevel > AILogLevelDebug) return; + if (self.loglevel > ADJLogLevelDebug) return; va_list parameters; va_start(parameters, format); [self logLevel:@"d" format:format parameters:parameters]; } - (void)info:(NSString *)format, ... { - if (self.loglevel > AILogLevelInfo) return; + if (self.loglevel > ADJLogLevelInfo) return; va_list parameters; va_start(parameters, format); [self logLevel:@"i" format:format parameters:parameters]; } - (void)warn:(NSString *)format, ... { - if (self.loglevel > AILogLevelWarn) return; + if (self.loglevel > ADJLogLevelWarn) return; va_list parameters; va_start(parameters, format); [self logLevel:@"w" format:format parameters:parameters]; } - (void)error:(NSString *)format, ... { - if (self.loglevel > AILogLevelError) return; + if (self.loglevel > ADJLogLevelError) return; va_list parameters; va_start(parameters, format); [self logLevel:@"e" format:format parameters:parameters]; } - (void)assert:(NSString *)format, ... { - if (self.loglevel > AILogLevelAssert) return; + if (self.loglevel > ADJLogLevelAssert) return; va_list parameters; va_start(parameters, format); [self logLevel:@"a" format:format parameters:parameters]; } @@ -71,27 +71,27 @@ - (void)logLevel:(NSString *)logLevel format:(NSString *)format parameters:(va_l } } -+ (AILogLevel)LogLevelFromString:(NSString *)logLevelString { ++ (ADJLogLevel)LogLevelFromString:(NSString *)logLevelString { if ([logLevelString isEqualToString:@"verbose"]) - return AILogLevelVerbose; + return ADJLogLevelVerbose; if ([logLevelString isEqualToString:@"debug"]) - return AILogLevelDebug; + return ADJLogLevelDebug; if ([logLevelString isEqualToString:@"info"]) - return AILogLevelInfo; + return ADJLogLevelInfo; if ([logLevelString isEqualToString:@"warn"]) - return AILogLevelWarn; + return ADJLogLevelWarn; if ([logLevelString isEqualToString:@"error"]) - return AILogLevelError; + return ADJLogLevelError; if ([logLevelString isEqualToString:@"assert"]) - return AILogLevelAssert; + return ADJLogLevelAssert; // default value if string does not match - return AILogLevelInfo; + return ADJLogLevelInfo; } @end diff --git a/Adjust/ADJPackageBuilder.h b/Adjust/ADJPackageBuilder.h new file mode 100644 index 000000000..36adaf7e7 --- /dev/null +++ b/Adjust/ADJPackageBuilder.h @@ -0,0 +1,34 @@ +// +// ADJPackageBuilder.h +// Adjust +// +// Created by Christian Wellenbrock on 2013-07-03. +// Copyright (c) 2013 adjust GmbH. All rights reserved. +// +#import +#import "ADJEvent.h" +#import "ADJDeviceInfo.h" +#import "ADJActivityState.h" +#import "ADJActivityPackage.h" +#import "ADJConfig.h" + +@interface ADJPackageBuilder : NSObject + +@property (nonatomic, copy) ADJDeviceInfo* deviceInfo; +@property (nonatomic, copy) ADJEvent* event; +@property (nonatomic, copy) ADJActivityState *activityState; +@property (nonatomic, copy) ADJConfig *adjustConfig; +@property (nonatomic, assign) BOOL hasDelegate; + +// reattributions +@property (nonatomic, copy) NSDictionary* deeplinkParameters; + +- (id) initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo + andActivityState:(ADJActivityState *)activityState + andConfig:(ADJConfig *)adjustConfig; + +- (ADJActivityPackage *)buildSessionPackage; +- (ADJActivityPackage *)buildEventPackage; +- (ADJActivityPackage *)buildClickPackage; + +@end diff --git a/Adjust/AIPackageBuilder.m b/Adjust/ADJPackageBuilder.m similarity index 86% rename from Adjust/AIPackageBuilder.m rename to Adjust/ADJPackageBuilder.m index 0df45f1aa..deb2bd9c7 100644 --- a/Adjust/AIPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -1,21 +1,21 @@ // -// AIPackageBuilder.m +// ADJPackageBuilder.m // Adjust // // Created by Christian Wellenbrock on 2013-07-03. // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AIPackageBuilder.h" -#import "AIActivityPackage.h" -#import "AIUtil.h" +#import "ADJPackageBuilder.h" +#import "ADJActivityPackage.h" +#import "ADJUtil.h" #pragma mark - -@implementation AIPackageBuilder +@implementation ADJPackageBuilder -- (id)initWithDeviceInfo:(AIDeviceInfo *)deviceInfo - andActivityState:(AIActivityState *)activityState - andConfig:(AdjustConfig *)adjustConfig +- (id)initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo + andActivityState:(ADJActivityState *)activityState + andConfig:(ADJConfig *)adjustConfig { self = [super init]; if (self == nil) return nil; @@ -33,22 +33,22 @@ - (id)initWithDeviceInfo:(AIDeviceInfo *)deviceInfo return self; } -- (AIActivityPackage *)buildSessionPackage { +- (ADJActivityPackage *)buildSessionPackage { NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"callback_params"]; [self parameters:parameters setDictionaryJson:self.adjustConfig.callbackPermanentParameters forKey:@"callback_params"]; [self parameters:parameters setDictionaryJson:self.adjustConfig.partnerPermanentParameters forKey:@"partner_params"]; - AIActivityPackage *sessionPackage = [self defaultActivityPackage]; + ADJActivityPackage *sessionPackage = [self defaultActivityPackage]; sessionPackage.path = @"/session"; - sessionPackage.activityKind = AIActivityKindSession; + sessionPackage.activityKind = ADJActivityKindSession; sessionPackage.suffix = @""; sessionPackage.parameters = parameters; return sessionPackage; } -- (AIActivityPackage *)buildEventPackage { +- (ADJActivityPackage *)buildEventPackage { NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setInt:self.activityState.eventCount forKey:@"event_count"]; [self parameters:parameters setString:self.amountString forKey:@"amount"]; @@ -62,23 +62,23 @@ - (AIActivityPackage *)buildEventPackage { NSMutableDictionary * partnerParamters = [self joinParamters:self.adjustConfig.partnerPermanentParameters parameters:self.event.partnerParameters]; [self parameters:parameters setDictionaryJson:partnerParamters forKey:@"partner_params"]; - AIActivityPackage *eventPackage = [self defaultActivityPackage]; + ADJActivityPackage *eventPackage = [self defaultActivityPackage]; eventPackage.path = @"/event"; - eventPackage.activityKind = AIActivityKindEvent; + eventPackage.activityKind = ADJActivityKindEvent; eventPackage.suffix = self.eventSuffix; eventPackage.parameters = parameters; return eventPackage; } -- (AIActivityPackage *)buildClickPackage { +- (ADJActivityPackage *)buildClickPackage { NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"deeplink_params"]; [self parameters:parameters setBool:self.deviceInfo.isIad forKey:@"is_iad"]; - AIActivityPackage *reattributionPackage = [self defaultActivityPackage]; + ADJActivityPackage *reattributionPackage = [self defaultActivityPackage]; reattributionPackage.path = @"/reattribute"; - reattributionPackage.activityKind = AIActivityKindReattribution; + reattributionPackage.activityKind = ADJActivityKindReattribution; reattributionPackage.suffix = @""; reattributionPackage.parameters = parameters; @@ -86,8 +86,8 @@ - (AIActivityPackage *)buildClickPackage { } #pragma mark private -- (AIActivityPackage *)defaultActivityPackage { - AIActivityPackage *activityPackage = [[AIActivityPackage alloc] init]; +- (ADJActivityPackage *)defaultActivityPackage { + ADJActivityPackage *activityPackage = [[ADJActivityPackage alloc] init]; activityPackage.clientSdk = self.deviceInfo.clientSdk; return activityPackage; } @@ -102,9 +102,9 @@ - (NSMutableDictionary *)defaultParameters { return parameters; } -- (void) constructDeviceInfo:(AIDeviceInfo *)deviceInfo +- (void) constructDeviceInfo:(ADJDeviceInfo *)deviceInfo withParameter:(NSMutableDictionary *) parameters - andConfig:(AdjustConfig*) adjustConfig{ + andConfig:(ADJConfig*) adjustConfig{ [self constructUserAgent:deviceInfo.userAgent withParameters:parameters]; @@ -123,7 +123,7 @@ - (void) constructDeviceInfo:(AIDeviceInfo *)deviceInfo [self parameters:parameters setString:adjustConfig.environment forKey:@"environment"]; } -- (void) constructActivityState:(AIActivityState *)activityState +- (void) constructActivityState:(ADJActivityState *)activityState withParamters:(NSMutableDictionary *)parameters { [self parameters:parameters setDate:activityState.createdAt forKey:@"created_at"]; [self parameters:parameters setInt:activityState.sessionCount forKey:@"session_count"]; @@ -134,7 +134,7 @@ - (void) constructActivityState:(AIActivityState *)activityState } -- (void) constructUserAgent:(AIUserAgent *)userAgent +- (void) constructUserAgent:(ADJUserAgent *)userAgent withParameters:(NSMutableDictionary *) parameters { [self parameters:parameters setString:userAgent.bundeIdentifier forKey:@"bundle_identifier"]; [self parameters:parameters setString:userAgent.bundleVersion forKey:@"bundle_version"]; @@ -182,7 +182,7 @@ - (void)parameters:(NSMutableDictionary *)parameters setInt:(int)value forKey:(N - (void)parameters:(NSMutableDictionary *)parameters setDate:(double)value forKey:(NSString *)key { if (value < 0) return; - NSString *dateString = [AIUtil dateFormat:value]; + NSString *dateString = [ADJUtil dateFormat:value]; [self parameters:parameters setString:dateString forKey:key]; } diff --git a/Adjust/ADJPackageHandler.h b/Adjust/ADJPackageHandler.h new file mode 100644 index 000000000..35b5f47ea --- /dev/null +++ b/Adjust/ADJPackageHandler.h @@ -0,0 +1,33 @@ +// +// ADJPackageHandler.h +// Adjust +// +// Created by Christian Wellenbrock on 2013-07-03. +// Copyright (c) 2013 adjust GmbH. All rights reserved. +// +#import + +#import "ADJActivityPackage.h" +#import "ADJPackageHandler.h" +#import "ADJActivityHandler.h" + +@protocol ADJPackageHandler + +- (id)initWithActivityHandler:(id)activityHandler; + +- (void)addPackage:(ADJActivityPackage *)package; +- (void)sendFirstPackage; +- (void)sendNextPackage; +- (void)closeFirstPackage; +- (void)pauseSending; +- (void)resumeSending; +- (void)finishedTrackingActivity:(NSDictionary *)jsonDict; +- (void)sendClickPackage:(ADJActivityPackage *) clickPackage; + +@end + +@interface ADJPackageHandler : NSObject + ++ (id)handlerWithActivityHandler:(id)activityHandler; + +@end diff --git a/Adjust/AIPackageHandler.m b/Adjust/ADJPackageHandler.m similarity index 77% rename from Adjust/AIPackageHandler.m rename to Adjust/ADJPackageHandler.m index 617119c97..f05c79b95 100644 --- a/Adjust/AIPackageHandler.m +++ b/Adjust/ADJPackageHandler.m @@ -1,31 +1,29 @@ // -// AIPackageHandler.m +// ADJPackageHandler.m // Adjust // // Created by Christian Wellenbrock on 2013-07-03. // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AIPackageHandler.h" -#import "AIActivityHandler.h" -#import "AIRequestHandler.h" -#import "AIActivityPackage.h" -#import "AILogger.h" -#import "AIUtil.h" -#import "AIAdjustFactory.h" +#import "ADJRequestHandler.h" +#import "ADJActivityPackage.h" +#import "ADJLogger.h" +#import "ADJUtil.h" +#import "ADJAdjustFactory.h" static NSString * const kPackageQueueFilename = @"AdjustIoPackageQueue"; static const char * const kInternalQueueName = "io.adjust.PackageQueue"; #pragma mark - private -@interface AIPackageHandler() +@interface ADJPackageHandler() @property (nonatomic) dispatch_queue_t internalQueue; @property (nonatomic) dispatch_semaphore_t sendingSemaphore; -@property (nonatomic, assign) id activityHandler; -@property (nonatomic, retain) id requestHandler; -@property (nonatomic, retain) id logger; +@property (nonatomic, assign) id activityHandler; +@property (nonatomic, retain) id requestHandler; +@property (nonatomic, retain) id logger; @property (nonatomic, retain) NSMutableArray *packageQueue; @property (nonatomic, assign, getter = isPaused) BOOL paused; @@ -33,13 +31,13 @@ @interface AIPackageHandler() #pragma mark - -@implementation AIPackageHandler +@implementation ADJPackageHandler -+ (id)handlerWithActivityHandler:(id)activityHandler { - return [[AIPackageHandler alloc] initWithActivityHandler:activityHandler]; ++ (id)handlerWithActivityHandler:(id)activityHandler { + return [[ADJPackageHandler alloc] initWithActivityHandler:activityHandler]; } -- (id)initWithActivityHandler:(id)activityHandler { +- (id)initWithActivityHandler:(id)activityHandler { self = [super init]; if (self == nil) return nil; @@ -53,7 +51,7 @@ - (id)initWithActivityHandler:(id)activityHandler { return self; } -- (void)addPackage:(AIActivityPackage *)package { +- (void)addPackage:(ADJActivityPackage *)package { dispatch_async(self.internalQueue, ^{ [self addInternal:package]; }); @@ -87,19 +85,19 @@ - (void)finishedTrackingActivity:(NSDictionary *)jsonDict{ [self.activityHandler finishedTrackingWithResponse:jsonDict]; } -- (void)sendClickPackage:(AIActivityPackage *)clickPackage { +- (void)sendClickPackage:(ADJActivityPackage *)clickPackage { [self.requestHandler sendClickPackage:clickPackage]; } #pragma mark - internal - (void)initInternal { - self.requestHandler = [AIAdjustFactory requestHandlerForPackageHandler:self]; - self.logger = AIAdjustFactory.logger; + self.requestHandler = [ADJAdjustFactory requestHandlerForPackageHandler:self]; + self.logger = ADJAdjustFactory.logger; self.sendingSemaphore = dispatch_semaphore_create(1); [self readPackageQueue]; } -- (void)addInternal:(AIActivityPackage *)newPackage { +- (void)addInternal:(ADJActivityPackage *)newPackage { [self.packageQueue addObject:newPackage]; [self.logger debug:@"Added package %d (%@)", self.packageQueue.count, newPackage]; [self.logger verbose:@"%@", newPackage.extendedString]; @@ -120,8 +118,8 @@ - (void)sendFirstInternal { return; } - AIActivityPackage *activityPackage = [self.packageQueue objectAtIndex:0]; - if (![activityPackage isKindOfClass:[AIActivityPackage class]]) { + ADJActivityPackage *activityPackage = [self.packageQueue objectAtIndex:0]; + if (![activityPackage isKindOfClass:[ADJActivityPackage class]]) { [self.logger error:@"Failed to read activity package"]; [self sendNextInternal]; return; @@ -163,7 +161,7 @@ - (void)writePackageQueue { NSString *filename = self.packageQueueFilename; BOOL result = [NSKeyedArchiver archiveRootObject:self.packageQueue toFile:filename]; if (result == YES) { - [AIUtil excludeFromBackup:filename]; + [ADJUtil excludeFromBackup:filename]; [self.logger debug:@"Package handler wrote %d packages", self.packageQueue.count]; } else { [self.logger error:@"Failed to write package queue"]; diff --git a/Adjust/ADJRequestHandler.h b/Adjust/ADJRequestHandler.h new file mode 100644 index 000000000..b28cc928f --- /dev/null +++ b/Adjust/ADJRequestHandler.h @@ -0,0 +1,27 @@ +// +// ADJRequestHandler.h +// Adjust +// +// Created by Christian Wellenbrock on 2013-07-04. +// Copyright (c) 2013 adjust GmbH. All rights reserved. +// +#import + +#import "ADJRequestHandler.h" +#import "ADJPackageHandler.h" + +@protocol ADJRequestHandler + +- (id)initWithPackageHandler:(id) packageHandler; + +- (void)sendPackage:(ADJActivityPackage *)activityPackage; + +- (void)sendClickPackage:(ADJActivityPackage *)clickPackage; +@end + + +@interface ADJRequestHandler : NSObject + ++ (id) handlerWithPackageHandler:(id)packageHandler; + +@end diff --git a/Adjust/AIRequestHandler.m b/Adjust/ADJRequestHandler.m similarity index 78% rename from Adjust/AIRequestHandler.m rename to Adjust/ADJRequestHandler.m index 3850e491c..4819dacf5 100644 --- a/Adjust/AIRequestHandler.m +++ b/Adjust/ADJRequestHandler.m @@ -1,58 +1,58 @@ // -// AIRequestHandler.m +// ADJRequestHandler.m // Adjust // // Created by Christian Wellenbrock on 2013-07-04. // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AIActivityPackage.h" -#import "AILogger.h" -#import "AIUtil.h" -#import "NSString+AIAdditions.h" -#import "AIAdjustFactory.h" +#import "ADJActivityPackage.h" +#import "ADJLogger.h" +#import "ADJUtil.h" +#import "NSString+ADJAdditions.h" +#import "ADJAdjustFactory.h" static const char * const kInternalQueueName = "io.adjust.RequestQueue"; static const double kRequestTimeout = 60; // 60 seconds #pragma mark - private -@interface AIRequestHandler() +@interface ADJRequestHandler() @property (nonatomic) dispatch_queue_t internalQueue; -@property (nonatomic, assign) id packageHandler; -@property (nonatomic, assign) id logger; +@property (nonatomic, assign) id packageHandler; +@property (nonatomic, assign) id logger; @property (nonatomic, retain) NSURL *baseUrl; @end #pragma mark - -@implementation AIRequestHandler +@implementation ADJRequestHandler -+ (AIRequestHandler *)handlerWithPackageHandler:(id)packageHandler { - return [[AIRequestHandler alloc] initWithPackageHandler:packageHandler]; ++ (ADJRequestHandler *)handlerWithPackageHandler:(id)packageHandler { + return [[ADJRequestHandler alloc] initWithPackageHandler:packageHandler]; } -- (id)initWithPackageHandler:(id) packageHandler { +- (id)initWithPackageHandler:(id) packageHandler { self = [super init]; if (self == nil) return nil; self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); self.packageHandler = packageHandler; - self.logger = AIAdjustFactory.logger; - self.baseUrl = [NSURL URLWithString:AIUtil.baseUrl]; + self.logger = ADJAdjustFactory.logger; + self.baseUrl = [NSURL URLWithString:ADJUtil.baseUrl]; return self; } -- (void)sendPackage:(AIActivityPackage *)activityPackage { +- (void)sendPackage:(ADJActivityPackage *)activityPackage { dispatch_async(self.internalQueue, ^{ [self sendInternal:activityPackage sendToPackageHandler:YES]; }); } -- (void)sendClickPackage:(AIActivityPackage *)clickPackage { +- (void)sendClickPackage:(ADJActivityPackage *)clickPackage { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ [self sendInternal:clickPackage sendToPackageHandler:NO]; }); @@ -60,7 +60,7 @@ - (void)sendClickPackage:(AIActivityPackage *)clickPackage { #pragma mark - internal -- (void)sendInternal:(AIActivityPackage *)package sendToPackageHandler:(BOOL)sendToPackageHandler{ +- (void)sendInternal:(ADJActivityPackage *)package sendToPackageHandler:(BOOL)sendToPackageHandler{ if (self.packageHandler == nil) return; NSMutableURLRequest *request = [self requestForPackage:package]; @@ -83,7 +83,7 @@ - (void)sendInternal:(AIActivityPackage *)package sendToPackageHandler:(BOOL)sen NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; [self.logger verbose:@"package response: %@", responseString]; - NSDictionary *jsonDict = [AIUtil buildJsonDict:responseString]; + NSDictionary *jsonDict = [ADJUtil buildJsonDict:responseString]; NSString* messageResponse = [jsonDict objectForKey:@"message"]; NSInteger statusCode = response.statusCode; @@ -101,7 +101,7 @@ - (void)sendInternal:(AIActivityPackage *)package sendToPackageHandler:(BOOL)sen } #pragma mark - private -- (NSMutableURLRequest *)requestForPackage:(AIActivityPackage *)package { +- (NSMutableURLRequest *)requestForPackage:(ADJActivityPackage *)package { NSURL *url = [NSURL URLWithString:package.path relativeToURL:self.baseUrl]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; request.timeoutInterval = kRequestTimeout; @@ -124,7 +124,7 @@ - (NSData *)bodyForParameters:(NSDictionary *)parameters { } double now = [NSDate.date timeIntervalSince1970]; - NSString *dateString = [AIUtil dateFormat:now]; + NSString *dateString = [ADJUtil dateFormat:now]; NSString *escapedDate = [dateString aiUrlEncode]; NSString *sentAtPair = [NSString stringWithFormat:@"%@=%@", @"sent_at", escapedDate]; [pairs addObject:sentAtPair]; diff --git a/Adjust/AITimer.h b/Adjust/ADJTimer.h similarity index 85% rename from Adjust/AITimer.h rename to Adjust/ADJTimer.h index 104dd0597..d96976bab 100644 --- a/Adjust/AITimer.h +++ b/Adjust/ADJTimer.h @@ -1,5 +1,5 @@ // -// AITimer.h +// ADJTimer.h // Adjust // // Created by Christian Wellenbrock on 2013-07-02. @@ -7,14 +7,14 @@ // #import -@interface AITimer : NSObject +@interface ADJTimer : NSObject -+ (AITimer *)timerWithInterval:(uint64_t)interval ++ (ADJTimer *)timerWithInterval:(uint64_t)interval leeway:(uint64_t)leeway queue:(dispatch_queue_t)queue block:(dispatch_block_t)block; -+ (AITimer *)timerWithStart:(uint64_t)start ++ (ADJTimer *)timerWithStart:(uint64_t)start leeway:(uint64_t)leeway queue:(dispatch_queue_t)queue block:(dispatch_block_t)block; diff --git a/Adjust/AITimer.m b/Adjust/ADJTimer.m similarity index 79% rename from Adjust/AITimer.m rename to Adjust/ADJTimer.m index bfe19587a..e63777da6 100644 --- a/Adjust/AITimer.m +++ b/Adjust/ADJTimer.m @@ -1,15 +1,15 @@ // -// AITimer.m +// ADJTimer.m // Adjust // // Created by Christian Wellenbrock on 2013-07-02. // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AITimer.h" +#import "ADJTimer.h" #pragma mark - private -@interface AITimer() +@interface ADJTimer() @property (nonatomic) dispatch_source_t source; @property (nonatomic, assign) BOOL suspended; @@ -18,19 +18,19 @@ @interface AITimer() #pragma mark - -@implementation AITimer +@implementation ADJTimer -+ (AITimer *)timerWithInterval:(uint64_t)interval ++ (ADJTimer *)timerWithInterval:(uint64_t)interval leeway:(uint64_t)leeway queue:(dispatch_queue_t)queue block:(dispatch_block_t)block { - return [[AITimer alloc] initWithInterval:interval leeway:leeway queue:queue block:block]; + return [[ADJTimer alloc] initWithInterval:interval leeway:leeway queue:queue block:block]; } -+ (AITimer *)timerWithStart:(uint64_t)start leeway:(uint64_t)leeway queue:(dispatch_queue_t)queue block:(dispatch_block_t)block ++ (ADJTimer *)timerWithStart:(uint64_t)start leeway:(uint64_t)leeway queue:(dispatch_queue_t)queue block:(dispatch_block_t)block { - return [[AITimer alloc] initWithStart:start leeway:leeway queue:queue block:block]; + return [[ADJTimer alloc] initWithStart:start leeway:leeway queue:queue block:block]; } - (id)initWithInterval:(uint64_t)interval diff --git a/Adjust/AIUserAgent.h b/Adjust/ADJUserAgent.h similarity index 89% rename from Adjust/AIUserAgent.h rename to Adjust/ADJUserAgent.h index 374b2a246..5e58646a1 100644 --- a/Adjust/AIUserAgent.h +++ b/Adjust/ADJUserAgent.h @@ -1,5 +1,5 @@ // -// AIUserAgent.h +// ADJUserAgent.h // adjust // // Created by Pedro Filipe on 28/10/14. @@ -8,7 +8,7 @@ #import -@interface AIUserAgent : NSObject +@interface ADJUserAgent : NSObject @property (nonatomic, copy) NSString *bundeIdentifier; @property (nonatomic, copy) NSString *bundleVersion; diff --git a/Adjust/AIUserAgent.m b/Adjust/ADJUserAgent.m similarity index 83% rename from Adjust/AIUserAgent.m rename to Adjust/ADJUserAgent.m index 15d7433bc..e00e25b1a 100644 --- a/Adjust/AIUserAgent.m +++ b/Adjust/ADJUserAgent.m @@ -1,18 +1,18 @@ // -// AIUserAgent.m +// ADJUserAgent.m // adjust // // Created by Pedro Filipe on 28/10/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIUserAgent.h" +#import "ADJUserAgent.h" -@implementation AIUserAgent +@implementation ADJUserAgent -(id)copyWithZone:(NSZone *)zone { - AIUserAgent * copy = [[[self class] allocWithZone:zone] init]; + ADJUserAgent * copy = [[[self class] allocWithZone:zone] init]; if (copy) { copy.bundeIdentifier = [self.bundeIdentifier copyWithZone:zone]; copy.bundleVersion = [self.bundleVersion copyWithZone:zone]; diff --git a/Adjust/AIUtil.h b/Adjust/ADJUtil.h similarity index 86% rename from Adjust/AIUtil.h rename to Adjust/ADJUtil.h index cfd0a65b4..c80fdee83 100644 --- a/Adjust/AIUtil.h +++ b/Adjust/ADJUtil.h @@ -1,18 +1,18 @@ // -// AIUtil.h +// ADJUtil.h // Adjust // // Created by Christian Wellenbrock on 2013-07-05. // Copyright (c) 2013 adjust GmbH. All rights reserved. // #import -#import "AIUserAgent.h" +#import "ADJUserAgent.h" -@interface AIUtil : NSObject +@interface ADJUtil : NSObject + (NSString *)baseUrl; + (NSString *)clientSdk; -+ (AIUserAgent *)userAgent; ++ (ADJUserAgent *)userAgent; + (void)excludeFromBackup:(NSString *)filename; + (NSString *)dateFormat:(double)value; diff --git a/Adjust/AIUtil.m b/Adjust/ADJUtil.m similarity index 88% rename from Adjust/AIUtil.m rename to Adjust/ADJUtil.m index 18a644e97..c40ec122a 100644 --- a/Adjust/AIUtil.m +++ b/Adjust/ADJUtil.m @@ -1,16 +1,16 @@ // -// AIUtil.m +// ADJUtil.m // Adjust // // Created by Christian Wellenbrock on 2013-07-05. // Copyright (c) 2013 adjust GmbH. All rights reserved. // -#import "AIUtil.h" -#import "AILogger.h" -#import "UIDevice+AIAdditions.h" -#import "AIAdjustFactory.h" -#import "NSString+AIAdditions.h" +#import "ADJUtil.h" +#import "ADJLogger.h" +#import "UIDevice+ADJAdditions.h" +#import "ADJAdjustFactory.h" +#import "NSString+ADJAdditions.h" #include @@ -22,7 +22,7 @@ #pragma mark - -@implementation AIUtil +@implementation ADJUtil + (NSString *)baseUrl { return kBaseUrl; @@ -32,9 +32,9 @@ + (NSString *)clientSdk { return kClientSdk; } -+ (AIUserAgent *)userAgent { ++ (ADJUserAgent *)userAgent { - AIUserAgent * userAgent = [[AIUserAgent alloc] init]; + ADJUserAgent * userAgent = [[ADJUserAgent alloc] init]; UIDevice *device = UIDevice.currentDevice; NSLocale *locale = NSLocale.currentLocale; @@ -81,7 +81,7 @@ + (void)excludeFromBackup:(NSString *)path { NSURL *url = [NSURL fileURLWithPath:path]; const char* filePath = [[url path] fileSystemRepresentation]; const char* attrName = "com.apple.MobileBackup"; - id logger = AIAdjustFactory.logger; + id logger = ADJAdjustFactory.logger; if (&NSURLIsExcludedFromBackupKey == nil) { // iOS 5.0.1 and lower u_int8_t attrValue = 1; @@ -143,11 +143,11 @@ + (NSString *)getFullFilename:(NSString *) baseFilename { + (id)readObject:(NSString *)filename objectName:(NSString *)objectName{ - id logger = [AIAdjustFactory logger]; + id logger = [ADJAdjustFactory logger]; @try { - NSString *fullFilename = [AIUtil getFullFilename:filename]; + NSString *fullFilename = [ADJUtil getFullFilename:filename]; id object = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFilename]; - if ([object isKindOfClass:[AIAttribution class]]) { + if ([object isKindOfClass:[ADJAttribution class]]) { [logger debug:@"Read %@: %@", objectName, object]; return object; } else if (object == nil) { @@ -165,11 +165,11 @@ + (id)readObject:(NSString *)filename + (void)writeObject:(id)object filename:(NSString *)filename objectName:(NSString *)objectName { - id logger = [AIAdjustFactory logger]; - NSString *fullFilename = [AIUtil getFullFilename:filename]; + id logger = [ADJAdjustFactory logger]; + NSString *fullFilename = [ADJUtil getFullFilename:filename]; BOOL result = [NSKeyedArchiver archiveRootObject:object toFile:fullFilename]; if (result == YES) { - [AIUtil excludeFromBackup:fullFilename]; + [ADJUtil excludeFromBackup:fullFilename]; [logger debug:@"Wrote %@: %@", objectName, object]; } else { [logger error:@"Failed to write %@ file", objectName]; diff --git a/Adjust/AIActivityKind.h b/Adjust/AIActivityKind.h deleted file mode 100644 index 756f7066c..000000000 --- a/Adjust/AIActivityKind.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// AIActivityKind.h -// Adjust -// -// Created by Christian Wellenbrock on 11.02.14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// - -#import - -typedef enum { - AIActivityKindUnknown = 0, - AIActivityKindSession = 1, - AIActivityKindEvent = 2, - AIActivityKindRevenue = 3, - AIActivityKindReattribution = 4, -} AIActivityKind; - -AIActivityKind AIActivityKindFromString(NSString *string); -NSString* AIActivityKindToString(AIActivityKind activityKind); diff --git a/Adjust/AIActivityKind.m b/Adjust/AIActivityKind.m deleted file mode 100644 index 5c3f1fee3..000000000 --- a/Adjust/AIActivityKind.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// AIActivityKind.m -// Adjust -// -// Created by Christian Wellenbrock on 11.02.14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// - -#import "AIActivityKind.h" - -AIActivityKind AIActivityKindFromString(NSString *string) { - if ([@"session" isEqualToString:string]) { - return AIActivityKindSession; - } else if ([@"event" isEqualToString:string]) { - return AIActivityKindEvent; - } else if ([@"revenue" isEqualToString:string]) { - return AIActivityKindRevenue; - } else if ([@"reattribution" isEqualToString:string]) { - return AIActivityKindReattribution; - } else { - return AIActivityKindUnknown; - } -} - -NSString* AIActivityKindToString(AIActivityKind activityKind) { - switch (activityKind) { - case AIActivityKindSession: return @"session"; - case AIActivityKindEvent: return @"event"; - case AIActivityKindRevenue: return @"revenue"; - case AIActivityKindReattribution: return @"reattribution"; - case AIActivityKindUnknown: return @"unknown"; - } -} diff --git a/Adjust/AIAdjustFactory.h b/Adjust/AIAdjustFactory.h deleted file mode 100644 index 139f0d80a..000000000 --- a/Adjust/AIAdjustFactory.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// AIAdjustFactory.h -// Adjust -// -// Created by Pedro Filipe on 07/02/14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// -#import - -#import "AIActivityHandler.h" -#import "AIPackageHandler.h" -#import "AIRequestHandler.h" -#import "AILogger.h" -#import "AIAttributionHandler.h" - -@interface AIAdjustFactory : NSObject - -+ (id)packageHandlerForActivityHandler:(id)activityHandler; -+ (id)requestHandlerForPackageHandler:(id)packageHandler; -+ (id)activityHandlerWithConfig:(AdjustConfig *)adjustConfig; -+ (id)logger; -+ (double)sessionInterval; -+ (double)subsessionInterval; -+ (id)attributionHandlerForActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds; - -+ (void)setPackageHandler:(id)packageHandler; -+ (void)setRequestHandler:(id)requestHandler; -+ (void)setActivityHandler:(id)activityHandler; -+ (void)setLogger:(id)logger; -+ (void)setSessionInterval:(double)sessionInterval; -+ (void)setSubsessionInterval:(double)subsessionInterval; -+ (void)setAttributionHandler:(id)attributionHandler; - -@end diff --git a/Adjust/AIAttributionHandler.h b/Adjust/AIAttributionHandler.h deleted file mode 100644 index 784f53abd..000000000 --- a/Adjust/AIAttributionHandler.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// AIAttributionHandler.h -// adjust -// -// Created by Pedro Filipe on 29/10/14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// - -#import -#import "AIActivityHandler.h" - -@protocol AIAttributionHandler - -- (id)initWithActivityHandler:(id) activityHandler withMaxDelay:(NSNumber* )milliseconds; - -- (void)checkAttribution:(NSDictionary *)jsonDict; - -- (void)getAttribution; - -@end - -@interface AIAttributionHandler : NSObject - -+ (id)handlerWithActivityHandler:(id)activityHandler - withMaxDelay:(NSNumber* )milliseconds; - -@end diff --git a/Adjust/AIPackageBuilder.h b/Adjust/AIPackageBuilder.h deleted file mode 100644 index e20710685..000000000 --- a/Adjust/AIPackageBuilder.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// AIPackageBuilder.h -// Adjust -// -// Created by Christian Wellenbrock on 2013-07-03. -// Copyright (c) 2013 adjust GmbH. All rights reserved. -// -#import -#import "AIEvent.h" -#import "AIDeviceInfo.h" -#import "AIActivityState.h" -#import "AIActivityPackage.h" -#import "AdjustConfig.h" - -@interface AIPackageBuilder : NSObject - -@property (nonatomic, copy) AIDeviceInfo* deviceInfo; -@property (nonatomic, copy) AIEvent* event; -@property (nonatomic, copy) AIActivityState *activityState; -@property (nonatomic, copy) AdjustConfig *adjustConfig; -@property (nonatomic, assign) BOOL hasDelegate; - -// reattributions -@property (nonatomic, copy) NSDictionary* deeplinkParameters; - -- (id) initWithDeviceInfo:(AIDeviceInfo *)deviceInfo - andActivityState:(AIActivityState *)activityState - andConfig:(AdjustConfig *)adjustConfig; - -- (AIActivityPackage *)buildSessionPackage; -- (AIActivityPackage *)buildEventPackage; -- (AIActivityPackage *)buildClickPackage; - -@end diff --git a/Adjust/AIPackageHandler.h b/Adjust/AIPackageHandler.h deleted file mode 100644 index aad5ba4f6..000000000 --- a/Adjust/AIPackageHandler.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// AIPackageHandler.h -// Adjust -// -// Created by Christian Wellenbrock on 2013-07-03. -// Copyright (c) 2013 adjust GmbH. All rights reserved. -// -#import - -@class AIActivityPackage; -@class AIResponseData; -@protocol AIActivityHandler; - -@protocol AIPackageHandler - -- (id)initWithActivityHandler:(id)activityHandler; - -- (void)addPackage:(AIActivityPackage *)package; -- (void)sendFirstPackage; -- (void)sendNextPackage; -- (void)closeFirstPackage; -- (void)pauseSending; -- (void)resumeSending; -- (void)finishedTrackingActivity:(NSDictionary *)jsonDict; -- (void)sendClickPackage:(AIActivityPackage *) clickPackage; - -@end - -@interface AIPackageHandler : NSObject - -+ (id)handlerWithActivityHandler:(id)activityHandler; - -@end diff --git a/Adjust/AIRequestHandler.h b/Adjust/AIRequestHandler.h deleted file mode 100644 index 99c1e1e1a..000000000 --- a/Adjust/AIRequestHandler.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// AIRequestHandler.h -// Adjust -// -// Created by Christian Wellenbrock on 2013-07-04. -// Copyright (c) 2013 adjust GmbH. All rights reserved. -// -#import - -#import "AIRequestHandler.h" -#import "AIPackageHandler.h" - -@protocol AIRequestHandler - -- (id)initWithPackageHandler:(id) packageHandler; - -- (void)sendPackage:(AIActivityPackage *)activityPackage; - -- (void)sendClickPackage:(AIActivityPackage *)clickPackage; -@end - - -@interface AIRequestHandler : NSObject - -+ (id) handlerWithPackageHandler:(id)packageHandler; - -@end diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index 5f3a8a610..eada857ac 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -6,10 +6,10 @@ // Copyright (c) 2012-2014 adjust GmbH. All rights reserved. // -#import "AILogger.h" -#import "AIEvent.h" -#import "AIAttribution.h" -#import "AdjustConfig.h" +#import "ADJLogger.h" +#import "ADJEvent.h" +#import "ADJAttribution.h" +#import "ADJConfig.h" /** * Constants for our supported tracking environments. @@ -35,7 +35,7 @@ static NSString * const AIEnvironmentProduction = @"production"; * be found it in your dashboard at http://adjust.com and should always * be 12 characters long. */ -+ (void)appDidLaunch:(AdjustConfig *)adjustConfig; ++ (void)appDidLaunch:(ADJConfig *)adjustConfig; /** * Tell Adjust that a particular event has happened. @@ -55,7 +55,7 @@ static NSString * const AIEnvironmentProduction = @"production"; * that is created in the dashboard at http://adjust.com and should be six * characters long. */ -+ (void)trackEvent:(AIEvent *)event; ++ (void)trackEvent:(ADJEvent *)event; /** * Tell adjust that the application resumed. @@ -105,9 +105,9 @@ static NSString * const AIEnvironmentProduction = @"production"; + (id)getInstance; -- (void)appDidLaunch:(AdjustConfig *)adjustConfig; +- (void)appDidLaunch:(ADJConfig *)adjustConfig; -- (void)trackEvent:(AIEvent *)event; +- (void)trackEvent:(ADJEvent *)event; - (void)trackSubsessionStart; - (void)trackSubsessionEnd; - (void)setEnabled:(BOOL)enabled; diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index e3368827a..7a37acc6a 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -7,9 +7,9 @@ // #import "Adjust.h" -#import "AIActivityHandler.h" -#import "AIAdjustFactory.h" -#import "AILogger.h" +#import "ADJActivityHandler.h" +#import "ADJAdjustFactory.h" +#import "ADJLogger.h" #if !__has_feature(objc_arc) #error Adjust requires ARC @@ -17,19 +17,19 @@ #endif @interface Adjust() -@property (nonatomic, retain) id activityHandler; -@property (nonatomic, retain) id logger; +@property (nonatomic, retain) id activityHandler; +@property (nonatomic, retain) id logger; @end #pragma mark - @implementation Adjust -+ (void)appDidLaunch:(AdjustConfig *)adjustConfig { ++ (void)appDidLaunch:(ADJConfig *)adjustConfig { Adjust * defaultInstance = [Adjust getInstance]; [defaultInstance appDidLaunch:adjustConfig]; } -+ (void)trackEvent:(AIEvent *)event { ++ (void)trackEvent:(ADJEvent *)event { Adjust * defaultInstance = [Adjust getInstance]; [defaultInstance trackEvent:event]; } @@ -98,21 +98,21 @@ - (id) init { if (self == nil) return nil; self.activityHandler = nil; - self.logger = [AIAdjustFactory logger]; + self.logger = [ADJAdjustFactory logger]; return self; } -- (void)appDidLaunch:(AdjustConfig *)adjustConfig { +- (void)appDidLaunch:(ADJConfig *)adjustConfig { if (self.activityHandler != nil) { [self.logger error:@"Adjust already initialized"]; return; } - self.activityHandler = [AIAdjustFactory activityHandlerWithConfig:adjustConfig]; + self.activityHandler = [ADJAdjustFactory activityHandlerWithConfig:adjustConfig]; } -- (void)trackEvent:(AIEvent *)event { +- (void)trackEvent:(ADJEvent *)event { if (![self checkActivityHandler]) return; [self.activityHandler trackEvent:event]; } diff --git a/AdjustBridge/AdjustBridge.m b/AdjustBridge/AdjustBridge.m index 32f1a3fee..b9ed19d74 100644 --- a/AdjustBridge/AdjustBridge.m +++ b/AdjustBridge/AdjustBridge.m @@ -8,7 +8,7 @@ #import "AdjustBridge.h" #import "WebViewJavascriptBridge.h" -#import "AIEvent.h" +#import "ADJEvent.h" #import "Adjust.h" static NSString * const kAdjustJsPrefix = @"adjust_"; @@ -33,7 +33,7 @@ + (void) loadBridge:(NSObject *) webViewDelegate [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@trackEvent", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { // TODO, test - AIEvent * event= [data objectForKey:@"event"]; + ADJEvent * event= [data objectForKey:@"event"]; /* NSString* eventToken = [data objectForKey:@"eventToken"]; NSDictionary* parameters = [data objectForKey:@"parameters"]; diff --git a/AdjustTests/AIActivityHandlerMock.h b/AdjustTests/AIActivityHandlerMock.h index 0db32e8bb..69bdac334 100644 --- a/AdjustTests/AIActivityHandlerMock.h +++ b/AdjustTests/AIActivityHandlerMock.h @@ -6,8 +6,8 @@ // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIActivityHandler.h" +#import "ADJActivityHandler.h" -@interface AIActivityHandlerMock : NSObject +@interface AIActivityHandlerMock : NSObject @end diff --git a/AdjustTests/AIActivityHandlerMock.m b/AdjustTests/AIActivityHandlerMock.m index efd611df1..1e27c8564 100644 --- a/AdjustTests/AIActivityHandlerMock.m +++ b/AdjustTests/AIActivityHandlerMock.m @@ -8,7 +8,7 @@ #import "AIActivityHandlerMock.h" #import "AILoggerMock.h" -#import "AIAdjustFactory.h" +#import "ADJAdjustFactory.h" static NSString * const prefix = @"AIActivityHandler "; @@ -30,7 +30,7 @@ - (id)initWithAppToken:(NSString *)yourAppToken { self = [super init]; if (self == nil) return nil; - self.loggerMock = (AILoggerMock *) [AIAdjustFactory logger]; + self.loggerMock = (AILoggerMock *) [ADJAdjustFactory logger]; [self.loggerMock test:[prefix stringByAppendingFormat:@"initWithAppToken yourAppToken:%@", yourAppToken]]; diff --git a/AdjustTests/AIActivityHandlerTests.m b/AdjustTests/AIActivityHandlerTests.m index 2d432d1d8..6ef6592f0 100644 --- a/AdjustTests/AIActivityHandlerTests.m +++ b/AdjustTests/AIActivityHandlerTests.m @@ -9,12 +9,12 @@ #import #import "AILoggerMock.h" #import "AIPackageHandlerMock.h" -#import "AIAdjustFactory.h" -#import "AIActivityHandler.h" -#import "AIActivityPackage.h" +#import "ADJAdjustFactory.h" +#import "ADJActivityHandler.h" +#import "ADJActivityPackage.h" #import "AITestsUtil.h" -#import "AIUtil.h" -#import "AILogger.h" +#import "ADJUtil.h" +#import "ADJLogger.h" @interface AIActivityHandlerTests : XCTestCase @@ -34,23 +34,23 @@ - (void)setUp - (void)tearDown { - [AIAdjustFactory setPackageHandler:nil]; - [AIAdjustFactory setLogger:nil]; - [AIAdjustFactory setSessionInterval:-1]; - [AIAdjustFactory setSubsessionInterval:-1]; + [ADJAdjustFactory setPackageHandler:nil]; + [ADJAdjustFactory setLogger:nil]; + [ADJAdjustFactory setSessionInterval:-1]; + [ADJAdjustFactory setSubsessionInterval:-1]; // Put teardown code here; it will be run once, after the last test case. [super tearDown]; } - (void)reset { self.loggerMock = [[AILoggerMock alloc] init]; - [AIAdjustFactory setLogger:self.loggerMock]; + [ADJAdjustFactory setLogger:self.loggerMock]; self.packageHandlerMock = [AIPackageHandlerMock alloc]; - [AIAdjustFactory setPackageHandler:self.packageHandlerMock]; + [ADJAdjustFactory setPackageHandler:self.packageHandlerMock]; - [AIAdjustFactory setSessionInterval:-1]; - [AIAdjustFactory setSubsessionInterval:-1]; + [ADJAdjustFactory setSessionInterval:-1]; + [ADJAdjustFactory setSubsessionInterval:-1]; } - (void)testFirstRun @@ -62,7 +62,7 @@ - (void)testFirstRun XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler and start the first session - id activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"]; + id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; // set the delegate to be called at after sending the package AITestsUtil * testsUtil = [[AITestsUtil alloc] init]; @@ -73,27 +73,27 @@ - (void)testFirstRun [NSThread sleepForTimeInterval:10.0]; // test that the file did not exist in the first run of the application - XCTAssert([self.loggerMock containsMessage:AILogLevelVerbose beginsWith:@"Activity state file not found"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelVerbose beginsWith:@"Activity state file not found"], @"%@", self.loggerMock); // when a session package is being sent the package handler should resume sending - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler resumeSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler resumeSending"], @"%@", self.loggerMock); // if the package was build, it was sent to the Package Handler - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler addPackage"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler addPackage"], @"%@", self.loggerMock); // checking the default values of the first session package // should only have one package XCTAssertEqual((NSUInteger)1, [self.packageHandlerMock.packageQueue count], @"%@", self.loggerMock); - AIActivityPackage *activityPackage = (AIActivityPackage *) self.packageHandlerMock.packageQueue[0]; + ADJActivityPackage *activityPackage = (ADJActivityPackage *) self.packageHandlerMock.packageQueue[0]; // check the Sdk version is being tested XCTAssertEqual(@"ios3.4.0", activityPackage.clientSdk, @"%@", activityPackage.extendedString); // check the server url - XCTAssertEqual(@"https://app.adjust.io", AIUtil.baseUrl); + XCTAssertEqual(@"https://app.adjust.io", ADJUtil.baseUrl); // packageType should be SESSION_START XCTAssertEqual(@"/startup", activityPackage.path, @"%@", activityPackage.extendedString); @@ -124,18 +124,18 @@ - (void)testFirstRun XCTAssertNotNil((NSString *)parameters[@"idfv"], @"%@", activityPackage.extendedString); // after adding, the activity handler ping the Package handler to send the package - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // check that the package handler calls back with the delegate - //XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AdjustDelegate adjustFinishedTrackingWithResponse"], + //XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AdjustDelegate adjustFinishedTrackingWithResponse"], // @"%@", self.loggerMock); // check that the activity state is written by the first session or timer - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Wrote activity state: "], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Wrote activity state: "], @"%@", self.loggerMock); // ending of first session - XCTAssert([self.loggerMock containsMessage:AILogLevelInfo beginsWith:@"First session"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelInfo beginsWith:@"First session"], @"%@", self.loggerMock); } - (void)testSessions { @@ -146,11 +146,11 @@ - (void)testSessions { XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // adjust the intervals for testing - [AIAdjustFactory setSessionInterval:(2)]; // 2 seconds - [AIAdjustFactory setSubsessionInterval:(0.1)]; // 0.1 second + [ADJAdjustFactory setSessionInterval:(2)]; // 2 seconds + [ADJAdjustFactory setSubsessionInterval:(0.1)]; // 0.1 second // create handler to start the session - id activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"]; + id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; // wait enough to be a new subsession, but not a new session [NSThread sleepForTimeInterval:1.5]; @@ -165,17 +165,17 @@ - (void)testSessions { [NSThread sleepForTimeInterval:1]; // check that a new subsession was created - XCTAssert([self.loggerMock containsMessage:AILogLevelInfo beginsWith:@"Processed Subsession 2 of Session 1"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelInfo beginsWith:@"Processed Subsession 2 of Session 1"], @"%@", self.loggerMock); // check that it's now on the 2nd session - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Session 2"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Session 2"], @"%@", self.loggerMock); // check that 2 packages were added to the package handler XCTAssertEqual((NSUInteger)2, [self.packageHandlerMock.packageQueue count], @"%@", self.loggerMock); // get the second session package and its parameters - AIActivityPackage *activityPackage = (AIActivityPackage *) self.packageHandlerMock.packageQueue[1]; + ADJActivityPackage *activityPackage = (ADJActivityPackage *) self.packageHandlerMock.packageQueue[1]; NSDictionary *parameters = activityPackage.parameters; // the session and subsession count should be 2 @@ -186,7 +186,7 @@ - (void)testSessions { XCTAssertEqual(2, [(NSString *)parameters[@"subsession_count"] intValue], @"%@", activityPackage.extendedString); // check that the package handler was paused - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler pauseSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler pauseSending"], @"%@", self.loggerMock); } @@ -198,7 +198,7 @@ - (void)testEventsBuffered { XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session - id activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"]; + id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; [activityHandler setBufferEvents:YES]; [activityHandler setDeviceToken:nil]; @@ -213,13 +213,13 @@ - (void)testEventsBuffered { [NSThread sleepForTimeInterval:2]; // check that event buffering is enabled - //XCTAssert([self.loggerMock containsMessage:AILogLevelInfo beginsWith:@"Event buffering is enabled"], @"%@", self.loggerMock); + //XCTAssert([self.loggerMock containsMessage:ADJLogLevelInfo beginsWith:@"Event buffering is enabled"], @"%@", self.loggerMock); // check that the package builder added the session, event and revenue package XCTAssertEqual((NSUInteger)3, [self.packageHandlerMock.packageQueue count], @"%@", self.loggerMock); // check the first event - AIActivityPackage *eventPackage = (AIActivityPackage *) self.packageHandlerMock.packageQueue[1]; + ADJActivityPackage *eventPackage = (ADJActivityPackage *) self.packageHandlerMock.packageQueue[1]; // check the event path XCTAssert([eventPackage.path isEqualToString:@"/event"], @"%@", eventPackage.extendedString); @@ -242,17 +242,17 @@ - (void)testEventsBuffered { XCTAssertNil(eventPackageParameters[@"push_token"], @"%@", eventPackage.extendedString); // check that the event was buffered - XCTAssert([self.loggerMock containsMessage:AILogLevelInfo beginsWith:@"Buffered event 'abc123'"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelInfo beginsWith:@"Buffered event 'abc123'"], @"%@", self.loggerMock); // check the event count in the written activity state - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Wrote activity state: ec:1"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Wrote activity state: ec:1"], @"%@", self.loggerMock); // check the event count in the logger - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Event 1"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 1"], @"%@", self.loggerMock); // check the second event/ first revenue - AIActivityPackage *revenuePackage = (AIActivityPackage *) self.packageHandlerMock.packageQueue[2]; + ADJActivityPackage *revenuePackage = (ADJActivityPackage *) self.packageHandlerMock.packageQueue[2]; // check the revenue path XCTAssert([revenuePackage.path isEqualToString:@"/revenue"], @"%@", revenuePackage.extendedString); @@ -279,15 +279,15 @@ - (void)testEventsBuffered { @"%@", eventPackage.extendedString); // check that the revenue was buffered - XCTAssert([self.loggerMock containsMessage:AILogLevelInfo beginsWith:@"Buffered revenue (4.5 cent, 'abc123')"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelInfo beginsWith:@"Buffered revenue (4.5 cent, 'abc123')"], @"%@", self.loggerMock); // check the event count in the written activity state - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Wrote activity state: ec:2"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Wrote activity state: ec:2"], @"%@", self.loggerMock); // check the event count in the logger - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Event 2 (revenue)"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 2 (revenue)"], @"%@", self.loggerMock); } - (void)testEventsNotBuffered { @@ -298,7 +298,7 @@ - (void)testEventsNotBuffered { XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session - id activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"]; + id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; [activityHandler setBufferEvents:NO]; // test push token @@ -315,7 +315,7 @@ - (void)testEventsNotBuffered { XCTAssertEqual((NSUInteger)3, [self.packageHandlerMock.packageQueue count], @"%@", self.loggerMock); // check the first event - AIActivityPackage *eventPackage = (AIActivityPackage *) self.packageHandlerMock.packageQueue[1]; + ADJActivityPackage *eventPackage = (ADJActivityPackage *) self.packageHandlerMock.packageQueue[1]; // check the event path XCTAssert([eventPackage.path isEqualToString:@"/event"], @"%@", eventPackage.extendedString); @@ -338,18 +338,18 @@ - (void)testEventsNotBuffered { XCTAssert([@"fc0721b6dfad5ee110975bb2a263de0061cc705b4a85a8ae3ccfbe7a662fb1ab" isEqualToString:eventPackageParameters[@"push_token"]], @"%@", eventPackage.extendedString); // check that the package handler was called - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // check the event count in the written activity state - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Wrote activity state: ec:1"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Wrote activity state: ec:1"], @"%@", self.loggerMock); // check the event count in the logger - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Event 1"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 1"], @"%@", self.loggerMock); // check the second event/ first revenue - AIActivityPackage *revenuePackage = (AIActivityPackage *) self.packageHandlerMock.packageQueue[2]; + ADJActivityPackage *revenuePackage = (ADJActivityPackage *) self.packageHandlerMock.packageQueue[2]; // check the revenue path XCTAssert([revenuePackage.path isEqualToString:@"/revenue"], @"%@", revenuePackage.extendedString); @@ -374,15 +374,15 @@ - (void)testEventsNotBuffered { XCTAssertNil(eventPackageParameters[@"params"], @"%@", eventPackage.extendedString); // check that the package handler was called - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // check the event count in the written activity state - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Wrote activity state: ec:2"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Wrote activity state: ec:2"], @"%@", self.loggerMock); // check the event count in the logger - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Event 2 (revenue)"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 2 (revenue)"], @"%@", self.loggerMock); } @@ -391,7 +391,7 @@ - (void)testChecks { [self reset]; // activity handler without app token - id nilActivityHandler = [AIAdjustFactory activityHandlerWithAppToken:nil]; + id nilActivityHandler = [ADJAdjustFactory activityHandlerWithAppToken:nil]; // trigger the nil app token a 2nd time for a subsession start [nilActivityHandler trackSubsessionStart]; @@ -407,11 +407,11 @@ - (void)testChecks { [NSThread sleepForTimeInterval:1]; // activity with invalid app token - [AIAdjustFactory activityHandlerWithAppToken:@"12345678901"]; + [ADJAdjustFactory activityHandlerWithAppToken:@"12345678901"]; [NSThread sleepForTimeInterval:1]; // activity with valid app token - id activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"]; + id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; // track event with nil token [activityHandler trackEvent:nil withParameters:nil]; @@ -428,28 +428,28 @@ - (void)testChecks { [NSThread sleepForTimeInterval:1]; // check missing app token messages - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Missing App Token"], @"%@", self.loggerMock); // check the invalid app token message - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Malformed App Token '12345678901'"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Malformed App Token '12345678901'"], @"%@", self.loggerMock); // check the nil event token - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Missing Event Token"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Missing Event Token"], @"%@", self.loggerMock); // check the invalid event token - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Malformed Event Token 'abc1234'"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Malformed Event Token 'abc1234'"], @"%@", self.loggerMock); // check the invalid revenue amount token - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Invalid amount -0.1"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Invalid amount -0.1"], @"%@", self.loggerMock); // check the invalid revenue token - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Malformed Event Token 'abc12'"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Malformed Event Token 'abc12'"], @"%@", self.loggerMock); } @@ -462,7 +462,7 @@ - (void)testDisable { XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session - id activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"]; + id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; // verify the default value XCTAssert([activityHandler isEnabled], @"%@", self.loggerMock); @@ -483,28 +483,28 @@ - (void)testDisable { XCTAssertFalse([activityHandler isEnabled], @"%@", self.loggerMock); // making sure the first session was sent - XCTAssert([self.loggerMock containsMessage:AILogLevelInfo beginsWith:@"First session"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelInfo beginsWith:@"First session"], @"%@", self.loggerMock); // delete the first session package from the log - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // making sure the timer fired did not call the package handler - XCTAssertFalse([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // test if the event was not triggered - XCTAssertFalse([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Event 1"], @"%@", self.loggerMock); + XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 1"], @"%@", self.loggerMock); // test if the revenue was not triggered - XCTAssertFalse([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Event 1 (revenue)"], @"%@", self.loggerMock); + XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 1 (revenue)"], @"%@", self.loggerMock); // verify that the application was paused - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler pauseSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler pauseSending"], @"%@", self.loggerMock); // verify that it was not resumed - XCTAssertFalse([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler resumeSending"], + XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler resumeSending"], @"%@", self.loggerMock); // enable again @@ -521,17 +521,17 @@ - (void)testDisable { XCTAssert([activityHandler isEnabled], @"%@", self.loggerMock); // test that the event was triggered - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Event 1"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 1"], @"%@", self.loggerMock); // test that the revenue was triggered - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Event 2 (revenue)"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 2 (revenue)"], @"%@", self.loggerMock); // verify that the application was paused - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler pauseSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler pauseSending"], @"%@", self.loggerMock); // verify that it was also resumed - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler resumeSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler resumeSending"], @"%@", self.loggerMock); } @@ -543,7 +543,7 @@ - (void)testOpenUrl { XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session - id activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"]; + id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; NSString* normal = @"AdjustTests://example.com/path/inApp?adjust_foo=bar&other=stuff&adjust_key=value"; NSString* emptyQueryString = @"AdjustTests://"; @@ -566,19 +566,19 @@ - (void)testOpenUrl { XCTAssertEqual((NSUInteger)2, [self.packageHandlerMock.packageQueue count], @"%@", self.loggerMock); // check that the normal url was parsed and sent - AIActivityPackage *package = (AIActivityPackage *) self.packageHandlerMock.packageQueue[1]; + ADJActivityPackage *package = (ADJActivityPackage *) self.packageHandlerMock.packageQueue[1]; // testing the activity kind is the correct one - AIActivityKind activityKind = package.activityKind; - XCTAssertEqual(AIActivityKindReattribution, activityKind, @"%@", package.extendedString); + ADJActivityKind activityKind = package.activityKind; + XCTAssertEqual(ADJActivityKindReattribution, activityKind, @"%@", package.extendedString); // testing the conversion from activity kind to string - NSString* activityKindString = AIActivityKindToString(activityKind); + NSString* activityKindString = ADJActivityKindToString(activityKind); XCTAssertEqual(@"reattribution", activityKindString); // testing the conversion from string to activity kind - activityKind = AIActivityKindFromString(activityKindString); - XCTAssertEqual(AIActivityKindReattribution, activityKind); + activityKind = ADJActivityKindFromString(activityKindString); + XCTAssertEqual(ADJActivityKindReattribution, activityKind); // packageType should be reattribute XCTAssertEqual(@"/reattribute", package.path, @"%@", package.extendedString); @@ -593,17 +593,17 @@ - (void)testOpenUrl { @"%@", parameters.description); // check that sent the reattribution package - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Reattribution {\n foo = bar;\n key = value;\n}"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Reattribution {\n foo = bar;\n key = value;\n}"], @"%@", self.loggerMock); } - (void)testConversions { // check the logLevel conversions - XCTAssertEqual(AILogLevelVerbose, [AILogger LogLevelFromString:@"verbose"]); - XCTAssertEqual(AILogLevelDebug, [AILogger LogLevelFromString:@"debug"]); - XCTAssertEqual(AILogLevelInfo, [AILogger LogLevelFromString:@"info"]); - XCTAssertEqual(AILogLevelWarn, [AILogger LogLevelFromString:@"warn"]); - XCTAssertEqual(AILogLevelError, [AILogger LogLevelFromString:@"error"]); - XCTAssertEqual(AILogLevelAssert, [AILogger LogLevelFromString:@"assert"]); + XCTAssertEqual(ADJLogLevelVerbose, [ADJLogger LogLevelFromString:@"verbose"]); + XCTAssertEqual(ADJLogLevelDebug, [ADJLogger LogLevelFromString:@"debug"]); + XCTAssertEqual(ADJLogLevelInfo, [ADJLogger LogLevelFromString:@"info"]); + XCTAssertEqual(ADJLogLevelWarn, [ADJLogger LogLevelFromString:@"warn"]); + XCTAssertEqual(ADJLogLevelError, [ADJLogger LogLevelFromString:@"error"]); + XCTAssertEqual(ADJLogLevelAssert, [ADJLogger LogLevelFromString:@"assert"]); } - (void)testfinishedTrackingWithResponse { @@ -614,12 +614,12 @@ - (void)testfinishedTrackingWithResponse { XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session - id activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"]; + id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; [activityHandler finishedTrackingWithResponse:nil deepLink:@"testfinishedTrackingWithResponse://"]; // check the deep link from the response - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Unable to open deep link (testfinishedTrackingWithResponse://)"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Unable to open deep link (testfinishedTrackingWithResponse://)"], @"%@", self.loggerMock); } @end diff --git a/AdjustTests/AILoggerMock.h b/AdjustTests/AILoggerMock.h index 41ca96fce..a60015e16 100644 --- a/AdjustTests/AILoggerMock.h +++ b/AdjustTests/AILoggerMock.h @@ -7,11 +7,11 @@ // #import -#import "AILogger.h" +#import "ADJLogger.h" -static const int AILogLevelTest = 0; +static const int ADJLogLevelTest = 0; -@interface AILoggerMock : NSObject +@interface AILoggerMock : NSObject - (void)test:(NSString *)message, ...; - (BOOL) containsMessage:(NSInteger)logLevel beginsWith:(NSString *)beginsWith; @end diff --git a/AdjustTests/AILoggerMock.m b/AdjustTests/AILoggerMock.m index 51433ddde..b34495401 100644 --- a/AdjustTests/AILoggerMock.m +++ b/AdjustTests/AILoggerMock.m @@ -55,44 +55,44 @@ - (BOOL) containsMessage:(NSInteger)logLevel beginsWith:(NSString *)beginsWith { return NO; } -- (void)setLogLevel:(AILogLevel)logLevel { +- (void)setLogLevel:(ADJLogLevel)logLevel { [self test:@"AILogger setLogLevel logLevel:%@", logLevel]; } - (void)test:(NSString *)format, ... { va_list parameters; va_start(parameters, format); - [self logLevel:AILogLevelTest logPrefix:@"t" format:format parameters:parameters]; + [self logLevel:ADJLogLevelTest logPrefix:@"t" format:format parameters:parameters]; } - (void)verbose:(NSString *)format, ... { va_list parameters; va_start(parameters, format); - [self logLevel:AILogLevelVerbose logPrefix:@"v" format:format parameters:parameters]; + [self logLevel:ADJLogLevelVerbose logPrefix:@"v" format:format parameters:parameters]; } - (void)debug: (NSString *)format, ... { va_list parameters; va_start(parameters, format); - [self logLevel:AILogLevelDebug logPrefix:@"d" format:format parameters:parameters]; + [self logLevel:ADJLogLevelDebug logPrefix:@"d" format:format parameters:parameters]; } - (void)info: (NSString *)format, ... { va_list parameters; va_start(parameters, format); - [self logLevel:AILogLevelInfo logPrefix:@"i" format:format parameters:parameters]; + [self logLevel:ADJLogLevelInfo logPrefix:@"i" format:format parameters:parameters]; } - (void)warn: (NSString *)format, ... { va_list parameters; va_start(parameters, format); - [self logLevel:AILogLevelWarn logPrefix:@"w" format:format parameters:parameters]; + [self logLevel:ADJLogLevelWarn logPrefix:@"w" format:format parameters:parameters]; } - (void)error: (NSString *)format, ... { va_list parameters; va_start(parameters, format); - [self logLevel:AILogLevelError logPrefix:@"e" format:format parameters:parameters]; + [self logLevel:ADJLogLevelError logPrefix:@"e" format:format parameters:parameters]; } - (void)assert: (NSString *)format, ... { va_list parameters; va_start(parameters, format); - [self logLevel:AILogLevelAssert logPrefix:@"a" format:format parameters:parameters]; + [self logLevel:ADJLogLevelAssert logPrefix:@"a" format:format parameters:parameters]; } // private implementation diff --git a/AdjustTests/AIPackageHandlerMock.h b/AdjustTests/AIPackageHandlerMock.h index 559c10f1b..3d3be71e4 100644 --- a/AdjustTests/AIPackageHandlerMock.h +++ b/AdjustTests/AIPackageHandlerMock.h @@ -6,13 +6,13 @@ // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIPackageHandler.h" +#import "ADJPackageHandler.h" -@interface AIPackageHandlerMock : NSObject +@interface AIPackageHandlerMock : NSObject @property (nonatomic, strong) NSMutableArray *packageQueue; @property (nonatomic, strong) AIResponseData *responseData; -@property (nonatomic, strong) AIActivityPackage * activityPackage; +@property (nonatomic, strong) ADJActivityPackage * activityPackage; @end diff --git a/AdjustTests/AIPackageHandlerMock.m b/AdjustTests/AIPackageHandlerMock.m index adff8cced..fcb7245ae 100644 --- a/AdjustTests/AIPackageHandlerMock.m +++ b/AdjustTests/AIPackageHandlerMock.m @@ -8,8 +8,8 @@ #import "AIPackageHandlerMock.h" #import "AILoggerMock.h" -#import "AIAdjustFactory.h" -#import "AIActivityHandler.h" +#import "ADJAdjustFactory.h" +#import "ADJActivityHandler.h" #import "AIResponseData.h" static NSString * const prefix = @"AIPackageHandler "; @@ -17,7 +17,7 @@ @interface AIPackageHandlerMock() @property (nonatomic, strong) AILoggerMock *loggerMock; -@property (nonatomic, assign) id activityHandler; +@property (nonatomic, assign) id activityHandler; @end @@ -27,13 +27,13 @@ - (id)init { return [self initWithActivityHandler:nil]; } -- (id)initWithActivityHandler:(id)activityHandler { +- (id)initWithActivityHandler:(id)activityHandler { self = [super init]; if (self == nil) return nil; self.activityHandler = activityHandler; - self.loggerMock = (AILoggerMock *) AIAdjustFactory.logger; + self.loggerMock = (AILoggerMock *) ADJAdjustFactory.logger; self.packageQueue = [NSMutableArray array]; [self.loggerMock test:[prefix stringByAppendingString:@"initWithActivityHandler"]]; @@ -41,7 +41,7 @@ - (id)initWithActivityHandler:(id)activityHandler { return self; } -- (void)addPackage:(AIActivityPackage *)package { +- (void)addPackage:(ADJActivityPackage *)package { [self.loggerMock test:[prefix stringByAppendingString:@"addPackage"]]; [self.packageQueue addObject:package]; } @@ -67,7 +67,7 @@ - (void)resumeSending { [self.loggerMock test:[prefix stringByAppendingString:@"resumeSending"]]; } -- (void)finishedTrackingActivity:(AIActivityPackage *)activityPackage withResponse:(AIResponseData *)response jsonDict:(NSDictionary *)jsonDict { +- (void)finishedTrackingActivity:(ADJActivityPackage *)activityPackage withResponse:(AIResponseData *)response jsonDict:(NSDictionary *)jsonDict { [self.loggerMock test:[prefix stringByAppendingString:@"finishedTrackingActivity"]]; self.responseData = response; } diff --git a/AdjustTests/AIPackageHandlerTests.m b/AdjustTests/AIPackageHandlerTests.m index 47e37071a..0a3fef37d 100644 --- a/AdjustTests/AIPackageHandlerTests.m +++ b/AdjustTests/AIPackageHandlerTests.m @@ -7,7 +7,7 @@ // #import -#import "AIAdjustFactory.h" +#import "ADJAdjustFactory.h" #import "AILoggerMock.h" #import "AIActivityHandlerMock.h" #import "AIRequestHandlerMock.h" @@ -30,8 +30,8 @@ - (void)setUp - (void)tearDown { - [AIAdjustFactory setRequestHandler:nil]; - [AIAdjustFactory setLogger:nil]; + [ADJAdjustFactory setRequestHandler:nil]; + [ADJAdjustFactory setLogger:nil]; // Put teardown code here; it will be run once, after the last test case. [super tearDown]; @@ -39,10 +39,10 @@ - (void)tearDown - (void)reset { self.loggerMock = [[AILoggerMock alloc] init]; - [AIAdjustFactory setLogger:self.loggerMock]; + [ADJAdjustFactory setLogger:self.loggerMock]; self.requestHandlerMock = [AIRequestHandlerMock alloc]; - [AIAdjustFactory setRequestHandler:self.requestHandlerMock]; + [ADJAdjustFactory setRequestHandler:self.requestHandlerMock]; } @@ -56,7 +56,7 @@ - (void)testFirstPackage // initialize Package Handler AIActivityHandlerMock *activityHandler = [[AIActivityHandlerMock alloc] initWithAppToken:@"123456789012"]; - id packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:activityHandler]; + id packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:activityHandler]; // enable sending packages to Request Handler [packageHandler resumeSending]; @@ -72,28 +72,28 @@ - (void)testFirstPackage [NSThread sleepForTimeInterval:1.0]; // check that the request handler mock was created - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); // test that the file did not exist in the first run of the application - XCTAssert([self.loggerMock containsMessage:AILogLevelVerbose beginsWith:@"Package queue file not found"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelVerbose beginsWith:@"Package queue file not found"], @"%@", self.loggerMock); // check that added first package to a previous empty queue - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Added package 1 (session)"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Added package 1 (session)"], @"%@", self.loggerMock); //TODO add the verbose message // it should write the package queue with the first session package - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Package handler wrote 1 packages"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Package handler wrote 1 packages"], @"%@", self.loggerMock); // check that the Request Handler was called to send the package - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIRequestHandler sendPackage"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler sendPackage"], @"%@", self.loggerMock); // check that the the request handler called the package callback, that foward it to the activity handler - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIActivityHandler finishedTrackingWithResponse"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIActivityHandler finishedTrackingWithResponse"], @"%@", self.loggerMock); // check that the package was removed from the queue and 0 packages were written - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Package handler wrote 0 packages"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Package handler wrote 0 packages"], @"%@", self.loggerMock); } - (void) testPaused { @@ -102,7 +102,7 @@ - (void) testPaused { // initialize Package Handler AIActivityHandlerMock *activityHandler = [[AIActivityHandlerMock alloc] initWithAppToken:@"123456789012"]; - id packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:activityHandler]; + id packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:activityHandler]; // disable sending packages to Request Handler [packageHandler pauseSending]; @@ -116,16 +116,16 @@ - (void) testPaused { [NSThread sleepForTimeInterval:1.0]; // check that the request handler mock was created - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); // check that a package was added - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Added package"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Added package"], @"%@", self.loggerMock); // check that the mock request handler was NOT called to send the package - XCTAssertFalse([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIRequestHandler sendPackage"], @"%@", self.loggerMock); + XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler sendPackage"], @"%@", self.loggerMock); // check that the package handler is paused - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Package handler is paused"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Package handler is paused"], @"%@", self.loggerMock); } - (void) testMultiplePackages { @@ -137,7 +137,7 @@ - (void) testMultiplePackages { // initialize Package Handler AIActivityHandlerMock *activityHandler = [[AIActivityHandlerMock alloc] initWithAppToken:@"123456789012"]; - id packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:activityHandler]; + id packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:activityHandler]; // enable sending packages to Request Handler [packageHandler resumeSending]; @@ -149,7 +149,7 @@ - (void) testMultiplePackages { // create a new package handler to simulate a new launch [NSThread sleepForTimeInterval:1.0]; - packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:activityHandler]; + packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:activityHandler]; // try to send two packages without closing the first [packageHandler sendFirstPackage]; @@ -158,19 +158,19 @@ - (void) testMultiplePackages { [NSThread sleepForTimeInterval:1.0]; // check that the request handler mock was created - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); // test that the file did not exist in the first run of the application - XCTAssert([self.loggerMock containsMessage:AILogLevelVerbose beginsWith:@"Package queue file not found"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelVerbose beginsWith:@"Package queue file not found"], @"%@", self.loggerMock); // check that added the third package to the queue and wrote to a file - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Added package 3 (session)"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Added package 3 (session)"], @"%@", self.loggerMock); // check that it reads the same 3 packages in the file - XCTAssert([self.loggerMock containsMessage:AILogLevelDebug beginsWith:@"Package handler read 3 packages"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Package handler read 3 packages"], @"%@", self.loggerMock); // check that the package handler was already sending one package before - XCTAssert([self.loggerMock containsMessage:AILogLevelVerbose beginsWith:@"Package handler is already sending"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelVerbose beginsWith:@"Package handler is already sending"], @"%@", self.loggerMock); } diff --git a/AdjustTests/AIRequestHandlerMock.h b/AdjustTests/AIRequestHandlerMock.h index e4d0f59c0..56b5c7415 100644 --- a/AdjustTests/AIRequestHandlerMock.h +++ b/AdjustTests/AIRequestHandlerMock.h @@ -7,9 +7,9 @@ // #import -#import "AIRequestHandler.h" +#import "ADJRequestHandler.h" -@interface AIRequestHandlerMock : NSObject +@interface AIRequestHandlerMock : NSObject @property (nonatomic, assign) BOOL connectionError; diff --git a/AdjustTests/AIRequestHandlerMock.m b/AdjustTests/AIRequestHandlerMock.m index 2574d2e0e..3e3e3240c 100644 --- a/AdjustTests/AIRequestHandlerMock.m +++ b/AdjustTests/AIRequestHandlerMock.m @@ -8,26 +8,26 @@ #import "AIRequestHandlerMock.h" #import "AILoggerMock.h" -#import "AIAdjustFactory.h" +#import "ADJAdjustFactory.h" #import "AIResponseData.h" static NSString * const prefix = @"AIRequestHandler "; @interface AIRequestHandlerMock() -@property (nonatomic, assign) id packageHandler; +@property (nonatomic, assign) id packageHandler; @property (nonatomic, assign) AILoggerMock *loggerMock; @end @implementation AIRequestHandlerMock -- (id)initWithPackageHandler:(id) packageHandler { +- (id)initWithPackageHandler:(id) packageHandler { self = [super init]; if (self == nil) return nil; self.packageHandler = packageHandler; - self.loggerMock = (AILoggerMock *) [AIAdjustFactory logger]; + self.loggerMock = (AILoggerMock *) [ADJAdjustFactory logger]; [self.loggerMock test:[prefix stringByAppendingString:@"initWithPackageHandler"]]; @@ -36,7 +36,7 @@ - (id)initWithPackageHandler:(id) packageHandler { return self; } -- (void)sendPackage:(AIActivityPackage *)activityPackage { +- (void)sendPackage:(ADJActivityPackage *)activityPackage { [self.loggerMock test:[prefix stringByAppendingString:@"sendPackage"]]; NSDictionary *jsonDict; diff --git a/AdjustTests/AIRequestHandlerTests.m b/AdjustTests/AIRequestHandlerTests.m index d34e69e7d..ff8a85745 100644 --- a/AdjustTests/AIRequestHandlerTests.m +++ b/AdjustTests/AIRequestHandlerTests.m @@ -7,7 +7,7 @@ // #import -#import "AIAdjustFactory.h" +#import "ADJAdjustFactory.h" #import "AILoggerMock.h" #import "NSURLConnection+NSURLConnectionSynchronousLoadingMocking.h" #import "AIPackageHandlerMock.h" @@ -19,7 +19,7 @@ @interface AIRequestHandlerTests : XCTestCase @property (atomic,strong) AILoggerMock *loggerMock; @property (atomic,strong) AIPackageHandlerMock *packageHandlerMock; -@property (atomic,strong) id requestHandler; +@property (atomic,strong) id requestHandler; @end @@ -37,7 +37,7 @@ - (void)setUp - (void)tearDown { - [AIAdjustFactory setLogger:nil]; + [ADJAdjustFactory setLogger:nil]; // Put teardown code here; it will be run once, after the last test case. [super tearDown]; @@ -45,10 +45,10 @@ - (void)tearDown - (void)reset { self.loggerMock = [[AILoggerMock alloc] init]; - [AIAdjustFactory setLogger:self.loggerMock]; + [ADJAdjustFactory setLogger:self.loggerMock]; self.packageHandlerMock = [[AIPackageHandlerMock alloc] init]; - self.requestHandler =[AIAdjustFactory requestHandlerForPackageHandler:self.packageHandlerMock]; + self.requestHandler =[ADJAdjustFactory requestHandlerForPackageHandler:self.packageHandlerMock]; } - (void)testSendPackage @@ -67,11 +67,11 @@ - (void)testSendPackage NSLog(@"%@", self.loggerMock); // check the URL Connection was called - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"NSURLConnection sendSynchronousRequest"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"NSURLConnection sendSynchronousRequest"], @"%@", self.loggerMock); // check that the package handler was pinged after sending - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler finishedTrackingActivity"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler finishedTrackingActivity"], @"%@", self.loggerMock); // check the response data, the kind is unknown because is set by the package handler @@ -81,11 +81,11 @@ - (void)testSendPackage @"%@", sresponseData); // check that the package was successfully sent - XCTAssert([self.loggerMock containsMessage:AILogLevelInfo beginsWith:@"Tracked session"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelInfo beginsWith:@"Tracked session"], @"%@", self.loggerMock); // check that the package handler was called to send the next package - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler sendNextPackage"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendNextPackage"], @"%@", self.loggerMock); } - (void)testConnectionError { @@ -100,11 +100,11 @@ - (void)testConnectionError { [NSThread sleepForTimeInterval:1.0]; // check the URL Connection was called - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"NSURLConnection sendSynchronousRequest"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"NSURLConnection sendSynchronousRequest"], @"%@", self.loggerMock); // check that the package handler was pinged after sending - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler finishedTrackingActivity"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler finishedTrackingActivity"], @"%@", self.loggerMock); // check the response data, @@ -113,11 +113,11 @@ - (void)testConnectionError { "trackerToken:(null) trackerName:(null) network:(null) campaign:(null) adgroup:(null) creative:(null)]"], @"%@", sresponseData); // check that the package was successfully sent - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Failed to track session. (connection error) Will retry later."], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Failed to track session. (connection error) Will retry later."], @"%@", self.loggerMock); // check that the package handler was called to close the package to retry later - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler closeFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler closeFirstPackage"], @"%@", self.loggerMock); } @@ -134,10 +134,10 @@ - (void)testResponseError { [NSThread sleepForTimeInterval:1.0]; // check the URL Connection was called - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"NSURLConnection sendSynchronousRequest"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"NSURLConnection sendSynchronousRequest"], @"%@", self.loggerMock); // check that the package handler was pinged after sending - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler finishedTrackingActivity"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler finishedTrackingActivity"], @"%@", self.loggerMock); // check the response data, @@ -147,11 +147,11 @@ - (void)testResponseError { "trackerToken:(null) trackerName:(null) network:(null) campaign:(null) adgroup:(null) creative:(null)]"], @"%@", sresponseData); // check that the package was successfully sent - XCTAssert([self.loggerMock containsMessage:AILogLevelError beginsWith:@"Failed to track session. (response error)"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Failed to track session. (response error)"], @"%@", sresponseData); // check that the package handler was called to send the next package - XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler sendNextPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendNextPackage"], @"%@", self.loggerMock); } diff --git a/AdjustTests/AITestsUtil.h b/AdjustTests/AITestsUtil.h index 5c80756c3..96fcb9aa3 100644 --- a/AdjustTests/AITestsUtil.h +++ b/AdjustTests/AITestsUtil.h @@ -8,14 +8,14 @@ #import #import "AILoggerMock.h" -#import "AIActivityPackage.h" +#import "ADJActivityPackage.h" #import "Adjust.h" @interface AITestsUtil : NSObject + (NSString *)getFilename:(NSString *)filename; + (BOOL)deleteFile:(NSString *)filename logger:(AILoggerMock *)loggerMock; -+ (AIActivityPackage *)buildEmptyPackage; ++ (ADJActivityPackage *)buildEmptyPackage; - (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData; diff --git a/AdjustTests/AITestsUtil.m b/AdjustTests/AITestsUtil.m index 9ad2930de..eafeb1e43 100644 --- a/AdjustTests/AITestsUtil.m +++ b/AdjustTests/AITestsUtil.m @@ -7,9 +7,9 @@ // #import "AITestsUtil.h" -#import "AIPackageBuilder.h" +#import "ADJPackageBuilder.h" #import "AILoggerMock.h" -#import "AIAdjustFactory.h" +#import "ADJAdjustFactory.h" @implementation AITestsUtil @@ -42,14 +42,14 @@ + (BOOL)deleteFile:(NSString *)filename logger:(AILoggerMock *)loggerMock { return deleted; } -+ (AIActivityPackage *)buildEmptyPackage { - AIPackageBuilder *sessionBuilder = [[AIPackageBuilder alloc] init]; - AIActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage]; ++ (ADJActivityPackage *)buildEmptyPackage { + ADJPackageBuilder *sessionBuilder = [[ADJPackageBuilder alloc] init]; + ADJActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage]; return sessionPackage; } - (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData { - AILoggerMock *loggerMock = (AILoggerMock *)AIAdjustFactory.logger; + AILoggerMock *loggerMock = (AILoggerMock *)ADJAdjustFactory.logger; [loggerMock test:@"AdjustDelegate adjustFinishedTrackingWithResponse"]; } diff --git a/AdjustTests/NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m b/AdjustTests/NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m index 39177ce24..69ddb1fe2 100644 --- a/AdjustTests/NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m +++ b/AdjustTests/NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m @@ -6,7 +6,7 @@ // Copyright (c) 2014 adjust GmbH. All rights reserved. // #import "NSURLConnection+NSURLConnectionSynchronousLoadingMocking.h" -#import "AIAdjustFactory.h" +#import "ADJAdjustFactory.h" #import "AILoggerMock.h" static BOOL triggerConnectionError = NO; @@ -15,7 +15,7 @@ @implementation NSURLConnection(NSURLConnectionSynchronousLoadingMock) + (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error { - AILoggerMock *loggerMock =(AILoggerMock *)AIAdjustFactory.logger; + AILoggerMock *loggerMock =(AILoggerMock *)ADJAdjustFactory.logger; [loggerMock test:@"NSURLConnection sendSynchronousRequest"]; if (triggerConnectionError) { From a7acfa6a45dd0ed103f2a9b2464d5f8f0841f998 Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 12 Nov 2014 19:21:35 +0100 Subject: [PATCH 16/86] Reattribution to Click --- Adjust/ADJActivityKind.h | 2 +- Adjust/ADJActivityKind.m | 4 ++-- Adjust/ADJPackageBuilder.m | 4 ++-- Adjust/ADJUtil.m | 2 +- AdjustTests/AIActivityHandlerTests.m | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Adjust/ADJActivityKind.h b/Adjust/ADJActivityKind.h index 6e3bb89dc..dc7f58d7c 100644 --- a/Adjust/ADJActivityKind.h +++ b/Adjust/ADJActivityKind.h @@ -13,7 +13,7 @@ typedef enum { ADJActivityKindSession = 1, ADJActivityKindEvent = 2, ADJActivityKindRevenue = 3, - ADJActivityKindReattribution = 4, + ADJActivityKindClick = 4, } ADJActivityKind; ADJActivityKind ADJActivityKindFromString(NSString *string); diff --git a/Adjust/ADJActivityKind.m b/Adjust/ADJActivityKind.m index aaf774b5d..a660b4086 100644 --- a/Adjust/ADJActivityKind.m +++ b/Adjust/ADJActivityKind.m @@ -15,7 +15,7 @@ ADJActivityKind ADJActivityKindFromString(NSString *string) { return ADJActivityKindEvent; } else if ([@"revenue" isEqualToString:string]) { return ADJActivityKindRevenue; - } else if ([@"reattribution" isEqualToString:string]) { + } else if ([@"click" isEqualToString:string]) { return ADJActivityKindReattribution; } else { return ADJActivityKindUnknown; @@ -27,7 +27,7 @@ ADJActivityKind ADJActivityKindFromString(NSString *string) { case ADJActivityKindSession: return @"session"; case ADJActivityKindEvent: return @"event"; case ADJActivityKindRevenue: return @"revenue"; - case ADJActivityKindReattribution: return @"reattribution"; + case ADJActivityKindReattribution: return @"click"; case ADJActivityKindUnknown: return @"unknown"; } } diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index deb2bd9c7..089a8ca9d 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -77,8 +77,8 @@ - (ADJActivityPackage *)buildClickPackage { [self parameters:parameters setBool:self.deviceInfo.isIad forKey:@"is_iad"]; ADJActivityPackage *reattributionPackage = [self defaultActivityPackage]; - reattributionPackage.path = @"/reattribute"; - reattributionPackage.activityKind = ADJActivityKindReattribution; + reattributionPackage.path = @"/sdk_click"; + reattributionPackage.activityKind = ADJActivityKindClick; reattributionPackage.suffix = @""; reattributionPackage.parameters = parameters; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index c40ec122a..f9509c669 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -14,7 +14,7 @@ #include -static NSString * const kBaseUrl = @"https://app.adjust.io"; +static NSString * const kBaseUrl = @"https://app.adjust.com"; static NSString * const kClientSdk = @"ios4.0.0"; static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss:SSS'Z'Z"; diff --git a/AdjustTests/AIActivityHandlerTests.m b/AdjustTests/AIActivityHandlerTests.m index 6ef6592f0..26f86f021 100644 --- a/AdjustTests/AIActivityHandlerTests.m +++ b/AdjustTests/AIActivityHandlerTests.m @@ -570,7 +570,7 @@ - (void)testOpenUrl { // testing the activity kind is the correct one ADJActivityKind activityKind = package.activityKind; - XCTAssertEqual(ADJActivityKindReattribution, activityKind, @"%@", package.extendedString); + XCTAssertEqual(ADJActivityKindClick, activityKind, @"%@", package.extendedString); // testing the conversion from activity kind to string NSString* activityKindString = ADJActivityKindToString(activityKind); @@ -578,7 +578,7 @@ - (void)testOpenUrl { // testing the conversion from string to activity kind activityKind = ADJActivityKindFromString(activityKindString); - XCTAssertEqual(ADJActivityKindReattribution, activityKind); + XCTAssertEqual(ADJActivityKindClick, activityKind); // packageType should be reattribute XCTAssertEqual(@"/reattribute", package.path, @"%@", package.extendedString); From 2c8be03a3cec4798659be03bf47d46a0ef0fb17a Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 13 Nov 2014 17:49:51 +0100 Subject: [PATCH 17/86] Network type user agent --- Adjust/ADJActivityHandler.m | 15 +-- Adjust/ADJActivityKind.m | 4 +- Adjust/ADJActivityState.m | 4 +- Adjust/ADJAdditions/UIDevice+ADJAdditions.h | 18 ++-- Adjust/ADJAdditions/UIDevice+ADJAdditions.m | 18 ++-- Adjust/ADJPackageBuilder.m | 13 ++- Adjust/ADJUserAgent.h | 5 + Adjust/ADJUserAgent.m | 114 ++++++++++++++++++++ Adjust/ADJUtil.h | 2 - Adjust/ADJUtil.m | 22 ---- 10 files changed, 157 insertions(+), 58 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index e8611c0dc..f977261f7 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -18,6 +18,7 @@ #import "NSString+ADJAdditions.h" #import "ADJAdjustFactory.h" #import "ADJAttributionHandler.h" +#include "ADJUserAgent.h" static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAttributionFilename = @"AdjustIoAttribution"; @@ -217,16 +218,16 @@ - (void)initInternal:(ADJConfig *)adjustConfig { [self.logger setLogLevel:adjustConfig.logLevel]; } - NSString *macAddress = UIDevice.currentDevice.aiMacAddress; + NSString *macAddress = UIDevice.currentDevice.adjMacAddress; NSString *macShort = macAddress.aiRemoveColons; self.deviceInfo.macSha1 = macAddress.aiSha1; self.deviceInfo.macShortMd5 = macShort.aiMd5; - self.deviceInfo.trackingEnabled = UIDevice.currentDevice.aiTrackingEnabled; - self.deviceInfo.idForAdvertisers = UIDevice.currentDevice.aiIdForAdvertisers; - self.deviceInfo.fbAttributionId = UIDevice.currentDevice.aiFbAttributionId; - self.deviceInfo.userAgent = ADJUtil.userAgent; - self.deviceInfo.vendorId = UIDevice.currentDevice.aiVendorId; + self.deviceInfo.trackingEnabled = UIDevice.currentDevice.adjTrackingEnabled; + self.deviceInfo.idForAdvertisers = UIDevice.currentDevice.adjIdForAdvertisers; + self.deviceInfo.fbAttributionId = UIDevice.currentDevice.adjFbAttributionId; + self.deviceInfo.userAgent = ADJUserAgent.userAgent; + self.deviceInfo.vendorId = UIDevice.currentDevice.adjVendorId; if (adjustConfig.sdkPrefix == nil) { self.deviceInfo.clientSdk = ADJUtil.clientSdk; @@ -242,7 +243,7 @@ - (void)initInternal:(ADJConfig *)adjustConfig { self.delegate = adjustConfig.delegate; - [[UIDevice currentDevice] aiSetIad:self]; + [[UIDevice currentDevice] adjSetIad:self]; self.packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:self]; self.attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self withMaxDelay:adjustConfig.attributionMaxTimeMilliseconds]; diff --git a/Adjust/ADJActivityKind.m b/Adjust/ADJActivityKind.m index a660b4086..86555be76 100644 --- a/Adjust/ADJActivityKind.m +++ b/Adjust/ADJActivityKind.m @@ -16,7 +16,7 @@ ADJActivityKind ADJActivityKindFromString(NSString *string) { } else if ([@"revenue" isEqualToString:string]) { return ADJActivityKindRevenue; } else if ([@"click" isEqualToString:string]) { - return ADJActivityKindReattribution; + return ADJActivityKindClick; } else { return ADJActivityKindUnknown; } @@ -27,7 +27,7 @@ ADJActivityKind ADJActivityKindFromString(NSString *string) { case ADJActivityKindSession: return @"session"; case ADJActivityKindEvent: return @"event"; case ADJActivityKindRevenue: return @"revenue"; - case ADJActivityKindReattribution: return @"click"; + case ADJActivityKindClick: return @"click"; case ADJActivityKindUnknown: return @"unknown"; } } diff --git a/Adjust/ADJActivityState.m b/Adjust/ADJActivityState.m index ba131c088..94a2ebf6c 100644 --- a/Adjust/ADJActivityState.m +++ b/Adjust/ADJActivityState.m @@ -19,7 +19,7 @@ - (id)init { if (self == nil) return nil; // create UUID for new devices - self.uuid = [UIDevice.currentDevice aiCreateUuid]; + self.uuid = [UIDevice.currentDevice adjCreateUuid]; self.eventCount = 0; self.sessionCount = 0; @@ -85,7 +85,7 @@ - (id)initWithCoder:(NSCoder *)decoder { // create UUID for migrating devices if (self.uuid == nil) { - self.uuid = [UIDevice.currentDevice aiCreateUuid]; + self.uuid = [UIDevice.currentDevice adjCreateUuid]; } if (self.transactionIds == nil) { diff --git a/Adjust/ADJAdditions/UIDevice+ADJAdditions.h b/Adjust/ADJAdditions/UIDevice+ADJAdditions.h index 413828bc7..3b7b154be 100644 --- a/Adjust/ADJAdditions/UIDevice+ADJAdditions.h +++ b/Adjust/ADJAdditions/UIDevice+ADJAdditions.h @@ -11,13 +11,13 @@ @interface UIDevice(ADJAdditions) -- (BOOL)aiTrackingEnabled; -- (NSString *)aiIdForAdvertisers; -- (NSString *)aiFbAttributionId; -- (NSString *)aiMacAddress; -- (NSString *)aiDeviceType; -- (NSString *)aiDeviceName; -- (NSString *)aiCreateUuid; -- (NSString *)aiVendorId; -- (void)aiSetIad:(ADJActivityHandler *)activityHandler; +- (BOOL)adjTrackingEnabled; +- (NSString *)adjIdForAdvertisers; +- (NSString *)adjFbAttributionId; +- (NSString *)adjMacAddress; +- (NSString *)adjDeviceType; +- (NSString *)adjDeviceName; +- (NSString *)adjCreateUuid; +- (NSString *)adjVendorId; +- (void)adjSetIad:(ADJActivityHandler *)activityHandler; @end diff --git a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m index 7697b3248..1d5489d16 100644 --- a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m +++ b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m @@ -24,7 +24,7 @@ @implementation UIDevice(ADJAdditions) -- (BOOL)aiTrackingEnabled { +- (BOOL)adjTrackingEnabled { #if !ADJUST_NO_IDFA NSString *className = [NSString aiJoin:@"A", @"S", @"identifier", @"manager", nil]; NSString *keyManager = [NSString aiJoin:@"shared", @"manager", nil]; @@ -53,7 +53,7 @@ - (BOOL)aiTrackingEnabled { } } -- (NSString *)aiIdForAdvertisers { +- (NSString *)adjIdForAdvertisers { #if !ADJUST_NO_IDFA NSString *className = [NSString aiJoin:@"A", @"S", @"identifier", @"manager", nil]; NSString *keyManager = [NSString aiJoin:@"shared", @"manager", nil]; @@ -85,13 +85,13 @@ - (NSString *)aiIdForAdvertisers { } } -- (NSString *)aiFbAttributionId { +- (NSString *)adjFbAttributionId { NSString *result = [UIPasteboard pasteboardWithName:@"fb_app_attribution" create:NO].string; if (result == nil) return @""; return result; } -- (NSString *)aiMacAddress { +- (NSString *)adjMacAddress { int mib[6]; size_t len; char *buf; @@ -138,12 +138,12 @@ - (NSString *)aiMacAddress { return macAddress; } -- (NSString *)aiDeviceType { +- (NSString *)adjDeviceType { NSString *type = [self.model stringByReplacingOccurrencesOfString:@" " withString:@""]; return type; } -- (NSString *)aiDeviceName { +- (NSString *)adjDeviceName { size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); char *name = malloc(size); @@ -153,7 +153,7 @@ - (NSString *)aiDeviceName { return machine; } -- (NSString *)aiCreateUuid { +- (NSString *)adjCreateUuid { CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault); CFStringRef stringRef = CFUUIDCreateString(kCFAllocatorDefault, newUniqueId); NSString *uuidString = (__bridge_transfer NSString*)stringRef; @@ -162,14 +162,14 @@ - (NSString *)aiCreateUuid { return lowerUuid; } -- (NSString *)aiVendorId { +- (NSString *)adjVendorId { if ([UIDevice.currentDevice respondsToSelector:@selector(identifierForVendor)]) { return [UIDevice.currentDevice.identifierForVendor UUIDString]; } return @""; } -- (void) aiSetIad:(ADJActivityHandler *) activityHandler{ +- (void) adjSetIad:(ADJActivityHandler *) activityHandler{ #if !ADJUST_NO_IDA Class ADClientClass = NSClassFromString(@"ADClient"); if (ADClientClass) { diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 089a8ca9d..8068a6c03 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -136,14 +136,17 @@ - (void) constructActivityState:(ADJActivityState *)activityState - (void) constructUserAgent:(ADJUserAgent *)userAgent withParameters:(NSMutableDictionary *) parameters { - [self parameters:parameters setString:userAgent.bundeIdentifier forKey:@"bundle_identifier"]; - [self parameters:parameters setString:userAgent.bundleVersion forKey:@"bundle_version"]; + [self parameters:parameters setString:userAgent.bundeIdentifier forKey:@"bundle_id"]; + [self parameters:parameters setString:userAgent.bundleVersion forKey:@"app_version"]; [self parameters:parameters setString:userAgent.deviceType forKey:@"device_type"]; [self parameters:parameters setString:userAgent.deviceName forKey:@"device_name"]; [self parameters:parameters setString:userAgent.osName forKey:@"os_name"]; - [self parameters:parameters setString:userAgent.systemVersion forKey:@"system_version"]; - [self parameters:parameters setString:userAgent.languageCode forKey:@"language_code"]; - [self parameters:parameters setString:userAgent.countryCode forKey:@"country_code"]; + [self parameters:parameters setString:userAgent.systemVersion forKey:@"os_version"]; + [self parameters:parameters setString:userAgent.languageCode forKey:@"language"]; + [self parameters:parameters setString:userAgent.countryCode forKey:@"country"]; + [self parameters:parameters setString:userAgent.networkType forKey:@"network_type"]; + [self parameters:parameters setString:userAgent.mobileCountryCode forKey:@"mobile_country_code"]; + [self parameters:parameters setString:userAgent.mobileNetworkCode forKey:@"mobile_network_code"]; } diff --git a/Adjust/ADJUserAgent.h b/Adjust/ADJUserAgent.h index 5e58646a1..3d558e28f 100644 --- a/Adjust/ADJUserAgent.h +++ b/Adjust/ADJUserAgent.h @@ -18,5 +18,10 @@ @property (nonatomic, copy) NSString *systemVersion; @property (nonatomic, copy) NSString *languageCode; @property (nonatomic, copy) NSString *countryCode; +@property (nonatomic, copy) NSString *networkType; +@property (nonatomic, copy) NSString *mobileCountryCode; +@property (nonatomic, copy) NSString *mobileNetworkCode; + ++ (ADJUserAgent *)userAgent; @end diff --git a/Adjust/ADJUserAgent.m b/Adjust/ADJUserAgent.m index e00e25b1a..e61b68572 100644 --- a/Adjust/ADJUserAgent.m +++ b/Adjust/ADJUserAgent.m @@ -7,6 +7,18 @@ // #import "ADJUserAgent.h" +#import "UIDevice+ADJAdditions.h" + +#import +#import + +#import +#import + + +static NSString * const kWiFi = @"WIFI"; +static NSString * const kWWAN = @"WWAN"; + @implementation ADJUserAgent @@ -22,9 +34,111 @@ -(id)copyWithZone:(NSZone *)zone copy.systemVersion = [self.systemVersion copyWithZone:zone]; copy.languageCode = [self.languageCode copyWithZone:zone]; copy.countryCode = [self.countryCode copyWithZone:zone]; + copy.networkType = [self.networkType copyWithZone:zone]; + copy.mobileCountryCode = [self.mobileCountryCode copyWithZone:zone]; + copy.mobileNetworkCode = [self.mobileNetworkCode copyWithZone:zone]; } return copy; } ++ (ADJUserAgent *)userAgent { + + ADJUserAgent * userAgent = [[ADJUserAgent alloc] init]; + + UIDevice *device = UIDevice.currentDevice; + NSLocale *locale = NSLocale.currentLocale; + NSBundle *bundle = NSBundle.mainBundle; + NSDictionary *infoDictionary = bundle.infoDictionary; + CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; + CTCarrier *carrier = [networkInfo subscriberCellularProvider]; + + userAgent.bundeIdentifier = [infoDictionary objectForKey:(NSString *)kCFBundleIdentifierKey]; + userAgent.bundleVersion = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]; + userAgent.languageCode = [locale objectForKey:NSLocaleLanguageCode]; + userAgent.countryCode = [locale objectForKey:NSLocaleCountryCode]; + userAgent.osName = @"ios"; + + userAgent.deviceType = device.adjDeviceType; + userAgent.deviceName = device.adjDeviceName; + userAgent.systemVersion = device.systemVersion; + userAgent.networkType = [ADJUserAgent getNetworkStatus]; + + userAgent.mobileCountryCode = [carrier mobileCountryCode]; + userAgent.mobileNetworkCode = [carrier mobileNetworkCode]; + + return userAgent; +} + +// from https://developer.apple.com/library/ios/samplecode/Reachability/ ++ (NSString *)getNetworkStatus { + + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + + const struct sockaddr_in * hostAddress = &zeroAddress; + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *) hostAddress); + + SCNetworkReachabilityFlags flags; + if(!SCNetworkReachabilityGetFlags(reachability, &flags)) { + return nil; + } + + if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) + { + return nil; + } + + 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... + */ + return kWiFi; + } + + 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... + */ + return kWiFi; + } + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + /* + ... but WWAN connections are OK if the calling application is using the CFNetwork APIs. + */ + return kWWAN; + } + + return nil; +} + ++ (NSString *) x{ + + + // Get mobile country code + NSString *mcc = [carrier mobileCountryCode]; + if (mcc != nil) + NSLog(@"Mobile Country Code (MCC): %@", mcc); + + // Get mobile network code + NSString *mnc = [carrier mobileNetworkCode]; + if (mnc != nil) + NSLog(@"Mobile Network Code (MNC): %@", mnc); + +} + @end diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index c80fdee83..febdc09af 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -6,13 +6,11 @@ // Copyright (c) 2013 adjust GmbH. All rights reserved. // #import -#import "ADJUserAgent.h" @interface ADJUtil : NSObject + (NSString *)baseUrl; + (NSString *)clientSdk; -+ (ADJUserAgent *)userAgent; + (void)excludeFromBackup:(NSString *)filename; + (NSString *)dateFormat:(double)value; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index f9509c669..f23de584d 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -32,28 +32,6 @@ + (NSString *)clientSdk { return kClientSdk; } -+ (ADJUserAgent *)userAgent { - - ADJUserAgent * userAgent = [[ADJUserAgent alloc] init]; - - UIDevice *device = UIDevice.currentDevice; - NSLocale *locale = NSLocale.currentLocale; - NSBundle *bundle = NSBundle.mainBundle; - NSDictionary *infoDictionary = bundle.infoDictionary; - - userAgent.bundeIdentifier = [infoDictionary objectForKey:(NSString *)kCFBundleIdentifierKey]; - userAgent.bundleVersion = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]; - userAgent.languageCode = [locale objectForKey:NSLocaleLanguageCode]; - userAgent.countryCode = [locale objectForKey:NSLocaleCountryCode]; - userAgent.osName = @"ios"; - - userAgent.deviceType = device.aiDeviceType; - userAgent.deviceName = device.aiDeviceName; - userAgent.systemVersion = device.systemVersion; - - return userAgent; -} - #pragma mark - sanitization + (NSString *)sanitizeU:(NSString *)string { return [self.class sanitize:string defaultString:@"unknown"]; From ddf3cc1d11e02d68696df709751389644c09e8ac Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 18 Nov 2014 17:54:05 +0100 Subject: [PATCH 18/86] Example app --- Adjust.xcodeproj/project.pbxproj | 48 ++ Adjust/ADJConfig.h | 1 + Adjust/ADJConfig.m | 5 + Adjust/ADJPackageBuilder.m | 2 +- Adjust/ADJUserAgent.m | 15 - example/example.xcodeproj/project.pbxproj | 572 ++++++++++++++++++ example/example/AppDelegate.h | 18 + example/example/AppDelegate.m | 51 ++ example/example/Base.lproj/LaunchScreen.xib | 41 ++ example/example/Base.lproj/Main.storyboard | 25 + example/example/ExampleAdjustHelper.h | 16 + example/example/ExampleAdjustHelper.m | 45 ++ .../AppIcon.appiconset/Contents.json | 68 +++ example/example/Info.plist | 47 ++ example/example/ViewController.h | 15 + example/example/ViewController.m | 27 + example/example/main.m | 16 + example/exampleTests/Info.plist | 24 + example/exampleTests/exampleTests.m | 40 ++ 19 files changed, 1060 insertions(+), 16 deletions(-) create mode 100644 example/example.xcodeproj/project.pbxproj create mode 100644 example/example/AppDelegate.h create mode 100644 example/example/AppDelegate.m create mode 100644 example/example/Base.lproj/LaunchScreen.xib create mode 100644 example/example/Base.lproj/Main.storyboard create mode 100644 example/example/ExampleAdjustHelper.h create mode 100644 example/example/ExampleAdjustHelper.m create mode 100644 example/example/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 example/example/Info.plist create mode 100644 example/example/ViewController.h create mode 100644 example/example/ViewController.m create mode 100644 example/example/main.m create mode 100644 example/exampleTests/Info.plist create mode 100644 example/exampleTests/exampleTests.m diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index 47846bd1e..1eb9ebbc7 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -52,6 +52,20 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 960FCF4E1A1B9ACF00282BD4 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 960FCF491A1B9ACE00282BD4 /* example.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 960FCF201A1B9ACE00282BD4; + remoteInfo = example; + }; + 960FCF501A1B9ACF00282BD4 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 960FCF491A1B9ACE00282BD4 /* example.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 960FCF391A1B9ACE00282BD4; + remoteInfo = exampleTests; + }; 9679922318BBAE2800394606 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 9679920518BBAE2800394606 /* Project object */; @@ -78,6 +92,7 @@ 9609BC6919EEA55800E02303 /* ADJEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJEvent.m; sourceTree = ""; }; 960A8BB71A029A8000F2BB95 /* ADJConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJConfig.h; sourceTree = ""; }; 960A8BB81A029A8000F2BB95 /* ADJConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJConfig.m; sourceTree = ""; }; + 960FCF491A1B9ACE00282BD4 /* example.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = example.xcodeproj; path = example/example.xcodeproj; sourceTree = ""; }; 96325E84190E5CD900A97911 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 96325E86190E5CE400A97911 /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iAd.framework; path = System/Library/Frameworks/iAd.framework; sourceTree = SDKROOT; }; 9644B7EA19F148F3008576FC /* ADJDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJDeviceInfo.h; sourceTree = ""; }; @@ -175,9 +190,19 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 960FCF4A1A1B9ACE00282BD4 /* Products */ = { + isa = PBXGroup; + children = ( + 960FCF4F1A1B9ACF00282BD4 /* example.app */, + 960FCF511A1B9ACF00282BD4 /* exampleTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; 9679920418BBAE2800394606 = { isa = PBXGroup; children = ( + 960FCF491A1B9ACE00282BD4 /* example.xcodeproj */, 96CD4471192A546F0029A1AA /* AdjustBridge */, 96E5E39A18BBB49E008E7B30 /* AdjustTests */, 96E5E34B18BBB48A008E7B30 /* Adjust */, @@ -365,6 +390,12 @@ mainGroup = 9679920418BBAE2800394606; productRefGroup = 9679920E18BBAE2800394606 /* Products */; projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 960FCF4A1A1B9ACE00282BD4 /* Products */; + ProjectRef = 960FCF491A1B9ACE00282BD4 /* example.xcodeproj */; + }, + ); projectRoot = ""; targets = ( 9679920C18BBAE2800394606 /* Adjust */, @@ -373,6 +404,23 @@ }; /* End PBXProject section */ +/* Begin PBXReferenceProxy section */ + 960FCF4F1A1B9ACF00282BD4 /* example.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = example.app; + remoteRef = 960FCF4E1A1B9ACF00282BD4 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 960FCF511A1B9ACF00282BD4 /* exampleTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = exampleTests.xctest; + remoteRef = 960FCF501A1B9ACF00282BD4 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + /* Begin PBXResourcesBuildPhase section */ 9679921B18BBAE2800394606 /* Resources */ = { isa = PBXResourcesBuildPhase; diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index fd7df4e56..4e917c351 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -40,6 +40,7 @@ @property (nonatomic, copy) NSNumber* attributionMaxTimeMilliseconds; - (id)initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; ++ (ADJConfig*)configWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; - (void)addPermanentCallbackParameter:(NSString *)key andValue:(NSString *)value; diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index b46d4905b..282deca7c 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -12,6 +12,11 @@ @implementation ADJConfig ++ (ADJConfig *) configWithAppToken:(NSString *)appToken + andEnvironment:(NSString *)environment { + return [[ADJConfig alloc] initWithAppToken:appToken andEnvironment:environment]; +} + - (id) initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment { diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 8068a6c03..8f77eaee8 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -40,7 +40,7 @@ - (ADJActivityPackage *)buildSessionPackage { [self parameters:parameters setDictionaryJson:self.adjustConfig.partnerPermanentParameters forKey:@"partner_params"]; ADJActivityPackage *sessionPackage = [self defaultActivityPackage]; - sessionPackage.path = @"/session"; + sessionPackage.path = @"/startup"; sessionPackage.activityKind = ADJActivityKindSession; sessionPackage.suffix = @""; sessionPackage.parameters = parameters; diff --git a/Adjust/ADJUserAgent.m b/Adjust/ADJUserAgent.m index e61b68572..d0e23c47b 100644 --- a/Adjust/ADJUserAgent.m +++ b/Adjust/ADJUserAgent.m @@ -126,19 +126,4 @@ + (NSString *)getNetworkStatus { return nil; } -+ (NSString *) x{ - - - // Get mobile country code - NSString *mcc = [carrier mobileCountryCode]; - if (mcc != nil) - NSLog(@"Mobile Country Code (MCC): %@", mcc); - - // Get mobile network code - NSString *mnc = [carrier mobileNetworkCode]; - if (mnc != nil) - NSLog(@"Mobile Network Code (MNC): %@", mnc); - -} - @end diff --git a/example/example.xcodeproj/project.pbxproj b/example/example.xcodeproj/project.pbxproj new file mode 100644 index 000000000..be5256ab4 --- /dev/null +++ b/example/example.xcodeproj/project.pbxproj @@ -0,0 +1,572 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 960FCF261A1B9ACE00282BD4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF251A1B9ACE00282BD4 /* main.m */; }; + 960FCF291A1B9ACE00282BD4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF281A1B9ACE00282BD4 /* AppDelegate.m */; }; + 960FCF2C1A1B9ACE00282BD4 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF2B1A1B9ACE00282BD4 /* ViewController.m */; }; + 960FCF2F1A1B9ACE00282BD4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 960FCF2D1A1B9ACE00282BD4 /* Main.storyboard */; }; + 960FCF311A1B9ACE00282BD4 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 960FCF301A1B9ACE00282BD4 /* Images.xcassets */; }; + 960FCF341A1B9ACE00282BD4 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 960FCF321A1B9ACE00282BD4 /* LaunchScreen.xib */; }; + 960FCF401A1B9ACE00282BD4 /* exampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF3F1A1B9ACE00282BD4 /* exampleTests.m */; }; + 960FCF7C1A1B9B7D00282BD4 /* NSString+ADJAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF531A1B9B7D00282BD4 /* NSString+ADJAdditions.m */; }; + 960FCF7D1A1B9B7D00282BD4 /* UIDevice+ADJAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF551A1B9B7D00282BD4 /* UIDevice+ADJAdditions.m */; }; + 960FCF7E1A1B9B7D00282BD4 /* Adjust.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF581A1B9B7D00282BD4 /* Adjust.m */; }; + 960FCF7F1A1B9B7D00282BD4 /* ADJActivityHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF5A1A1B9B7D00282BD4 /* ADJActivityHandler.m */; }; + 960FCF801A1B9B7D00282BD4 /* ADJActivityKind.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF5C1A1B9B7D00282BD4 /* ADJActivityKind.m */; }; + 960FCF811A1B9B7D00282BD4 /* ADJActivityPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF5E1A1B9B7D00282BD4 /* ADJActivityPackage.m */; }; + 960FCF821A1B9B7D00282BD4 /* ADJActivityState.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF601A1B9B7D00282BD4 /* ADJActivityState.m */; }; + 960FCF831A1B9B7D00282BD4 /* ADJAdjustFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF621A1B9B7D00282BD4 /* ADJAdjustFactory.m */; }; + 960FCF841A1B9B7D00282BD4 /* ADJLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF641A1B9B7D00282BD4 /* ADJLogger.m */; }; + 960FCF851A1B9B7D00282BD4 /* ADJPackageBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF661A1B9B7D00282BD4 /* ADJPackageBuilder.m */; }; + 960FCF861A1B9B7D00282BD4 /* ADJPackageHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF681A1B9B7D00282BD4 /* ADJPackageHandler.m */; }; + 960FCF871A1B9B7D00282BD4 /* ADJRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF6A1A1B9B7D00282BD4 /* ADJRequestHandler.m */; }; + 960FCF881A1B9B7D00282BD4 /* ADJTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF6C1A1B9B7D00282BD4 /* ADJTimer.m */; }; + 960FCF891A1B9B7D00282BD4 /* ADJUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF6E1A1B9B7D00282BD4 /* ADJUtil.m */; }; + 960FCF8A1A1B9B7D00282BD4 /* ADJEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF701A1B9B7D00282BD4 /* ADJEvent.m */; }; + 960FCF8B1A1B9B7D00282BD4 /* ADJDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF721A1B9B7D00282BD4 /* ADJDeviceInfo.m */; }; + 960FCF8C1A1B9B7D00282BD4 /* ADJUserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF741A1B9B7D00282BD4 /* ADJUserAgent.m */; }; + 960FCF8D1A1B9B7D00282BD4 /* ADJAttributionHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF761A1B9B7D00282BD4 /* ADJAttributionHandler.m */; }; + 960FCF8E1A1B9B7D00282BD4 /* ADJAttribution.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF781A1B9B7D00282BD4 /* ADJAttribution.m */; }; + 960FCF8F1A1B9B7D00282BD4 /* ADJConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF7A1A1B9B7D00282BD4 /* ADJConfig.m */; }; + 960FCF921A1B9E6800282BD4 /* ExampleAdjustHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF911A1B9E6800282BD4 /* ExampleAdjustHelper.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 960FCF3A1A1B9ACE00282BD4 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 960FCF181A1B9ACE00282BD4 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 960FCF1F1A1B9ACE00282BD4; + remoteInfo = example; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 960FCF201A1B9ACE00282BD4 /* example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 960FCF241A1B9ACE00282BD4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 960FCF251A1B9ACE00282BD4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 960FCF271A1B9ACE00282BD4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 960FCF281A1B9ACE00282BD4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 960FCF2A1A1B9ACE00282BD4 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 960FCF2B1A1B9ACE00282BD4 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 960FCF2E1A1B9ACE00282BD4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 960FCF301A1B9ACE00282BD4 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + 960FCF331A1B9ACE00282BD4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + 960FCF391A1B9ACE00282BD4 /* exampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = exampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 960FCF3E1A1B9ACE00282BD4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 960FCF3F1A1B9ACE00282BD4 /* exampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = exampleTests.m; sourceTree = ""; }; + 960FCF521A1B9B7D00282BD4 /* NSString+ADJAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+ADJAdditions.h"; sourceTree = ""; }; + 960FCF531A1B9B7D00282BD4 /* NSString+ADJAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+ADJAdditions.m"; sourceTree = ""; }; + 960FCF541A1B9B7D00282BD4 /* UIDevice+ADJAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+ADJAdditions.h"; sourceTree = ""; }; + 960FCF551A1B9B7D00282BD4 /* UIDevice+ADJAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+ADJAdditions.m"; sourceTree = ""; }; + 960FCF571A1B9B7D00282BD4 /* Adjust.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Adjust.h; sourceTree = ""; }; + 960FCF581A1B9B7D00282BD4 /* Adjust.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Adjust.m; sourceTree = ""; }; + 960FCF591A1B9B7D00282BD4 /* ADJActivityHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityHandler.h; sourceTree = ""; }; + 960FCF5A1A1B9B7D00282BD4 /* ADJActivityHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityHandler.m; sourceTree = ""; }; + 960FCF5B1A1B9B7D00282BD4 /* ADJActivityKind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityKind.h; sourceTree = ""; }; + 960FCF5C1A1B9B7D00282BD4 /* ADJActivityKind.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityKind.m; sourceTree = ""; }; + 960FCF5D1A1B9B7D00282BD4 /* ADJActivityPackage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityPackage.h; sourceTree = ""; }; + 960FCF5E1A1B9B7D00282BD4 /* ADJActivityPackage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityPackage.m; sourceTree = ""; }; + 960FCF5F1A1B9B7D00282BD4 /* ADJActivityState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityState.h; sourceTree = ""; }; + 960FCF601A1B9B7D00282BD4 /* ADJActivityState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityState.m; sourceTree = ""; }; + 960FCF611A1B9B7D00282BD4 /* ADJAdjustFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJAdjustFactory.h; sourceTree = ""; }; + 960FCF621A1B9B7D00282BD4 /* ADJAdjustFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAdjustFactory.m; sourceTree = ""; }; + 960FCF631A1B9B7D00282BD4 /* ADJLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJLogger.h; sourceTree = ""; }; + 960FCF641A1B9B7D00282BD4 /* ADJLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJLogger.m; sourceTree = ""; }; + 960FCF651A1B9B7D00282BD4 /* ADJPackageBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJPackageBuilder.h; sourceTree = ""; }; + 960FCF661A1B9B7D00282BD4 /* ADJPackageBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJPackageBuilder.m; sourceTree = ""; }; + 960FCF671A1B9B7D00282BD4 /* ADJPackageHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJPackageHandler.h; sourceTree = ""; }; + 960FCF681A1B9B7D00282BD4 /* ADJPackageHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJPackageHandler.m; sourceTree = ""; }; + 960FCF691A1B9B7D00282BD4 /* ADJRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJRequestHandler.h; sourceTree = ""; }; + 960FCF6A1A1B9B7D00282BD4 /* ADJRequestHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJRequestHandler.m; sourceTree = ""; }; + 960FCF6B1A1B9B7D00282BD4 /* ADJTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJTimer.h; sourceTree = ""; }; + 960FCF6C1A1B9B7D00282BD4 /* ADJTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJTimer.m; sourceTree = ""; }; + 960FCF6D1A1B9B7D00282BD4 /* ADJUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUtil.h; sourceTree = ""; }; + 960FCF6E1A1B9B7D00282BD4 /* ADJUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUtil.m; sourceTree = ""; }; + 960FCF6F1A1B9B7D00282BD4 /* ADJEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJEvent.h; sourceTree = ""; }; + 960FCF701A1B9B7D00282BD4 /* ADJEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJEvent.m; sourceTree = ""; }; + 960FCF711A1B9B7D00282BD4 /* ADJDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJDeviceInfo.h; sourceTree = ""; }; + 960FCF721A1B9B7D00282BD4 /* ADJDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJDeviceInfo.m; sourceTree = ""; }; + 960FCF731A1B9B7D00282BD4 /* ADJUserAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUserAgent.h; sourceTree = ""; }; + 960FCF741A1B9B7D00282BD4 /* ADJUserAgent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserAgent.m; sourceTree = ""; }; + 960FCF751A1B9B7D00282BD4 /* ADJAttributionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJAttributionHandler.h; sourceTree = ""; }; + 960FCF761A1B9B7D00282BD4 /* ADJAttributionHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAttributionHandler.m; sourceTree = ""; }; + 960FCF771A1B9B7D00282BD4 /* ADJAttribution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJAttribution.h; sourceTree = ""; }; + 960FCF781A1B9B7D00282BD4 /* ADJAttribution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAttribution.m; sourceTree = ""; }; + 960FCF791A1B9B7D00282BD4 /* ADJConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJConfig.h; sourceTree = ""; }; + 960FCF7A1A1B9B7D00282BD4 /* ADJConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJConfig.m; sourceTree = ""; }; + 960FCF901A1B9E6800282BD4 /* ExampleAdjustHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleAdjustHelper.h; sourceTree = ""; }; + 960FCF911A1B9E6800282BD4 /* ExampleAdjustHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleAdjustHelper.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 960FCF1D1A1B9ACE00282BD4 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 960FCF361A1B9ACE00282BD4 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 960FCF171A1B9ACE00282BD4 = { + isa = PBXGroup; + children = ( + 960FCF221A1B9ACE00282BD4 /* example */, + 960FCF3C1A1B9ACE00282BD4 /* exampleTests */, + 960FCF211A1B9ACE00282BD4 /* Products */, + ); + sourceTree = ""; + }; + 960FCF211A1B9ACE00282BD4 /* Products */ = { + isa = PBXGroup; + children = ( + 960FCF201A1B9ACE00282BD4 /* example.app */, + 960FCF391A1B9ACE00282BD4 /* exampleTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 960FCF221A1B9ACE00282BD4 /* example */ = { + isa = PBXGroup; + children = ( + 960FCF271A1B9ACE00282BD4 /* AppDelegate.h */, + 960FCF281A1B9ACE00282BD4 /* AppDelegate.m */, + 960FCF2A1A1B9ACE00282BD4 /* ViewController.h */, + 960FCF2B1A1B9ACE00282BD4 /* ViewController.m */, + 960FCF2D1A1B9ACE00282BD4 /* Main.storyboard */, + 960FCF301A1B9ACE00282BD4 /* Images.xcassets */, + 960FCF321A1B9ACE00282BD4 /* LaunchScreen.xib */, + 960FCF231A1B9ACE00282BD4 /* Supporting Files */, + 960FCF901A1B9E6800282BD4 /* ExampleAdjustHelper.h */, + 960FCF911A1B9E6800282BD4 /* ExampleAdjustHelper.m */, + ); + path = example; + sourceTree = ""; + }; + 960FCF231A1B9ACE00282BD4 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 960FCF7B1A1B9B7D00282BD4 /* Adjust */, + 960FCF241A1B9ACE00282BD4 /* Info.plist */, + 960FCF251A1B9ACE00282BD4 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 960FCF3C1A1B9ACE00282BD4 /* exampleTests */ = { + isa = PBXGroup; + children = ( + 960FCF3F1A1B9ACE00282BD4 /* exampleTests.m */, + 960FCF3D1A1B9ACE00282BD4 /* Supporting Files */, + ); + path = exampleTests; + sourceTree = ""; + }; + 960FCF3D1A1B9ACE00282BD4 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 960FCF3E1A1B9ACE00282BD4 /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 960FCF561A1B9B7D00282BD4 /* ADJAdditions */ = { + isa = PBXGroup; + children = ( + 960FCF521A1B9B7D00282BD4 /* NSString+ADJAdditions.h */, + 960FCF531A1B9B7D00282BD4 /* NSString+ADJAdditions.m */, + 960FCF541A1B9B7D00282BD4 /* UIDevice+ADJAdditions.h */, + 960FCF551A1B9B7D00282BD4 /* UIDevice+ADJAdditions.m */, + ); + path = ADJAdditions; + sourceTree = ""; + }; + 960FCF7B1A1B9B7D00282BD4 /* Adjust */ = { + isa = PBXGroup; + children = ( + 960FCF561A1B9B7D00282BD4 /* ADJAdditions */, + 960FCF571A1B9B7D00282BD4 /* Adjust.h */, + 960FCF581A1B9B7D00282BD4 /* Adjust.m */, + 960FCF591A1B9B7D00282BD4 /* ADJActivityHandler.h */, + 960FCF5A1A1B9B7D00282BD4 /* ADJActivityHandler.m */, + 960FCF5B1A1B9B7D00282BD4 /* ADJActivityKind.h */, + 960FCF5C1A1B9B7D00282BD4 /* ADJActivityKind.m */, + 960FCF5D1A1B9B7D00282BD4 /* ADJActivityPackage.h */, + 960FCF5E1A1B9B7D00282BD4 /* ADJActivityPackage.m */, + 960FCF5F1A1B9B7D00282BD4 /* ADJActivityState.h */, + 960FCF601A1B9B7D00282BD4 /* ADJActivityState.m */, + 960FCF611A1B9B7D00282BD4 /* ADJAdjustFactory.h */, + 960FCF621A1B9B7D00282BD4 /* ADJAdjustFactory.m */, + 960FCF631A1B9B7D00282BD4 /* ADJLogger.h */, + 960FCF641A1B9B7D00282BD4 /* ADJLogger.m */, + 960FCF651A1B9B7D00282BD4 /* ADJPackageBuilder.h */, + 960FCF661A1B9B7D00282BD4 /* ADJPackageBuilder.m */, + 960FCF671A1B9B7D00282BD4 /* ADJPackageHandler.h */, + 960FCF681A1B9B7D00282BD4 /* ADJPackageHandler.m */, + 960FCF691A1B9B7D00282BD4 /* ADJRequestHandler.h */, + 960FCF6A1A1B9B7D00282BD4 /* ADJRequestHandler.m */, + 960FCF6B1A1B9B7D00282BD4 /* ADJTimer.h */, + 960FCF6C1A1B9B7D00282BD4 /* ADJTimer.m */, + 960FCF6D1A1B9B7D00282BD4 /* ADJUtil.h */, + 960FCF6E1A1B9B7D00282BD4 /* ADJUtil.m */, + 960FCF6F1A1B9B7D00282BD4 /* ADJEvent.h */, + 960FCF701A1B9B7D00282BD4 /* ADJEvent.m */, + 960FCF711A1B9B7D00282BD4 /* ADJDeviceInfo.h */, + 960FCF721A1B9B7D00282BD4 /* ADJDeviceInfo.m */, + 960FCF731A1B9B7D00282BD4 /* ADJUserAgent.h */, + 960FCF741A1B9B7D00282BD4 /* ADJUserAgent.m */, + 960FCF751A1B9B7D00282BD4 /* ADJAttributionHandler.h */, + 960FCF761A1B9B7D00282BD4 /* ADJAttributionHandler.m */, + 960FCF771A1B9B7D00282BD4 /* ADJAttribution.h */, + 960FCF781A1B9B7D00282BD4 /* ADJAttribution.m */, + 960FCF791A1B9B7D00282BD4 /* ADJConfig.h */, + 960FCF7A1A1B9B7D00282BD4 /* ADJConfig.m */, + ); + name = Adjust; + path = ../../Adjust; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 960FCF1F1A1B9ACE00282BD4 /* example */ = { + isa = PBXNativeTarget; + buildConfigurationList = 960FCF431A1B9ACE00282BD4 /* Build configuration list for PBXNativeTarget "example" */; + buildPhases = ( + 960FCF1C1A1B9ACE00282BD4 /* Sources */, + 960FCF1D1A1B9ACE00282BD4 /* Frameworks */, + 960FCF1E1A1B9ACE00282BD4 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = example; + productName = example; + productReference = 960FCF201A1B9ACE00282BD4 /* example.app */; + productType = "com.apple.product-type.application"; + }; + 960FCF381A1B9ACE00282BD4 /* exampleTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 960FCF461A1B9ACE00282BD4 /* Build configuration list for PBXNativeTarget "exampleTests" */; + buildPhases = ( + 960FCF351A1B9ACE00282BD4 /* Sources */, + 960FCF361A1B9ACE00282BD4 /* Frameworks */, + 960FCF371A1B9ACE00282BD4 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 960FCF3B1A1B9ACE00282BD4 /* PBXTargetDependency */, + ); + name = exampleTests; + productName = exampleTests; + productReference = 960FCF391A1B9ACE00282BD4 /* exampleTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 960FCF181A1B9ACE00282BD4 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0610; + ORGANIZATIONNAME = adjust; + TargetAttributes = { + 960FCF1F1A1B9ACE00282BD4 = { + CreatedOnToolsVersion = 6.1; + }; + 960FCF381A1B9ACE00282BD4 = { + CreatedOnToolsVersion = 6.1; + TestTargetID = 960FCF1F1A1B9ACE00282BD4; + }; + }; + }; + buildConfigurationList = 960FCF1B1A1B9ACE00282BD4 /* Build configuration list for PBXProject "example" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 960FCF171A1B9ACE00282BD4; + productRefGroup = 960FCF211A1B9ACE00282BD4 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 960FCF1F1A1B9ACE00282BD4 /* example */, + 960FCF381A1B9ACE00282BD4 /* exampleTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 960FCF1E1A1B9ACE00282BD4 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 960FCF2F1A1B9ACE00282BD4 /* Main.storyboard in Resources */, + 960FCF341A1B9ACE00282BD4 /* LaunchScreen.xib in Resources */, + 960FCF311A1B9ACE00282BD4 /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 960FCF371A1B9ACE00282BD4 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 960FCF1C1A1B9ACE00282BD4 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 960FCF891A1B9B7D00282BD4 /* ADJUtil.m in Sources */, + 960FCF8B1A1B9B7D00282BD4 /* ADJDeviceInfo.m in Sources */, + 960FCF851A1B9B7D00282BD4 /* ADJPackageBuilder.m in Sources */, + 960FCF8E1A1B9B7D00282BD4 /* ADJAttribution.m in Sources */, + 960FCF821A1B9B7D00282BD4 /* ADJActivityState.m in Sources */, + 960FCF2C1A1B9ACE00282BD4 /* ViewController.m in Sources */, + 960FCF921A1B9E6800282BD4 /* ExampleAdjustHelper.m in Sources */, + 960FCF7D1A1B9B7D00282BD4 /* UIDevice+ADJAdditions.m in Sources */, + 960FCF291A1B9ACE00282BD4 /* AppDelegate.m in Sources */, + 960FCF881A1B9B7D00282BD4 /* ADJTimer.m in Sources */, + 960FCF8F1A1B9B7D00282BD4 /* ADJConfig.m in Sources */, + 960FCF261A1B9ACE00282BD4 /* main.m in Sources */, + 960FCF811A1B9B7D00282BD4 /* ADJActivityPackage.m in Sources */, + 960FCF8D1A1B9B7D00282BD4 /* ADJAttributionHandler.m in Sources */, + 960FCF871A1B9B7D00282BD4 /* ADJRequestHandler.m in Sources */, + 960FCF7E1A1B9B7D00282BD4 /* Adjust.m in Sources */, + 960FCF7F1A1B9B7D00282BD4 /* ADJActivityHandler.m in Sources */, + 960FCF861A1B9B7D00282BD4 /* ADJPackageHandler.m in Sources */, + 960FCF801A1B9B7D00282BD4 /* ADJActivityKind.m in Sources */, + 960FCF841A1B9B7D00282BD4 /* ADJLogger.m in Sources */, + 960FCF831A1B9B7D00282BD4 /* ADJAdjustFactory.m in Sources */, + 960FCF8A1A1B9B7D00282BD4 /* ADJEvent.m in Sources */, + 960FCF8C1A1B9B7D00282BD4 /* ADJUserAgent.m in Sources */, + 960FCF7C1A1B9B7D00282BD4 /* NSString+ADJAdditions.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 960FCF351A1B9ACE00282BD4 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 960FCF401A1B9ACE00282BD4 /* exampleTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 960FCF3B1A1B9ACE00282BD4 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 960FCF1F1A1B9ACE00282BD4 /* example */; + targetProxy = 960FCF3A1A1B9ACE00282BD4 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 960FCF2D1A1B9ACE00282BD4 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 960FCF2E1A1B9ACE00282BD4 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 960FCF321A1B9ACE00282BD4 /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + 960FCF331A1B9ACE00282BD4 /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 960FCF411A1B9ACE00282BD4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = 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_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.1; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 960FCF421A1B9ACE00282BD4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = 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_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.1; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 960FCF441A1B9ACE00282BD4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = example/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 960FCF451A1B9ACE00282BD4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = example/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 960FCF471A1B9ACE00282BD4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = exampleTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/example"; + }; + name = Debug; + }; + 960FCF481A1B9ACE00282BD4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + INFOPLIST_FILE = exampleTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/example"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 960FCF1B1A1B9ACE00282BD4 /* Build configuration list for PBXProject "example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 960FCF411A1B9ACE00282BD4 /* Debug */, + 960FCF421A1B9ACE00282BD4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 960FCF431A1B9ACE00282BD4 /* Build configuration list for PBXNativeTarget "example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 960FCF441A1B9ACE00282BD4 /* Debug */, + 960FCF451A1B9ACE00282BD4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; + 960FCF461A1B9ACE00282BD4 /* Build configuration list for PBXNativeTarget "exampleTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 960FCF471A1B9ACE00282BD4 /* Debug */, + 960FCF481A1B9ACE00282BD4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 960FCF181A1B9ACE00282BD4 /* Project object */; +} diff --git a/example/example/AppDelegate.h b/example/example/AppDelegate.h new file mode 100644 index 000000000..a3335390b --- /dev/null +++ b/example/example/AppDelegate.h @@ -0,0 +1,18 @@ +// +// AppDelegate.h +// example +// +// Created by Pedro Filipe on 18/11/14. +// Copyright (c) 2014 adjust. All rights reserved. +// + +#import +#import "ADJConfig.h" + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m new file mode 100644 index 000000000..77030edfa --- /dev/null +++ b/example/example/AppDelegate.m @@ -0,0 +1,51 @@ +// +// AppDelegate.m +// example +// +// Created by Pedro Filipe on 18/11/14. +// Copyright (c) 2014 adjust. All rights reserved. +// + +#import "AppDelegate.h" +#import "ExampleAdjustHelper.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + [ExampleAdjustHelper initAdjust:self]; + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +- (void)adjustAttributionCallback:(ADJAttribution *)attribution { + +} + +@end diff --git a/example/example/Base.lproj/LaunchScreen.xib b/example/example/Base.lproj/LaunchScreen.xib new file mode 100644 index 000000000..b0d2755c9 --- /dev/null +++ b/example/example/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/example/Base.lproj/Main.storyboard b/example/example/Base.lproj/Main.storyboard new file mode 100644 index 000000000..f56d2f3bb --- /dev/null +++ b/example/example/Base.lproj/Main.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/example/ExampleAdjustHelper.h b/example/example/ExampleAdjustHelper.h new file mode 100644 index 000000000..43e4a2be1 --- /dev/null +++ b/example/example/ExampleAdjustHelper.h @@ -0,0 +1,16 @@ +// +// AdjustInit.h +// example +// +// Created by Pedro Filipe on 18/11/14. +// Copyright (c) 2014 adjust. All rights reserved. +// + +#import +#import "ADJConfig.h" + +@interface ExampleAdjustHelper : NSObject + ++ (void) initAdjust: (id)adjustDelegate; + +@end diff --git a/example/example/ExampleAdjustHelper.m b/example/example/ExampleAdjustHelper.m new file mode 100644 index 000000000..aaf6e5694 --- /dev/null +++ b/example/example/ExampleAdjustHelper.m @@ -0,0 +1,45 @@ +// +// AdjustInit.m +// example +// +// Created by Pedro Filipe on 18/11/14. +// Copyright (c) 2014 adjust. All rights reserved. +// + +#import "ExampleAdjustHelper.h" +#import "Adjust.h" +#import "ADJLogger.h" + +@implementation ExampleAdjustHelper + ++ (void) initAdjust: (id)adjustDelegate { + NSString * yourAppToken = @"{YourAppToken}"; + NSString * enviroment = AIEnvironmentSandbox; + ADJConfig * adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; + + // change the log level + //[adjustConfig setLogLevel:ADJLogLevelVerbose]; + + // enable event buffering + //[adjustConfig setEventBufferingEnabled:YES]; + + // disable MAC MD5 tracking + //[adjustConfig setMacMd5TrackingEnabled:NO]; + + // set an attribution delegate + //[adjustConfig setDelegate:adjustDelegate]; + + // set maximum waited to get the attribution + //[adjustConfig setAttributionMaxTimeMilliseconds:10000]; + + // add callback parameters to all events and sessions + //[adjustConfig addPermanentCallbackParameter:@"key" andValue:@"value"]; + + // add partner parameteres to all events and sessions + //[adjustConfig addPermanentPartnerParameter:@"key" andValue:@"value"]; + + Adjust * adjust = [Adjust getInstance]; + [adjust appDidLaunch:adjustConfig]; +} + +@end diff --git a/example/example/Images.xcassets/AppIcon.appiconset/Contents.json b/example/example/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..36d2c80d8 --- /dev/null +++ b/example/example/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/example/example/Info.plist b/example/example/Info.plist new file mode 100644 index 000000000..c6d8e00cf --- /dev/null +++ b/example/example/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.adjust.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/example/example/ViewController.h b/example/example/ViewController.h new file mode 100644 index 000000000..81545a882 --- /dev/null +++ b/example/example/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// example +// +// Created by Pedro Filipe on 18/11/14. +// Copyright (c) 2014 adjust. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/example/example/ViewController.m b/example/example/ViewController.m new file mode 100644 index 000000000..a3447534e --- /dev/null +++ b/example/example/ViewController.m @@ -0,0 +1,27 @@ +// +// ViewController.m +// example +// +// Created by Pedro Filipe on 18/11/14. +// Copyright (c) 2014 adjust. All rights reserved. +// + +#import "ViewController.h" + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +@end diff --git a/example/example/main.m b/example/example/main.m new file mode 100644 index 000000000..dd5631230 --- /dev/null +++ b/example/example/main.m @@ -0,0 +1,16 @@ +// +// main.m +// example +// +// Created by Pedro Filipe on 18/11/14. +// Copyright (c) 2014 adjust. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/example/exampleTests/Info.plist b/example/exampleTests/Info.plist new file mode 100644 index 000000000..43234cef3 --- /dev/null +++ b/example/exampleTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.adjust.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/example/exampleTests/exampleTests.m b/example/exampleTests/exampleTests.m new file mode 100644 index 000000000..d6b06fb6c --- /dev/null +++ b/example/exampleTests/exampleTests.m @@ -0,0 +1,40 @@ +// +// exampleTests.m +// exampleTests +// +// Created by Pedro Filipe on 18/11/14. +// Copyright (c) 2014 adjust. All rights reserved. +// + +#import +#import + +@interface exampleTests : XCTestCase + +@end + +@implementation exampleTests + +- (void)setUp { + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testExample { + // This is an example of a functional test case. + XCTAssert(YES, @"Pass"); +} + +- (void)testPerformanceExample { + // This is an example of a performance test case. + [self measureBlock:^{ + // Put the code you want to measure the time of here. + }]; +} + +@end From b58e41336cd2a90b68de3addb19575b1ef70b036 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 27 Nov 2014 18:15:42 +0100 Subject: [PATCH 19/86] iAd time --- Adjust/ADJActivityHandler.h | 2 + Adjust/ADJActivityHandler.m | 67 ++++++++++++----- Adjust/ADJAdditions/UIDevice+ADJAdditions.m | 8 ++- Adjust/ADJDeviceInfo.h | 1 - Adjust/ADJDeviceInfo.m | 1 - Adjust/ADJPackageBuilder.h | 11 ++- Adjust/ADJPackageBuilder.m | 80 ++++++++++++++------- Adjust/ADJRequestHandler.m | 2 +- Adjust/ADJUtil.h | 3 +- Adjust/ADJUtil.m | 14 ++-- example/example/Base.lproj/LaunchScreen.xib | 4 +- example/example/Base.lproj/Main.storyboard | 6 +- 12 files changed, 134 insertions(+), 65 deletions(-) diff --git a/Adjust/ADJActivityHandler.h b/Adjust/ADJActivityHandler.h index 0e096c2f9..49c563276 100644 --- a/Adjust/ADJActivityHandler.h +++ b/Adjust/ADJActivityHandler.h @@ -28,6 +28,8 @@ - (void) setAttribution:(ADJAttribution*)attribution; - (void) updateAttribution:(ADJAttribution*) attribution; +- (void) setIadDate:(NSDate*)iAdImpressionDate withPurchaseDate:(NSDate*)appPurchaseDate; + - (void) launchAttributionDelegate; - (void) setOfflineMode:(BOOL)enabled; diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index f977261f7..748227fe6 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -157,15 +157,18 @@ - (void)setDeviceToken:(NSData *)deviceToken { }); } -- (void)setIsIad:(BOOL)isIad { - self.deviceInfo.isIad = isIad; - if (isIad) { - ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo - andActivityState:self.activityState - andConfig:self.adjustConfig]; +- (void)setIadDate:(NSDate *)iAdImpressionDate withPurchaseDate:(NSDate *)appPurchaseDate { + if (iAdImpressionDate != nil || appPurchaseDate != nil) { + ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc] + initWithDeviceInfo:self.deviceInfo + andActivityState:self.activityState + andConfig:self.adjustConfig]; - ADJActivityPackage *reattributionPackage = [clickBuilder buildClickPackage]; - [self.packageHandler sendClickPackage:reattributionPackage]; + [clickBuilder setIAdImpressionDate:iAdImpressionDate]; + [clickBuilder setAppPurchaseDate:appPurchaseDate]; + + ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad"]; + [self.packageHandler sendClickPackage:clickPackage]; } } @@ -346,9 +349,8 @@ - (void)eventInternal:(ADJEvent *)event ADJPackageBuilder *eventBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState andConfig:self.adjustConfig]; - eventBuilder.event = event; - ADJActivityPackage *eventPackage = [eventBuilder buildEventPackage]; + ADJActivityPackage *eventPackage = [eventBuilder buildEventPackage:event]; [self.packageHandler addPackage:eventPackage]; if (self.adjustConfig.eventBufferingEnabled) { @@ -363,6 +365,8 @@ - (void)eventInternal:(ADJEvent *)event - (void) appWillOpenUrlInternal:(NSURL *)url { NSArray* queryArray = [url.query componentsSeparatedByString:@"&"]; NSMutableDictionary* adjustDeepLinks = [NSMutableDictionary dictionary]; + ADJAttribution * attribution = [[ADJAttribution alloc] init]; + BOOL adjustParamsFound = NO; for (NSString* fieldValuePair in queryArray) { NSArray* pairComponents = [fieldValuePair componentsSeparatedByString:@"="]; @@ -377,22 +381,53 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { NSString* keyWOutPrefix = [key substringFromIndex:kAdjustPrefix.length]; if (keyWOutPrefix.length == 0) continue; - [adjustDeepLinks setObject:value forKey:keyWOutPrefix]; + adjustParamsFound = YES; + if (![self trySetAttributionDeeplink:attribution withKey:keyWOutPrefix withValue:value]) { + [adjustDeepLinks setObject:value forKey:keyWOutPrefix]; + } } [self.attributionHandler getAttribution]; - if (adjustDeepLinks.count == 0) { + if (!adjustParamsFound) { return; } - ADJPackageBuilder *ClickBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + ADJPackageBuilder * clickBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState andConfig:self.adjustConfig]; - ClickBuilder.deeplinkParameters = adjustDeepLinks; + clickBuilder.deeplinkParameters = adjustDeepLinks; + clickBuilder.attribution = attribution; + + ADJActivityPackage * clickPackage = [clickBuilder buildClickPackage:@"deeplink"]; + [self.packageHandler sendClickPackage:clickPackage]; +} + +- (BOOL) trySetAttributionDeeplink:(ADJAttribution *)attribution + withKey:(NSString *)key + withValue:(NSString*)value { + + if ([key isEqualToString:@"tracker"]) { + attribution.trackerName = value; + return YES; + } + + if ([key isEqualToString:@"campaign"]) { + attribution.campaign = value; + return YES; + } + + if ([key isEqualToString:@"adgroup"]) { + attribution.adgroup = value; + return YES; + } + + if ([key isEqualToString:@"creative"]) { + attribution.creative = value; + return YES; + } - ADJActivityPackage *reattributionPackage = [ClickBuilder buildClickPackage]; - [self.packageHandler sendClickPackage:reattributionPackage]; + return NO; } - (void) setDeviceTokenInternal:(NSData *)deviceToken { diff --git a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m index 1d5489d16..4c7b6998a 100644 --- a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m +++ b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m @@ -172,16 +172,18 @@ - (NSString *)adjVendorId { - (void) adjSetIad:(ADJActivityHandler *) activityHandler{ #if !ADJUST_NO_IDA Class ADClientClass = NSClassFromString(@"ADClient"); + if (ADClientClass) { @try { SEL sharedClientSelector = NSSelectorFromString(@"sharedClient"); - SEL iadSelector = NSSelectorFromString(@"determineAppInstallationAttributionWithCompletionHandler:"); + SEL iadDateSelector = NSSelectorFromString(@"lookupAdConversionDetails:"); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" id ADClientSharedClientInstance = [ADClientClass performSelector:sharedClientSelector]; - [ADClientSharedClientInstance performSelector:iadSelector withObject:^(BOOL appInstallationWasAttributedToiAd) { - activityHandler.isIad = appInstallationWasAttributedToiAd; + [ADClientSharedClientInstance performSelector:iadDateSelector + withObject:^(NSDate *appPurchaseDate, NSDate *iAdImpressionDate) { + [activityHandler setIadDate:iAdImpressionDate withPurchaseDate:appPurchaseDate]; }]; #pragma clang diagnostic pop } diff --git a/Adjust/ADJDeviceInfo.h b/Adjust/ADJDeviceInfo.h index 6fe950e82..02b5eea75 100644 --- a/Adjust/ADJDeviceInfo.h +++ b/Adjust/ADJDeviceInfo.h @@ -16,7 +16,6 @@ @property (nonatomic, copy) NSString *idForAdvertisers; @property (nonatomic, copy) NSString *fbAttributionId; @property (nonatomic, assign) BOOL trackingEnabled; -@property (nonatomic, assign) BOOL isIad; @property (nonatomic, copy) NSString *vendorId; @property (nonatomic, copy) NSString *pushToken; @property (nonatomic, copy) NSString *clientSdk; diff --git a/Adjust/ADJDeviceInfo.m b/Adjust/ADJDeviceInfo.m index 2d26d6fc4..a742302b6 100644 --- a/Adjust/ADJDeviceInfo.m +++ b/Adjust/ADJDeviceInfo.m @@ -19,7 +19,6 @@ -(id)copyWithZone:(NSZone *)zone copy.idForAdvertisers = [self.idForAdvertisers copyWithZone:zone]; copy.fbAttributionId = [self.fbAttributionId copyWithZone:zone]; copy.trackingEnabled = self.trackingEnabled; - copy.isIad = self.isIad; copy.vendorId = [self.vendorId copyWithZone:zone]; copy.pushToken = [self.pushToken copyWithZone:zone]; copy.clientSdk = [self.clientSdk copyWithZone:zone]; diff --git a/Adjust/ADJPackageBuilder.h b/Adjust/ADJPackageBuilder.h index 36adaf7e7..a1b2d53b0 100644 --- a/Adjust/ADJPackageBuilder.h +++ b/Adjust/ADJPackageBuilder.h @@ -15,12 +15,12 @@ @interface ADJPackageBuilder : NSObject @property (nonatomic, copy) ADJDeviceInfo* deviceInfo; -@property (nonatomic, copy) ADJEvent* event; @property (nonatomic, copy) ADJActivityState *activityState; @property (nonatomic, copy) ADJConfig *adjustConfig; @property (nonatomic, assign) BOOL hasDelegate; - -// reattributions +@property (nonatomic, copy) ADJAttribution * attribution; +@property (nonatomic, copy) NSDate * iAdImpressionDate; +@property (nonatomic, copy) NSDate * appPurchaseDate; @property (nonatomic, copy) NSDictionary* deeplinkParameters; - (id) initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo @@ -28,7 +28,6 @@ andConfig:(ADJConfig *)adjustConfig; - (ADJActivityPackage *)buildSessionPackage; -- (ADJActivityPackage *)buildEventPackage; -- (ADJActivityPackage *)buildClickPackage; - +- (ADJActivityPackage *)buildEventPackage:(ADJEvent *)event; +- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource; @end diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 8f77eaee8..78926f051 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -9,6 +9,7 @@ #import "ADJPackageBuilder.h" #import "ADJActivityPackage.h" #import "ADJUtil.h" +#import "ADJAttribution.h" #pragma mark - @implementation ADJPackageBuilder @@ -48,41 +49,51 @@ - (ADJActivityPackage *)buildSessionPackage { return sessionPackage; } -- (ADJActivityPackage *)buildEventPackage { +- (ADJActivityPackage *)buildEventPackage:(ADJEvent *) event{ NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setInt:self.activityState.eventCount forKey:@"event_count"]; - [self parameters:parameters setString:self.amountString forKey:@"amount"]; - [self parameters:parameters setString:self.event.currency forKey:@"currency"]; - [self parameters:parameters setString:self.event.eventToken forKey:@"event_token"]; + NSString * amountString = [self amountString:event]; + [self parameters:parameters setString:amountString forKey:@"amount"]; + [self parameters:parameters setString:event.currency forKey:@"currency"]; + [self parameters:parameters setString:event.eventToken forKey:@"event_token"]; // join the permanent parameters with the ones from the event - NSMutableDictionary * callbackParameters = [self joinParamters:self.adjustConfig.callbackPermanentParameters parameters:self.event.callbackParameters]; + NSMutableDictionary * callbackParameters = [self joinParamters:self.adjustConfig.callbackPermanentParameters parameters:event.callbackParameters]; [self parameters:parameters setDictionaryJson:callbackParameters forKey:@"callback_params"]; - NSMutableDictionary * partnerParamters = [self joinParamters:self.adjustConfig.partnerPermanentParameters parameters:self.event.partnerParameters]; + NSMutableDictionary * partnerParamters = [self joinParamters:self.adjustConfig.partnerPermanentParameters parameters:event.partnerParameters]; [self parameters:parameters setDictionaryJson:partnerParamters forKey:@"partner_params"]; ADJActivityPackage *eventPackage = [self defaultActivityPackage]; eventPackage.path = @"/event"; eventPackage.activityKind = ADJActivityKindEvent; - eventPackage.suffix = self.eventSuffix; + eventPackage.suffix = [self eventSuffix:event]; eventPackage.parameters = parameters; return eventPackage; } -- (ADJActivityPackage *)buildClickPackage { +- (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource{ NSMutableDictionary *parameters = [self defaultParameters]; - [self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"deeplink_params"]; - [self parameters:parameters setBool:self.deviceInfo.isIad forKey:@"is_iad"]; + [self parameters:parameters setString:@"source" forKey:clickSource]; + [self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"params"]; + [self parameters:parameters setDate:self.iAdImpressionDate forKey:@"click_time"]; + [self parameters:parameters setDate:self.appPurchaseDate forKey:@"purchase_time"]; + + if (self.attribution != nil) { + [self parameters:parameters setString:self.attribution.trackerName forKey:@"tracker"]; + [self parameters:parameters setString:self.attribution.campaign forKey:@"campaign"]; + [self parameters:parameters setString:self.attribution.adgroup forKey:@"adgroup"]; + [self parameters:parameters setString:self.attribution.creative forKey:@"creative"]; + } - ADJActivityPackage *reattributionPackage = [self defaultActivityPackage]; - reattributionPackage.path = @"/sdk_click"; - reattributionPackage.activityKind = ADJActivityKindClick; - reattributionPackage.suffix = @""; - reattributionPackage.parameters = parameters; + ADJActivityPackage *clickPackage = [self defaultActivityPackage]; + clickPackage.path = @"/sdk_click"; + clickPackage.activityKind = ADJActivityKindClick; + clickPackage.suffix = @""; + clickPackage.parameters = parameters; - return reattributionPackage; + return clickPackage; } #pragma mark private @@ -125,7 +136,7 @@ - (void) constructDeviceInfo:(ADJDeviceInfo *)deviceInfo - (void) constructActivityState:(ADJActivityState *)activityState withParamters:(NSMutableDictionary *)parameters { - [self parameters:parameters setDate:activityState.createdAt forKey:@"created_at"]; + [self parameters:parameters setDate1970:activityState.createdAt forKey:@"created_at"]; [self parameters:parameters setInt:activityState.sessionCount forKey:@"session_count"]; [self parameters:parameters setInt:activityState.subsessionCount forKey:@"subsession_count"]; [self parameters:parameters setDuration:activityState.sessionLength forKey:@"session_length"]; @@ -150,22 +161,22 @@ - (void) constructUserAgent:(ADJUserAgent *)userAgent } -- (NSString *)amountString { - if (self.event.revenue == nil || [self.event.revenue doubleValue] == 0) { +- (NSString *)amountString:(ADJEvent*)event { + if (event.revenue == nil || [event.revenue doubleValue] == 0) { return nil; } - double revenue = [self.event.revenue doubleValue]; + double revenue = [event.revenue doubleValue]; int amountInMillis = round(1000 * revenue); - self.event.revenue = [NSNumber numberWithDouble:(amountInMillis / 1000.0)]; // now rounded to one decimal point + event.revenue = [NSNumber numberWithDouble:(amountInMillis / 1000.0)]; // now rounded to one decimal point NSString *amountString = [NSNumber numberWithInt:amountInMillis].stringValue; return amountString; } -- (NSString *)eventSuffix { - if (self.event.revenue == nil) { - return [NSString stringWithFormat:@" '%@'", self.event.eventToken]; +- (NSString *)eventSuffix:(ADJEvent*)event { + if (event.revenue == nil) { + return [NSString stringWithFormat:@" '%@'", event.eventToken]; } else { - return [NSString stringWithFormat:@" (%.3f cent, '%@')", [self.event.revenue doubleValue], self.event.eventToken]; + return [NSString stringWithFormat:@" (%.3f cent, '%@')", [event.revenue doubleValue], event.eventToken]; } } @@ -182,10 +193,17 @@ - (void)parameters:(NSMutableDictionary *)parameters setInt:(int)value forKey:(N [self parameters:parameters setString:valueString forKey:key]; } -- (void)parameters:(NSMutableDictionary *)parameters setDate:(double)value forKey:(NSString *)key { +- (void)parameters:(NSMutableDictionary *)parameters setDate1970:(double)value forKey:(NSString *)key { if (value < 0) return; - NSString *dateString = [ADJUtil dateFormat:value]; + NSString *dateString = [ADJUtil formatSeconds1970:value]; + [self parameters:parameters setString:dateString forKey:key]; +} + +- (void)parameters:(NSMutableDictionary *)parameters setDate:(NSDate *)value forKey:(NSString *)key { + if (value == nil) return; + + NSString *dateString = [ADJUtil formatDate:value]; [self parameters:parameters setString:dateString forKey:key]; } @@ -212,6 +230,14 @@ - (void)parameters:(NSMutableDictionary *)parameters setBool:(BOOL)value forKey: [self parameters:parameters setInt:valueInt forKey:key]; } +- (void)parameters:(NSMutableDictionary *)parameters setNumberBool:(NSNumber *)value forKey:(NSString *)key { + if (value == nil); + + BOOL boolValue = [value boolValue]; + + [self parameters:parameters setBool:boolValue forKey:key]; +} + - (NSMutableDictionary *) joinParamters:(NSMutableDictionary *)permanentParameters parameters:(NSMutableDictionary *)parameters { if (permanentParameters == nil) { diff --git a/Adjust/ADJRequestHandler.m b/Adjust/ADJRequestHandler.m index 4819dacf5..6cba08bc6 100644 --- a/Adjust/ADJRequestHandler.m +++ b/Adjust/ADJRequestHandler.m @@ -124,7 +124,7 @@ - (NSData *)bodyForParameters:(NSDictionary *)parameters { } double now = [NSDate.date timeIntervalSince1970]; - NSString *dateString = [ADJUtil dateFormat:now]; + NSString *dateString = [ADJUtil formatSeconds1970:now]; NSString *escapedDate = [dateString aiUrlEncode]; NSString *sentAtPair = [NSString stringWithFormat:@"%@=%@", @"sent_at", escapedDate]; [pairs addObject:sentAtPair]; diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index febdc09af..81b994cf1 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -13,7 +13,8 @@ + (NSString *)clientSdk; + (void)excludeFromBackup:(NSString *)filename; -+ (NSString *)dateFormat:(double)value; ++ (NSString *)formatSeconds1970:(double)value; ++ (NSString *)formatDate:(NSDate *)value; + (NSDictionary *) buildJsonDict:(NSString *)jsonString; + (NSString *)getFullFilename:(NSString *) baseFilename; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index f23de584d..8ccc3bad2 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -89,17 +89,23 @@ + (void)excludeFromBackup:(NSString *)path { } } -+ (NSString *)dateFormat:(double) value { ++ (NSString *)formatSeconds1970:(double) value { + NSDate *date = [NSDate dateWithTimeIntervalSince1970:value]; + + return [self formatDate:date]; +} + + ++ (NSString *)formatDate:(NSDate *) value { if (dateFormat == nil) { dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:kDateFormat]; } - NSDate *date = [NSDate dateWithTimeIntervalSince1970:value]; - - return [dateFormat stringFromDate:date]; + return [dateFormat stringFromDate:value]; } + + (NSDictionary *)buildJsonDict:(NSString *)jsonString { NSError *error = nil; NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; diff --git a/example/example/Base.lproj/LaunchScreen.xib b/example/example/Base.lproj/LaunchScreen.xib index b0d2755c9..18a59b2fc 100644 --- a/example/example/Base.lproj/LaunchScreen.xib +++ b/example/example/Base.lproj/LaunchScreen.xib @@ -1,7 +1,7 @@ - + - + diff --git a/example/example/Base.lproj/Main.storyboard b/example/example/Base.lproj/Main.storyboard index f56d2f3bb..bebd9f514 100644 --- a/example/example/Base.lproj/Main.storyboard +++ b/example/example/Base.lproj/Main.storyboard @@ -1,13 +1,13 @@ - + - + - + From 02985adc47447025b8fa80c0b121e0aa2b55afc9 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 1 Dec 2014 15:13:40 +0100 Subject: [PATCH 20/86] Example app trigger event --- Adjust/ADJAttribution.m | 1 - Adjust/ADJEvent.h | 1 + Adjust/ADJEvent.m | 4 ++++ Adjust/ADJPackageBuilder.m | 2 +- example/example/AppDelegate.m | 4 +++- example/example/ExampleAdjustHelper.h | 1 + example/example/ExampleAdjustHelper.m | 20 +++++++++++++++++++- 7 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Adjust/ADJAttribution.m b/Adjust/ADJAttribution.m index 48d697e49..f77c642f9 100644 --- a/Adjust/ADJAttribution.m +++ b/Adjust/ADJAttribution.m @@ -92,7 +92,6 @@ - (NSDictionary *)dictionary { [responseDataDic setObject:(self.finalAttribution? @"true" : @"false") forKey:@"final"]; - return responseDataDic; } diff --git a/Adjust/ADJEvent.h b/Adjust/ADJEvent.h index ab4ddb109..116cdf8a5 100644 --- a/Adjust/ADJEvent.h +++ b/Adjust/ADJEvent.h @@ -18,6 +18,7 @@ @property (nonatomic, copy) NSString* currency; - (id) initWithEventToken:(NSString *)eventToken; ++ (ADJEvent *)eventWithEventToken:(NSString *)eventToken; - (void) addCallbackParameter:(NSString *)key andValue:(NSString *)value; diff --git a/Adjust/ADJEvent.m b/Adjust/ADJEvent.m index f699bc5c3..48b36db88 100644 --- a/Adjust/ADJEvent.m +++ b/Adjust/ADJEvent.m @@ -12,6 +12,10 @@ @implementation ADJEvent ++ (ADJEvent *)eventWithEventToken:(NSString *)eventToken { + return [[ADJEvent alloc] initWithEventToken:eventToken]; +} + - (id) initWithEventToken:(NSString *)eventToken { self = [super init]; if (self == nil) return nil; diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 78926f051..995d1aa6b 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -108,7 +108,7 @@ - (NSMutableDictionary *)defaultParameters { [self constructDeviceInfo:self.deviceInfo withParameter:parameters andConfig:self.adjustConfig]; [self constructActivityState:self.activityState withParamters:parameters]; - [self parameters:parameters setBool:self.hasDelegate forKey:@"has_delegate"]; + [self parameters:parameters setBool:!self.hasDelegate forKey:@"needs_attribution_data"]; return parameters; } diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m index 77030edfa..d62986a0e 100644 --- a/example/example/AppDelegate.m +++ b/example/example/AppDelegate.m @@ -19,6 +19,8 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [ExampleAdjustHelper initAdjust:self]; + + [ExampleAdjustHelper triggerEvent:@"{your event token}"]; return YES; } @@ -45,7 +47,7 @@ - (void)applicationWillTerminate:(UIApplication *)application { } - (void)adjustAttributionCallback:(ADJAttribution *)attribution { - + NSLog(@"adjust attribution %@", attribution); } @end diff --git a/example/example/ExampleAdjustHelper.h b/example/example/ExampleAdjustHelper.h index 43e4a2be1..8be0e399a 100644 --- a/example/example/ExampleAdjustHelper.h +++ b/example/example/ExampleAdjustHelper.h @@ -13,4 +13,5 @@ + (void) initAdjust: (id)adjustDelegate; ++ (void) triggerEvent: (NSString*) eventToken; @end diff --git a/example/example/ExampleAdjustHelper.m b/example/example/ExampleAdjustHelper.m index aaf6e5694..6be14eec1 100644 --- a/example/example/ExampleAdjustHelper.m +++ b/example/example/ExampleAdjustHelper.m @@ -9,6 +9,7 @@ #import "ExampleAdjustHelper.h" #import "Adjust.h" #import "ADJLogger.h" +#import "ADJEvent.h" @implementation ExampleAdjustHelper @@ -36,10 +37,27 @@ + (void) initAdjust: (id)adjustDelegate { //[adjustConfig addPermanentCallbackParameter:@"key" andValue:@"value"]; // add partner parameteres to all events and sessions - //[adjustConfig addPermanentPartnerParameter:@"key" andValue:@"value"]; + //[adjustConfig addPermanentPartnerParameter:@"foo" andValue:@"bar"]; Adjust * adjust = [Adjust getInstance]; [adjust appDidLaunch:adjustConfig]; } ++ (void) triggerEvent: (NSString*) eventToken { + + ADJEvent * event = [ADJEvent eventWithEventToken:eventToken]; + + // add revenue 1 cent of an euro + //[event setRevenue:0.01 currency:@"EUR"]; + + // add callback parameters to this parameter + //[event addCallbackParameter:@"key" andValue:@"value"]; + + // add partner parameteres to all events and sessions + //[event addPartnerParameter:@"foo" andValue:@"bar"]; + + Adjust * adjust = [Adjust getInstance]; + [adjust trackEvent:event]; +} + @end From f8e3689e64c883ba5934329300bc5b6b016d7613 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 1 Dec 2014 18:11:58 +0100 Subject: [PATCH 21/86] Attribution handler url --- Adjust/ADJActivityHandler.m | 15 +++++--- Adjust/ADJActivityKind.h | 2 +- Adjust/ADJActivityKind.m | 2 +- Adjust/ADJAdjustFactory.h | 5 ++- Adjust/ADJAdjustFactory.m | 13 +++++-- Adjust/ADJAttribution.m | 2 +- Adjust/ADJAttributionHandler.h | 9 +++-- Adjust/ADJAttributionHandler.m | 50 +++++++++++++++++++++------ Adjust/ADJPackageBuilder.h | 2 ++ Adjust/ADJPackageBuilder.m | 19 ++++++++++ Adjust/ADJRequestHandler.m | 41 ++++++++++------------ Adjust/ADJUtil.h | 1 + Adjust/ADJUtil.m | 19 ++++++++++ example/example/AppDelegate.m | 2 +- example/example/ExampleAdjustHelper.h | 2 +- example/example/ExampleAdjustHelper.m | 8 ++--- 16 files changed, 141 insertions(+), 51 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 748227fe6..7325e0041 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -23,7 +23,7 @@ static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAttributionFilename = @"AdjustIoAttribution"; static NSString * const kActivityStateName = @"activity state"; -static NSString * const kAttributionName = @"attributionlo"; +static NSString * const kAttributionName = @"attribution"; static NSString * const kAdjustPrefix = @"adjust_"; static const char * const kInternalQueueName = "io.adjust.ActivityQueue"; @@ -106,7 +106,7 @@ - (void)finishedTrackingWithResponse:(NSDictionary *)jsonDict{ } - (void)launchDeepLink:(NSDictionary *)jsonDict{ - if (jsonDict == nil) return; + if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; NSString * deepLink = [jsonDict objectForKey:@"deeplink"]; if (deepLink == nil) return; @@ -248,10 +248,17 @@ - (void)initInternal:(ADJConfig *)adjustConfig { [[UIDevice currentDevice] adjSetIad:self]; + self.activityState = [ADJUtil readObject:kActivityStateFilename objectName:kActivityStateName]; + self.packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:self]; - self.attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self withMaxDelay:adjustConfig.attributionMaxTimeMilliseconds]; + ADJPackageBuilder * attributionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + andActivityState:self.activityState + andConfig:self.adjustConfig]; + ADJActivityPackage * attributionPackage = [attributionBuilder buildAttributionPackage]; + self.attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self + withMaxDelay:adjustConfig.attributionMaxTimeMilliseconds + withAttributionPackage:attributionPackage]; - self.activityState = [ADJUtil readObject:kActivityStateFilename objectName:kActivityStateName]; self.attribution = [ADJUtil readObject:kAttributionFilename objectName:kAttributionName]; [self startInternal]; diff --git a/Adjust/ADJActivityKind.h b/Adjust/ADJActivityKind.h index dc7f58d7c..684c332e7 100644 --- a/Adjust/ADJActivityKind.h +++ b/Adjust/ADJActivityKind.h @@ -13,7 +13,7 @@ typedef enum { ADJActivityKindSession = 1, ADJActivityKindEvent = 2, ADJActivityKindRevenue = 3, - ADJActivityKindClick = 4, + ADJActivityKindClick = 4, } ADJActivityKind; ADJActivityKind ADJActivityKindFromString(NSString *string); diff --git a/Adjust/ADJActivityKind.m b/Adjust/ADJActivityKind.m index 86555be76..a80b84c53 100644 --- a/Adjust/ADJActivityKind.m +++ b/Adjust/ADJActivityKind.m @@ -28,6 +28,6 @@ ADJActivityKind ADJActivityKindFromString(NSString *string) { case ADJActivityKindEvent: return @"event"; case ADJActivityKindRevenue: return @"revenue"; case ADJActivityKindClick: return @"click"; - case ADJActivityKindUnknown: return @"unknown"; + default: return @"unknown"; } } diff --git a/Adjust/ADJAdjustFactory.h b/Adjust/ADJAdjustFactory.h index f0aedf0cf..c3aeed374 100644 --- a/Adjust/ADJAdjustFactory.h +++ b/Adjust/ADJAdjustFactory.h @@ -12,6 +12,7 @@ #import "ADJRequestHandler.h" #import "ADJLogger.h" #import "ADJAttributionHandler.h" +#import "ADJActivityPackage.h" @interface ADJAdjustFactory : NSObject @@ -21,7 +22,9 @@ + (id)logger; + (double)sessionInterval; + (double)subsessionInterval; -+ (id)attributionHandlerForActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds; ++ (id)attributionHandlerForActivityHandler:(id)activityHandler + withMaxDelay:(NSNumber *)milliseconds + withAttributionPackage:(ADJActivityPackage *) attributionPackage; + (void)setPackageHandler:(id)packageHandler; + (void)setRequestHandler:(id)requestHandler; diff --git a/Adjust/ADJAdjustFactory.m b/Adjust/ADJAdjustFactory.m index 7ef358a45..5a2988a95 100644 --- a/Adjust/ADJAdjustFactory.m +++ b/Adjust/ADJAdjustFactory.m @@ -63,12 +63,19 @@ + (double)subsessionInterval { return intervalSubsessionInterval; } -+ (id)attributionHandlerForActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds{ ++ (id)attributionHandlerForActivityHandler:(id)activityHandler + withMaxDelay:(NSNumber *)milliseconds + withAttributionPackage:(ADJActivityPackage *) attributionPackage +{ if (internalAttributionHandler == nil) { - return [ADJAttributionHandler handlerWithActivityHandler:activityHandler withMaxDelay:milliseconds]; + return [ADJAttributionHandler handlerWithActivityHandler:activityHandler + withMaxDelay:milliseconds + withAttributionPackage:attributionPackage]; } - return [internalAttributionHandler initWithActivityHandler:activityHandler withMaxDelay:milliseconds]; + return [internalAttributionHandler initWithActivityHandler:activityHandler + withMaxDelay:milliseconds + withAttributionPackage:attributionPackage]; } + (void)setPackageHandler:(id)packageHandler { diff --git a/Adjust/ADJAttribution.m b/Adjust/ADJAttribution.m index f77c642f9..95e9bf04b 100644 --- a/Adjust/ADJAttribution.m +++ b/Adjust/ADJAttribution.m @@ -18,7 +18,7 @@ - (id)initWithJsonDict:(NSDictionary *)jsonDict { self = [super init]; if (self == nil) return nil; - if (jsonDict == nil) { + if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) { return nil; } diff --git a/Adjust/ADJAttributionHandler.h b/Adjust/ADJAttributionHandler.h index 0b0f61a16..a93272b97 100644 --- a/Adjust/ADJAttributionHandler.h +++ b/Adjust/ADJAttributionHandler.h @@ -8,10 +8,13 @@ #import #import "ADJActivityHandler.h" +#import "ADJActivityPackage.h" @protocol ADJAttributionHandler -- (id)initWithActivityHandler:(id) activityHandler withMaxDelay:(NSNumber* )milliseconds; +- (id)initWithActivityHandler:(id) activityHandler + withMaxDelay:(NSNumber*) milliseconds + withAttributionPackage:(ADJActivityPackage *) attributionPackage; - (void)checkAttribution:(NSDictionary *)jsonDict; @@ -22,6 +25,8 @@ @interface ADJAttributionHandler : NSObject + (id)handlerWithActivityHandler:(id)activityHandler - withMaxDelay:(NSNumber* )milliseconds; + withMaxDelay:(NSNumber *)milliseconds + withAttributionPackage:(ADJActivityPackage *) attributionPackage; + @end diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index a259686d8..6716f07f8 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -20,9 +20,9 @@ @interface ADJAttributionHandler() @property (nonatomic) dispatch_queue_t internalQueue; @property (nonatomic, assign) id activityHandler; @property (nonatomic, assign) id logger; -@property (nonatomic, retain) NSURL *url; @property (nonatomic, retain) ADJTimer *askInTimer; @property (nonatomic, retain) ADJTimer *maxDelayTimer; +@property (nonatomic, retain) ADJActivityPackage * attributionPackage; @end @@ -30,20 +30,26 @@ @interface ADJAttributionHandler() @implementation ADJAttributionHandler -+ (id)handlerWithActivityHandler:(id)activityHandler withMaxDelay:(NSNumber *)milliseconds{ - return [[ADJAttributionHandler alloc] initWithActivityHandler:activityHandler withMaxDelay:milliseconds]; ++ (id)handlerWithActivityHandler:(id)activityHandler + withMaxDelay:(NSNumber *)milliseconds + withAttributionPackage:(ADJActivityPackage *) attributionPackage; +{ + return [[ADJAttributionHandler alloc] initWithActivityHandler:activityHandler + withMaxDelay:milliseconds + withAttributionPackage:attributionPackage]; } - (id)initWithActivityHandler:(id) activityHandler - withMaxDelay:(NSNumber* )milliseconds{ + withMaxDelay:(NSNumber*) milliseconds + withAttributionPackage:(ADJActivityPackage *) attributionPackage; +{ self = [super init]; if (self == nil) return nil; self.internalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); self.activityHandler = activityHandler; self.logger = ADJAdjustFactory.logger; - self.url = [NSURL URLWithString:ADJUtil.baseUrl]; - //TODO change baseURL + self.attributionPackage = attributionPackage; if (milliseconds != nil) { uint64_t timer_nano = [milliseconds intValue] * NSEC_PER_MSEC; @@ -68,7 +74,7 @@ - (void) getAttribution { #pragma mark - internal -(void) checkAttributionInternal:(NSDictionary *)jsonDict { - if (jsonDict == nil) return; + if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; NSDictionary* jsonAttribution = [jsonDict objectForKey:@"attribution"]; ADJAttribution * attribution = [ADJAttribution dataWithJsonDict:jsonAttribution]; @@ -86,12 +92,16 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { return; }; + [self.logger debug:@"waiting to query attribution in %d milliseconds", [timer_milliseconds intValue]]; + uint64_t timer_nano = [timer_milliseconds intValue] * NSEC_PER_MSEC; self.askInTimer = [ADJTimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self getAttributionInternal]; }]; [self.askInTimer resume]; } -(void) getAttributionInternal { + [self.logger verbose:@"%@", self.attributionPackage.extendedString]; + NSMutableURLRequest *request = [self request]; NSError *requestError; NSURLResponse *urlResponse = nil; @@ -106,26 +116,46 @@ -(void) getAttributionInternal { } NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; - [self.logger verbose:@"attribution response: %@", responseString]; + NSInteger statusCode = ((NSHTTPURLResponse*)urlResponse).statusCode; + [self.logger verbose:@"status code %d for attribution response: %@", statusCode, responseString]; NSDictionary *jsonDict = [ADJUtil buildJsonDict:responseString]; - if (jsonDict == nil) { + if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) { [self.logger error:@"Failed to parse json attribution response: %@", responseString.aiTrim]; return; } + NSString* messageResponse = [jsonDict objectForKey:@"message"]; + + if (statusCode == 200) { + [self.logger info:@"%@", messageResponse]; + } else { + [self.logger error:@"%@", messageResponse]; + } + [self checkAttributionInternal:jsonDict]; } #pragma mark - private - (NSMutableURLRequest *)request { - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.url]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self url]]; request.timeoutInterval = kRequestTimeout; request.HTTPMethod = @"GET"; + [request setValue:self.attributionPackage.clientSdk forHTTPHeaderField:@"Client-Sdk"]; + return request; } +- (NSURL *)url { + NSString * parameters = [ADJUtil queryString:self.attributionPackage.parameters]; + NSString * relativePath = [NSString stringWithFormat:@"%@?%@", self.attributionPackage.path, parameters]; + NSURL * baseUrl = [NSURL URLWithString:ADJUtil.baseUrl]; + NSURL * url = [NSURL URLWithString:relativePath relativeToURL:baseUrl]; + + return url; +} + @end diff --git a/Adjust/ADJPackageBuilder.h b/Adjust/ADJPackageBuilder.h index a1b2d53b0..6cd740f20 100644 --- a/Adjust/ADJPackageBuilder.h +++ b/Adjust/ADJPackageBuilder.h @@ -30,4 +30,6 @@ - (ADJActivityPackage *)buildSessionPackage; - (ADJActivityPackage *)buildEventPackage:(ADJEvent *)event; - (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource; +- (ADJActivityPackage *)buildAttributionPackage; + @end diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 995d1aa6b..dd8c172c0 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -96,6 +96,25 @@ - (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource{ return clickPackage; } +- (ADJActivityPackage *)buildAttributionPackage { + NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; + + [self parameters:parameters setString:self.deviceInfo.macSha1 forKey:@"mac_sha1"]; + [self parameters:parameters setString:self.deviceInfo.idForAdvertisers forKey:@"idfa"]; + [self parameters:parameters setString:self.deviceInfo.vendorId forKey:@"idfv"]; + [self parameters:parameters setString:self.deviceInfo.macShortMd5 forKey:@"mac_md5"]; + [self parameters:parameters setString:self.adjustConfig.appToken forKey:@"app_token"]; + [self parameters:parameters setString:self.adjustConfig.environment forKey:@"environment"]; + [self parameters:parameters setString:self.activityState.uuid forKey:@"ios_uuid"]; + [self parameters:parameters setBool:!self.hasDelegate forKey:@"needs_attribution_data"]; + + ADJActivityPackage *attributionPackage = [self defaultActivityPackage]; + attributionPackage.path = @"/attribution"; + attributionPackage.parameters = parameters; + + return attributionPackage; +} + #pragma mark private - (ADJActivityPackage *)defaultActivityPackage { ADJActivityPackage *activityPackage = [[ADJActivityPackage alloc] init]; diff --git a/Adjust/ADJRequestHandler.m b/Adjust/ADJRequestHandler.m index 6cba08bc6..1365f60e5 100644 --- a/Adjust/ADJRequestHandler.m +++ b/Adjust/ADJRequestHandler.m @@ -11,6 +11,7 @@ #import "ADJUtil.h" #import "NSString+ADJAdditions.h" #import "ADJAdjustFactory.h" +#import "ADJActivityKind.h" static const char * const kInternalQueueName = "io.adjust.RequestQueue"; static const double kRequestTimeout = 60; // 60 seconds @@ -81,19 +82,29 @@ - (void)sendInternal:(ADJActivityPackage *)package sendToPackageHandler:(BOOL)se } NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - [self.logger verbose:@"package response: %@", responseString]; + NSInteger statusCode = response.statusCode; + + [self.logger verbose:@"status code %d for package response: %@", statusCode, responseString]; NSDictionary *jsonDict = [ADJUtil buildJsonDict:responseString]; + + if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) { + NSString * activityKindString = ADJActivityKindToString(package.activityKind); + [self.logger error:@"Failed to parse json %@ response: %@", activityKindString, responseString.aiTrim]; + if (sendToPackageHandler) { + [self.packageHandler closeFirstPackage]; + } + return; + } + NSString* messageResponse = [jsonDict objectForKey:@"message"]; - NSInteger statusCode = response.statusCode; if (statusCode == 200) { - [self.logger info:@"status code %d with message %@", statusCode, messageResponse]; + [self.logger info:@"%@", messageResponse]; } else { - [self.logger error:@"status code %d with message %@", statusCode, messageResponse]; + [self.logger error:@"%@", messageResponse]; } - [self.packageHandler finishedTrackingActivity:jsonDict]; if (sendToPackageHandler) { [self.packageHandler sendNextPackage]; @@ -115,27 +126,13 @@ - (NSMutableURLRequest *)requestForPackage:(ADJActivityPackage *)package { } - (NSData *)bodyForParameters:(NSDictionary *)parameters { - NSMutableArray *pairs = [NSMutableArray array]; - for (NSString *key in parameters) { - NSString *value = [parameters objectForKey:key]; - NSString *escapedValue = [value aiUrlEncode]; - NSString *pair = [NSString stringWithFormat:@"%@=%@", key, escapedValue]; - [pairs addObject:pair]; - } - - double now = [NSDate.date timeIntervalSince1970]; - NSString *dateString = [ADJUtil formatSeconds1970:now]; - NSString *escapedDate = [dateString aiUrlEncode]; - NSString *sentAtPair = [NSString stringWithFormat:@"%@=%@", @"sent_at", escapedDate]; - [pairs addObject:sentAtPair]; - - NSString *bodyString = [pairs componentsJoinedByString:@"&"]; + NSString *bodyString = [ADJUtil queryString:parameters]; NSData *body = [NSData dataWithBytes:bodyString.UTF8String length:bodyString.length]; return body; } - (void) checkMessageResponse:(NSDictionary *)jsonDict { - if (jsonDict == nil) return; + if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; NSString* messageResponse = [jsonDict objectForKey:@"message"]; if (messageResponse != nil) { @@ -144,7 +141,7 @@ - (void) checkMessageResponse:(NSDictionary *)jsonDict { } - (void)checkErrorResponse:(NSDictionary *)jsonDict { - if (jsonDict == nil) return; + if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; NSString* errorResponse = [jsonDict objectForKey:@"error"]; if (errorResponse != nil) { diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index 81b994cf1..965f4baee 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -26,4 +26,5 @@ filename:(NSString *)filename objectName:(NSString *)objectName; ++ (NSString *) queryString:(NSDictionary *)parameters; @end diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 8ccc3bad2..d0aede591 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -161,5 +161,24 @@ + (void)writeObject:(id)object } ++ (NSString *) queryString:(NSDictionary *)parameters { + NSMutableArray *pairs = [NSMutableArray array]; + for (NSString *key in parameters) { + NSString *value = [parameters objectForKey:key]; + NSString *escapedValue = [value aiUrlEncode]; + NSString *pair = [NSString stringWithFormat:@"%@=%@", key, escapedValue]; + [pairs addObject:pair]; + } + + double now = [NSDate.date timeIntervalSince1970]; + NSString *dateString = [ADJUtil formatSeconds1970:now]; + NSString *escapedDate = [dateString aiUrlEncode]; + NSString *sentAtPair = [NSString stringWithFormat:@"%@=%@", @"sent_at", escapedDate]; + [pairs addObject:sentAtPair]; + + NSString *queryString = [pairs componentsJoinedByString:@"&"]; + + return queryString; +} @end diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m index d62986a0e..3613b52f4 100644 --- a/example/example/AppDelegate.m +++ b/example/example/AppDelegate.m @@ -20,7 +20,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // Override point for customization after application launch. [ExampleAdjustHelper initAdjust:self]; - [ExampleAdjustHelper triggerEvent:@"{your event token}"]; + [ExampleAdjustHelper triggerEvent:@"gd6a8u"]; return YES; } diff --git a/example/example/ExampleAdjustHelper.h b/example/example/ExampleAdjustHelper.h index 8be0e399a..18306f438 100644 --- a/example/example/ExampleAdjustHelper.h +++ b/example/example/ExampleAdjustHelper.h @@ -11,7 +11,7 @@ @interface ExampleAdjustHelper : NSObject -+ (void) initAdjust: (id)adjustDelegate; ++ (void) initAdjust: (NSObject *)adjustDelegate; + (void) triggerEvent: (NSString*) eventToken; @end diff --git a/example/example/ExampleAdjustHelper.m b/example/example/ExampleAdjustHelper.m index 6be14eec1..c73b38e7f 100644 --- a/example/example/ExampleAdjustHelper.m +++ b/example/example/ExampleAdjustHelper.m @@ -13,13 +13,13 @@ @implementation ExampleAdjustHelper -+ (void) initAdjust: (id)adjustDelegate { - NSString * yourAppToken = @"{YourAppToken}"; ++ (void) initAdjust: (NSObject *) adjustDelegate { + NSString * yourAppToken = @"dgau42x652ul"; NSString * enviroment = AIEnvironmentSandbox; ADJConfig * adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; // change the log level - //[adjustConfig setLogLevel:ADJLogLevelVerbose]; + [adjustConfig setLogLevel:ADJLogLevelVerbose]; // enable event buffering //[adjustConfig setEventBufferingEnabled:YES]; @@ -28,7 +28,7 @@ + (void) initAdjust: (id)adjustDelegate { //[adjustConfig setMacMd5TrackingEnabled:NO]; // set an attribution delegate - //[adjustConfig setDelegate:adjustDelegate]; + [adjustConfig setDelegate:adjustDelegate]; // set maximum waited to get the attribution //[adjustConfig setAttributionMaxTimeMilliseconds:10000]; From 2caa541aa7f3d9699fc2bd1821d21ca11e54d92c Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 2 Dec 2014 15:20:51 +0100 Subject: [PATCH 22/86] Ask in stored --- Adjust/ADJActivityHandler.h | 3 +- Adjust/ADJActivityHandler.m | 21 ++++++++-- Adjust/ADJActivityState.h | 1 + Adjust/ADJActivityState.m | 8 ++++ Adjust/ADJAdditions/NSString+ADJAdditions.h | 1 + Adjust/ADJAdditions/NSString+ADJAdditions.m | 8 ++++ Adjust/ADJAttribution.h | 2 - Adjust/ADJAttribution.m | 27 ++++-------- Adjust/ADJAttributionHandler.m | 18 +++++--- Adjust/ADJConfig.h | 3 -- Adjust/ADJConfig.m | 5 --- Adjust/ADJTimer.m | 10 ++++- example/example/AppDelegate.m | 2 - example/example/Base.lproj/Main.storyboard | 46 ++++++++++++++++++++- example/example/ExampleAdjustHelper.h | 2 +- example/example/ExampleAdjustHelper.m | 10 +++-- example/example/ViewController.m | 37 +++++++++++++++++ 17 files changed, 154 insertions(+), 50 deletions(-) diff --git a/Adjust/ADJActivityHandler.h b/Adjust/ADJActivityHandler.h index 49c563276..0db560f0e 100644 --- a/Adjust/ADJActivityHandler.h +++ b/Adjust/ADJActivityHandler.h @@ -26,8 +26,9 @@ - (ADJAttribution*) attribution; - (void) setAttribution:(ADJAttribution*)attribution; +- (void) setAskIn:(BOOL)askIn; -- (void) updateAttribution:(ADJAttribution*) attribution; +- (BOOL) updateAttribution:(ADJAttribution*) attribution; - (void) setIadDate:(NSDate*)iAdImpressionDate withPurchaseDate:(NSDate*)appPurchaseDate; - (void) launchAttributionDelegate; diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 7325e0041..3fb3e71a5 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -172,15 +172,17 @@ - (void)setIadDate:(NSDate *)iAdImpressionDate withPurchaseDate:(NSDate *)appPur } } -- (void)updateAttribution:(ADJAttribution *)attribution { +- (BOOL)updateAttribution:(ADJAttribution *)attribution { if (attribution == nil) { - return; + return NO; } if ([attribution isEqual:self.attribution]) { - return; + return NO; } self.attribution = attribution; [ADJUtil writeObject:self.attribution filename:kAttributionFilename objectName:kAttributionName]; + + return YES; } - (void)launchAttributionDelegate{ @@ -210,6 +212,13 @@ - (void) addPermanentPartnerParameter:(NSString *)key [self.adjustConfig addPermanentPartnerParameter:key andValue:value]; } +- (void) setAskIn:(BOOL)askIn { + self.activityState.askIn = askIn; + [ADJUtil writeObject:self.activityState + filename:kActivityStateFilename + objectName:kActivityStateName]; +} + #pragma mark - internal - (void)initInternal:(ADJConfig *)adjustConfig { self.adjustConfig = adjustConfig; @@ -256,7 +265,7 @@ - (void)initInternal:(ADJConfig *)adjustConfig { andConfig:self.adjustConfig]; ADJActivityPackage * attributionPackage = [attributionBuilder buildAttributionPackage]; self.attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self - withMaxDelay:adjustConfig.attributionMaxTimeMilliseconds + withMaxDelay:nil withAttributionPackage:attributionPackage]; self.attribution = [ADJUtil readObject:kAttributionFilename objectName:kAttributionName]; @@ -320,6 +329,10 @@ - (void)startInternal { self.activityState.subsessionCount, self.activityState.sessionCount]; } + + if (self.activityState.askIn) { + [self.attributionHandler getAttribution]; + } } - (void)endInternal { diff --git a/Adjust/ADJActivityState.h b/Adjust/ADJActivityState.h index 64e04d568..15d7caacd 100644 --- a/Adjust/ADJActivityState.h +++ b/Adjust/ADJActivityState.h @@ -12,6 +12,7 @@ // persistent data @property (nonatomic, copy) NSString *uuid; @property (nonatomic, assign) BOOL enabled; +@property (nonatomic, assign) BOOL askIn; // global counters @property (nonatomic, assign) int eventCount; diff --git a/Adjust/ADJActivityState.m b/Adjust/ADJActivityState.m index 94a2ebf6c..9e18ad985 100644 --- a/Adjust/ADJActivityState.m +++ b/Adjust/ADJActivityState.m @@ -31,6 +31,7 @@ - (id)init { self.lastInterval = -1; self.transactionIds = [NSMutableArray arrayWithCapacity:kTransactionIdCount]; self.enabled = YES; + self.askIn = NO; return self; } @@ -82,6 +83,7 @@ - (id)initWithCoder:(NSCoder *)decoder { self.uuid = [decoder decodeObjectForKey:@"uuid"]; self.transactionIds = [decoder decodeObjectForKey:@"transactionIds"]; self.enabled = [decoder decodeBoolForKey:@"enabled"]; + self.askIn = [decoder decodeBoolForKey:@"askAttribution"]; // create UUID for migrating devices if (self.uuid == nil) { @@ -96,6 +98,10 @@ - (id)initWithCoder:(NSCoder *)decoder { self.enabled = YES; } + if (![decoder containsValueForKey:@"askAttribution"]) { + self.askIn = NO; + } + self.lastInterval = -1; return self; @@ -112,6 +118,7 @@ - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:self.uuid forKey:@"uuid"]; [encoder encodeObject:self.transactionIds forKey:@"transactionIds"]; [encoder encodeBool:self.enabled forKey:@"enabled"]; + [encoder encodeBool:self.askIn forKey:@"askAttribution"]; } -(id)copyWithZone:(NSZone *)zone @@ -128,6 +135,7 @@ -(id)copyWithZone:(NSZone *)zone copy.eventCount = self.eventCount; copy.enabled = self.enabled; copy.lastActivity = self.lastActivity; + copy.askIn = self.askIn; // transactionIds not copied } diff --git a/Adjust/ADJAdditions/NSString+ADJAdditions.h b/Adjust/ADJAdditions/NSString+ADJAdditions.h index 9829d4fb4..09271fe0f 100644 --- a/Adjust/ADJAdditions/NSString+ADJAdditions.h +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.h @@ -17,5 +17,6 @@ - (NSString *)aiRemoveColons; + (NSString *)aiJoin:(NSString *)strings, ...; ++ (BOOL) adjIsEqual:(NSString *)first toString:(NSString *)second; @end diff --git a/Adjust/ADJAdditions/NSString+ADJAdditions.m b/Adjust/ADJAdditions/NSString+ADJAdditions.m index 337bc5ec2..ed07f3833 100644 --- a/Adjust/ADJAdditions/NSString+ADJAdditions.m +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.m @@ -79,4 +79,12 @@ + (NSString *)aiJoin:(NSString *)first, ... { return result; } ++ (BOOL) adjIsEqual:(NSString *)first toString:(NSString *)second { + if (first == nil && second == nil) { + return YES; + } + + return [first isEqualToString:second]; +} + @end diff --git a/Adjust/ADJAttribution.h b/Adjust/ADJAttribution.h index 9d4ca45c7..3e51f7b2b 100644 --- a/Adjust/ADJAttribution.h +++ b/Adjust/ADJAttribution.h @@ -31,8 +31,6 @@ // tracker creative @property (nonatomic, copy) NSString *creative; -@property (nonatomic, assign) BOOL finalAttribution; - - (BOOL)isEqualToAttribution:(ADJAttribution *)attribution; + (ADJAttribution *)dataWithJsonDict:(NSDictionary *)jsonDict; diff --git a/Adjust/ADJAttribution.m b/Adjust/ADJAttribution.m index 95e9bf04b..edf2252a3 100644 --- a/Adjust/ADJAttribution.m +++ b/Adjust/ADJAttribution.m @@ -7,6 +7,7 @@ // #import "ADJAttribution.h" +#import "NSString+ADJAdditions.h" @implementation ADJAttribution @@ -28,9 +29,6 @@ - (id)initWithJsonDict:(NSDictionary *)jsonDict { self.campaign = [jsonDict objectForKey:@"campaign"]; self.adgroup = [jsonDict objectForKey:@"adgroup"]; self.creative = [jsonDict objectForKey:@"creative"]; - if ([[jsonDict objectForKey:@"final"] isEqualToString:@"true"]) { - self.finalAttribution = YES; - } return self; } @@ -39,27 +37,25 @@ - (BOOL)isEqualToAttribution:(ADJAttribution *)attribution { if (attribution == nil) { return NO; } - if (![self.trackerToken isEqualToString:attribution.trackerToken]) { - return NO; - } - if (![self.trackerName isEqualToString:attribution.trackerName]) { + if (![NSString adjIsEqual:self.trackerToken toString:attribution.trackerToken]) { return NO; } - if (![self.network isEqualToString:attribution.network]) { + if (![NSString adjIsEqual:self.trackerName toString:attribution.trackerName]) { return NO; } - if (![self.campaign isEqualToString:attribution.campaign]) { + if (![NSString adjIsEqual:self.network toString:attribution.network]) { return NO; } - if (![self.adgroup isEqualToString:attribution.adgroup]) { + if (![NSString adjIsEqual:self.campaign toString:attribution.campaign]) { return NO; } - if (![self.creative isEqualToString:attribution.creative]) { + if (![NSString adjIsEqual:self.adgroup toString:attribution.adgroup]) { return NO; } - if (self.finalAttribution != attribution.finalAttribution) { + if (![NSString adjIsEqual:self.creative toString:attribution.creative]) { return NO; } + return YES; } @@ -90,8 +86,6 @@ - (NSDictionary *)dictionary { [responseDataDic setObject:self.creative forKey:@"creative"]; } - [responseDataDic setObject:(self.finalAttribution? @"true" : @"false") forKey:@"final"]; - return responseDataDic; } @@ -125,7 +119,6 @@ - (NSUInteger)hash { result = prime * result + [self.campaign hash]; result = prime * result + [self.adgroup hash]; result = prime * result + [self.creative hash]; - result = prime * result + self.finalAttribution; return result; } @@ -142,9 +135,6 @@ - (id)initWithCoder:(NSCoder *)decoder { self.campaign = [decoder decodeObjectForKey:@"campaign"]; self.adgroup = [decoder decodeObjectForKey:@"adgroup"]; self.creative = [decoder decodeObjectForKey:@"creative"]; - if ([[decoder decodeObjectForKey:@"final"] isEqualToString:@"true"]) { - self.finalAttribution = YES; - } return self; } @@ -156,7 +146,6 @@ - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:self.campaign forKey:@"campaign"]; [encoder encodeObject:self.adgroup forKey:@"adgroup"]; [encoder encodeObject:self.creative forKey:@"creative"]; - [encoder encodeObject:(self.finalAttribution? @"true" : @"false") forKey:@"final"]; } @end diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 6716f07f8..d1746fa60 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -81,17 +81,23 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { NSNumber * timer_milliseconds = [jsonDict objectForKey:@"ask_in"]; - if (attribution != nil && timer_milliseconds == nil) { - attribution.finalAttribution = YES; - } + if (timer_milliseconds == nil) { + BOOL updated = [self.activityHandler updateAttribution:attribution]; - [self.activityHandler updateAttribution:attribution]; + if (updated) { + [self.activityHandler launchAttributionDelegate]; + } + + [self.activityHandler setAskIn:NO]; - if (timer_milliseconds == nil) { - [self.activityHandler launchAttributionDelegate]; return; }; + [self.activityHandler setAskIn:YES]; + if (self.askInTimer != nil) { + [self.askInTimer suspend]; + } + [self.logger debug:@"waiting to query attribution in %d milliseconds", [timer_milliseconds intValue]]; uint64_t timer_nano = [timer_milliseconds intValue] * NSEC_PER_MSEC; diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index 4e917c351..d536a061d 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -37,7 +37,6 @@ @property (nonatomic, copy) NSMutableDictionary* callbackPermanentParameters; @property (nonatomic, copy) NSMutableDictionary* partnerPermanentParameters; @property (nonatomic, retain) NSObject *delegate; -@property (nonatomic, copy) NSNumber* attributionMaxTimeMilliseconds; - (id)initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; + (ADJConfig*)configWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; @@ -48,6 +47,4 @@ - (void)addPermanentPartnerParameter:(NSString *)key andValue:(NSString *)value; -- (void)setAttributionMaxTime:(int)milliseconds; - @end diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index 282deca7c..31432b36c 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -54,10 +54,6 @@ - (void) addPermanentPartnerParameter:(NSString *)key [_partnerPermanentParameters setObject:value forKey:key]; } -- (void) setAttributionMaxTime:(int)milliseconds { - self.attributionMaxTimeMilliseconds = [NSNumber numberWithInt:milliseconds]; -} - - (BOOL) checkEnvironment:(NSString *)environment { id logger = ADJAdjustFactory.logger; @@ -93,7 +89,6 @@ -(id)copyWithZone:(NSZone *)zone copy.callbackPermanentParameters = [self.callbackPermanentParameters copyWithZone:zone]; copy.partnerPermanentParameters = [self.partnerPermanentParameters copyWithZone:zone]; // adjust delegate not copied - copy.attributionMaxTimeMilliseconds = [self.attributionMaxTimeMilliseconds copyWithZone:zone]; } return copy; diff --git a/Adjust/ADJTimer.m b/Adjust/ADJTimer.m index e63777da6..37588b7b9 100644 --- a/Adjust/ADJTimer.m +++ b/Adjust/ADJTimer.m @@ -43,7 +43,10 @@ - (id)initWithInterval:(uint64_t)interval self.source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); if (self.source != nil) { - dispatch_source_set_timer(self.source, dispatch_walltime(NULL, 0), interval, leeway); + dispatch_source_set_timer(self.source, + dispatch_time(DISPATCH_TIME_NOW, interval), + interval, + leeway); dispatch_source_set_event_handler(self.source, block); } self.suspended = YES; @@ -58,7 +61,10 @@ - (id)initWithStart:(uint64_t)start leeway:(uint64_t)leeway queue:(dispatch_queu self.source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); if (self.source != nil) { - dispatch_source_set_timer(self.source, dispatch_walltime(NULL, start), DISPATCH_TIME_FOREVER, leeway); + dispatch_source_set_timer(self.source, + dispatch_time(DISPATCH_TIME_NOW, start), + DISPATCH_TIME_FOREVER, + leeway); dispatch_source_set_event_handler(self.source, block); } self.suspended = YES; diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m index 3613b52f4..f06d29dd6 100644 --- a/example/example/AppDelegate.m +++ b/example/example/AppDelegate.m @@ -19,8 +19,6 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [ExampleAdjustHelper initAdjust:self]; - - [ExampleAdjustHelper triggerEvent:@"gd6a8u"]; return YES; } diff --git a/example/example/Base.lproj/Main.storyboard b/example/example/Base.lproj/Main.storyboard index bebd9f514..e9454e8b3 100644 --- a/example/example/Base.lproj/Main.storyboard +++ b/example/example/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -15,8 +15,52 @@ + + + + + + + + + + + + diff --git a/example/example/ExampleAdjustHelper.h b/example/example/ExampleAdjustHelper.h index 18306f438..19c99cc9a 100644 --- a/example/example/ExampleAdjustHelper.h +++ b/example/example/ExampleAdjustHelper.h @@ -13,5 +13,5 @@ + (void) initAdjust: (NSObject *)adjustDelegate; -+ (void) triggerEvent: (NSString*) eventToken; ++ (void) triggerEvent; @end diff --git a/example/example/ExampleAdjustHelper.m b/example/example/ExampleAdjustHelper.m index c73b38e7f..7a55cdda3 100644 --- a/example/example/ExampleAdjustHelper.m +++ b/example/example/ExampleAdjustHelper.m @@ -11,10 +11,12 @@ #import "ADJLogger.h" #import "ADJEvent.h" +static NSString * const appToken = @"dgau42x652ul"; + @implementation ExampleAdjustHelper + (void) initAdjust: (NSObject *) adjustDelegate { - NSString * yourAppToken = @"dgau42x652ul"; + NSString * yourAppToken = appToken; NSString * enviroment = AIEnvironmentSandbox; ADJConfig * adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; @@ -43,12 +45,12 @@ + (void) initAdjust: (NSObject *) adjustDelegate { [adjust appDidLaunch:adjustConfig]; } -+ (void) triggerEvent: (NSString*) eventToken { ++ (void) triggerEvent { - ADJEvent * event = [ADJEvent eventWithEventToken:eventToken]; + ADJEvent * event = [ADJEvent eventWithEventToken:@"gd6a8u"]; // add revenue 1 cent of an euro - //[event setRevenue:0.01 currency:@"EUR"]; + [event setRevenue:0.01 currency:@"EUR"]; // add callback parameters to this parameter //[event addCallbackParameter:@"key" andValue:@"value"]; diff --git a/example/example/ViewController.m b/example/example/ViewController.m index a3447534e..e23ff199d 100644 --- a/example/example/ViewController.m +++ b/example/example/ViewController.m @@ -7,9 +7,16 @@ // #import "ViewController.h" +#import "Adjust.h" +#import "ExampleAdjustHelper.h" @interface ViewController () +@property (weak, nonatomic) IBOutlet UIButton *btnTrackEvent; +@property (weak, nonatomic) IBOutlet UIButton *btnDisableSdk; +@property (weak, nonatomic) IBOutlet UIButton *btnSetOfflineMode; +@property (weak, nonatomic) IBOutlet UIButton *btnSetOnlineMode; + @end @implementation ViewController @@ -17,11 +24,41 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. + + BOOL isEnabled = [Adjust isEnabled]; + if (!isEnabled) { + [self.btnDisableSdk setTitle:@"Enable SDK" forState:UIControlStateNormal]; + } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } +- (IBAction)clickTrackEvent:(UIButton *)sender { + [ExampleAdjustHelper triggerEvent]; +} +- (IBAction)clickDisableSdk:(UIButton *)sender { + NSString * txtDisableSdk = self.btnDisableSdk.titleLabel.text; + + if ([txtDisableSdk hasPrefix:@"Disable"]) { + [Adjust setEnabled:NO]; + } else { + [Adjust setEnabled:YES]; + } + + BOOL isEnabled = [Adjust isEnabled]; + if (!isEnabled) { + [self.btnDisableSdk setTitle:@"Enable SDK" forState:UIControlStateNormal]; + } else { + [self.btnDisableSdk setTitle:@"Disable SDK" forState:UIControlStateNormal]; + } +} +- (IBAction)clickSetOfflineMode:(UIButton *)sender { + [Adjust setOfflineMode:YES]; +} +- (IBAction)clickSetOnlineMode:(UIButton *)sender { + [Adjust setOfflineMode:NO]; +} @end From f1a53e33bc199d573960f1bc389e32a5c89f4cca Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 2 Dec 2014 16:56:15 +0100 Subject: [PATCH 23/86] Remove permanent parameters --- Adjust/ADJActivityHandler.h | 6 ------ Adjust/ADJActivityHandler.m | 22 ++++++++------------- Adjust/ADJActivityState.m | 10 +++++----- Adjust/ADJAttributionHandler.m | 2 +- Adjust/ADJConfig.h | 8 -------- Adjust/ADJConfig.m | 20 ------------------- Adjust/ADJPackageBuilder.m | 16 ++++++--------- Adjust/ADJTimer.h | 1 + Adjust/ADJTimer.m | 11 ++++++----- Adjust/ADJUtil.h | 3 ++- Adjust/ADJUtil.m | 6 ++++-- Adjust/Adjust.h | 12 ------------ Adjust/Adjust.m | 28 --------------------------- example/example/ExampleAdjustHelper.m | 12 +++--------- 14 files changed, 36 insertions(+), 121 deletions(-) diff --git a/Adjust/ADJActivityHandler.h b/Adjust/ADJActivityHandler.h index 0db560f0e..bf578ffbd 100644 --- a/Adjust/ADJActivityHandler.h +++ b/Adjust/ADJActivityHandler.h @@ -35,12 +35,6 @@ - (void) setOfflineMode:(BOOL)enabled; -- (void)addPermanentCallbackParameter:(NSString *)key - andValue:(NSString *)value; - -- (void)addPermanentPartnerParameter:(NSString *)key - andValue:(NSString *)value; - @end @interface ADJActivityHandler : NSObject diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 3fb3e71a5..5f59463e5 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -126,7 +126,7 @@ - (void)launchDeepLink:(NSDictionary *)jsonDict{ - (void)setEnabled:(BOOL)enabled { _enabled = enabled; - if ([self checkActivityState:self.activityState]) { + if (self.activityState != nil) { self.activityState.enabled = enabled; [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; } @@ -138,7 +138,7 @@ - (void)setEnabled:(BOOL)enabled { } - (BOOL)isEnabled { - if ([self checkActivityState:self.activityState]) { + if (self.activityState != nil) { return self.activityState.enabled; } else { return _enabled; @@ -202,16 +202,6 @@ - (void)setOfflineMode:(BOOL)enabled { } } -- (void) addPermanentCallbackParameter:(NSString *)key - andValue:(NSString *)value { - [self.adjustConfig addPermanentCallbackParameter:key andValue:value]; -} - -- (void) addPermanentPartnerParameter:(NSString *)key - andValue:(NSString *)value { - [self.adjustConfig addPermanentPartnerParameter:key andValue:value]; -} - - (void) setAskIn:(BOOL)askIn { self.activityState.askIn = askIn; [ADJUtil writeObject:self.activityState @@ -257,7 +247,9 @@ - (void)initInternal:(ADJConfig *)adjustConfig { [[UIDevice currentDevice] adjSetIad:self]; - self.activityState = [ADJUtil readObject:kActivityStateFilename objectName:kActivityStateName]; + self.activityState = [ADJUtil readObject:kActivityStateFilename + objectName:kActivityStateName + class:[ADJActivityState class]]; self.packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:self]; ADJPackageBuilder * attributionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo @@ -268,7 +260,9 @@ - (void)initInternal:(ADJConfig *)adjustConfig { withMaxDelay:nil withAttributionPackage:attributionPackage]; - self.attribution = [ADJUtil readObject:kAttributionFilename objectName:kAttributionName]; + self.attribution = [ADJUtil readObject:kAttributionFilename + objectName:kAttributionName + class:[ADJAttribution class]]; [self startInternal]; } diff --git a/Adjust/ADJActivityState.m b/Adjust/ADJActivityState.m index 9e18ad985..c428ee882 100644 --- a/Adjust/ADJActivityState.m +++ b/Adjust/ADJActivityState.m @@ -31,7 +31,7 @@ - (id)init { self.lastInterval = -1; self.transactionIds = [NSMutableArray arrayWithCapacity:kTransactionIdCount]; self.enabled = YES; - self.askIn = NO; + self.askIn = NO; return self; } @@ -83,7 +83,7 @@ - (id)initWithCoder:(NSCoder *)decoder { self.uuid = [decoder decodeObjectForKey:@"uuid"]; self.transactionIds = [decoder decodeObjectForKey:@"transactionIds"]; self.enabled = [decoder decodeBoolForKey:@"enabled"]; - self.askIn = [decoder decodeBoolForKey:@"askAttribution"]; + self.askIn = [decoder decodeBoolForKey:@"askIn"]; // create UUID for migrating devices if (self.uuid == nil) { @@ -98,7 +98,7 @@ - (id)initWithCoder:(NSCoder *)decoder { self.enabled = YES; } - if (![decoder containsValueForKey:@"askAttribution"]) { + if (![decoder containsValueForKey:@"askIn"]) { self.askIn = NO; } @@ -118,7 +118,7 @@ - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:self.uuid forKey:@"uuid"]; [encoder encodeObject:self.transactionIds forKey:@"transactionIds"]; [encoder encodeBool:self.enabled forKey:@"enabled"]; - [encoder encodeBool:self.askIn forKey:@"askAttribution"]; + [encoder encodeBool:self.askIn forKey:@"askIn"]; } -(id)copyWithZone:(NSZone *)zone @@ -135,7 +135,7 @@ -(id)copyWithZone:(NSZone *)zone copy.eventCount = self.eventCount; copy.enabled = self.enabled; copy.lastActivity = self.lastActivity; - copy.askIn = self.askIn; + copy.askIn = self.askIn; // transactionIds not copied } diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index d1746fa60..382aeff51 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -95,7 +95,7 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { [self.activityHandler setAskIn:YES]; if (self.askInTimer != nil) { - [self.askInTimer suspend]; + [self.askInTimer cancel]; } [self.logger debug:@"waiting to query attribution in %d milliseconds", [timer_milliseconds intValue]]; diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index d536a061d..fc1cfa060 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -34,17 +34,9 @@ @property (nonatomic, copy) NSString *sdkPrefix; @property (nonatomic, assign) BOOL eventBufferingEnabled; @property (nonatomic, assign) BOOL macMd5TrackingEnabled; -@property (nonatomic, copy) NSMutableDictionary* callbackPermanentParameters; -@property (nonatomic, copy) NSMutableDictionary* partnerPermanentParameters; @property (nonatomic, retain) NSObject *delegate; - (id)initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; + (ADJConfig*)configWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; -- (void)addPermanentCallbackParameter:(NSString *)key - andValue:(NSString *)value; - -- (void)addPermanentPartnerParameter:(NSString *)key - andValue:(NSString *)value; - @end diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index 31432b36c..e708387dd 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -36,24 +36,6 @@ - (id) initWithAppToken:(NSString *)appToken return self; } -- (void) addPermanentCallbackParameter:(NSString *)key - andValue:(NSString *)value { - if (_callbackPermanentParameters == nil) { - _callbackPermanentParameters = [[NSMutableDictionary alloc] init]; - } - - [_callbackPermanentParameters setObject:value forKey:key]; -} - -- (void) addPermanentPartnerParameter:(NSString *)key - andValue:(NSString *)value { - if (_partnerPermanentParameters == nil) { - _partnerPermanentParameters = [[NSMutableDictionary alloc] init]; - } - - [_partnerPermanentParameters setObject:value forKey:key]; -} - - (BOOL) checkEnvironment:(NSString *)environment { id logger = ADJAdjustFactory.logger; @@ -86,8 +68,6 @@ -(id)copyWithZone:(NSZone *)zone copy.sdkPrefix = [self.environment copyWithZone:zone]; copy.eventBufferingEnabled = self.eventBufferingEnabled; copy.macMd5TrackingEnabled = self.macMd5TrackingEnabled; - copy.callbackPermanentParameters = [self.callbackPermanentParameters copyWithZone:zone]; - copy.partnerPermanentParameters = [self.partnerPermanentParameters copyWithZone:zone]; // adjust delegate not copied } diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index dd8c172c0..9e36a1d06 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -37,8 +37,6 @@ - (id)initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo - (ADJActivityPackage *)buildSessionPackage { NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"callback_params"]; - [self parameters:parameters setDictionaryJson:self.adjustConfig.callbackPermanentParameters forKey:@"callback_params"]; - [self parameters:parameters setDictionaryJson:self.adjustConfig.partnerPermanentParameters forKey:@"partner_params"]; ADJActivityPackage *sessionPackage = [self defaultActivityPackage]; sessionPackage.path = @"/startup"; @@ -57,12 +55,8 @@ - (ADJActivityPackage *)buildEventPackage:(ADJEvent *) event{ [self parameters:parameters setString:event.currency forKey:@"currency"]; [self parameters:parameters setString:event.eventToken forKey:@"event_token"]; - // join the permanent parameters with the ones from the event - NSMutableDictionary * callbackParameters = [self joinParamters:self.adjustConfig.callbackPermanentParameters parameters:event.callbackParameters]; - [self parameters:parameters setDictionaryJson:callbackParameters forKey:@"callback_params"]; - - NSMutableDictionary * partnerParamters = [self joinParamters:self.adjustConfig.partnerPermanentParameters parameters:event.partnerParameters]; - [self parameters:parameters setDictionaryJson:partnerParamters forKey:@"partner_params"]; + [self parameters:parameters setDictionaryJson:event.callbackParameters forKey:@"callback_params"]; + [self parameters:parameters setDictionaryJson:event.partnerParameters forKey:@"partner_params"]; ADJActivityPackage *eventPackage = [self defaultActivityPackage]; eventPackage.path = @"/event"; @@ -265,9 +259,11 @@ - (NSMutableDictionary *) joinParamters:(NSMutableDictionary *)permanentParamete if (parameters == nil) { return permanentParameters; } - [permanentParameters addEntriesFromDictionary:parameters]; - return permanentParameters; + NSMutableDictionary * joinedParameters = [[NSMutableDictionary alloc] initWithDictionary:permanentParameters]; + [joinedParameters addEntriesFromDictionary:parameters]; + + return joinedParameters; } @end diff --git a/Adjust/ADJTimer.h b/Adjust/ADJTimer.h index d96976bab..1e351f839 100644 --- a/Adjust/ADJTimer.h +++ b/Adjust/ADJTimer.h @@ -31,5 +31,6 @@ - (void)resume; - (void)suspend; +- (void)cancel; @end diff --git a/Adjust/ADJTimer.m b/Adjust/ADJTimer.m index 37588b7b9..92b94c5cf 100644 --- a/Adjust/ADJTimer.m +++ b/Adjust/ADJTimer.m @@ -44,7 +44,7 @@ - (id)initWithInterval:(uint64_t)interval self.source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); if (self.source != nil) { dispatch_source_set_timer(self.source, - dispatch_time(DISPATCH_TIME_NOW, interval), + dispatch_walltime(NULL, interval), interval, leeway); dispatch_source_set_event_handler(self.source, block); @@ -61,10 +61,7 @@ - (id)initWithStart:(uint64_t)start leeway:(uint64_t)leeway queue:(dispatch_queu self.source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); if (self.source != nil) { - dispatch_source_set_timer(self.source, - dispatch_time(DISPATCH_TIME_NOW, start), - DISPATCH_TIME_FOREVER, - leeway); + dispatch_source_set_timer(self.source, dispatch_walltime(NULL, start), DISPATCH_TIME_FOREVER, leeway); dispatch_source_set_event_handler(self.source, block); } self.suspended = YES; @@ -86,4 +83,8 @@ - (void)suspend { self.suspended = YES; } +- (void)cancel { + dispatch_source_cancel(self.source); +} + @end diff --git a/Adjust/ADJUtil.h b/Adjust/ADJUtil.h index 965f4baee..76fc47b0d 100644 --- a/Adjust/ADJUtil.h +++ b/Adjust/ADJUtil.h @@ -20,7 +20,8 @@ + (NSString *)getFullFilename:(NSString *) baseFilename; + (id)readObject:(NSString *)filename - objectName:(NSString *)objectName; + objectName:(NSString *)objectName + class:(Class) classToRead; + (void)writeObject:(id)object filename:(NSString *)filename diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index d0aede591..0417ead0a 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -126,12 +126,14 @@ + (NSString *)getFullFilename:(NSString *) baseFilename { } + (id)readObject:(NSString *)filename - objectName:(NSString *)objectName{ + objectName:(NSString *)objectName + class:(Class) classToRead +{ id logger = [ADJAdjustFactory logger]; @try { NSString *fullFilename = [ADJUtil getFullFilename:filename]; id object = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFilename]; - if ([object isKindOfClass:[ADJAttribution class]]) { + if ([object isKindOfClass:classToRead]) { [logger debug:@"Read %@: %@", objectName, object]; return object; } else if (object == nil) { diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index eada857ac..19d1f1c40 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -97,12 +97,6 @@ static NSString * const AIEnvironmentProduction = @"production"; + (void)setOfflineMode:(BOOL)enabled; -+ (void)addPermanentCallbackParameter:(NSString *)key - andValue:(NSString *)value; - -+ (void)addPermanentPartnerParameter:(NSString *)key - andValue:(NSString *)value; - + (id)getInstance; - (void)appDidLaunch:(ADJConfig *)adjustConfig; @@ -116,11 +110,5 @@ static NSString * const AIEnvironmentProduction = @"production"; - (void)setDeviceToken:(NSData *)deviceToken; - (void)setOfflineMode:(BOOL)enabled; -- (void)addPermanentCallbackParameter:(NSString *)key - andValue:(NSString *)value; - -- (void)addPermanentPartnerParameter:(NSString *)key - andValue:(NSString *)value; - @end diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index 7a37acc6a..e55f661d4 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -69,20 +69,6 @@ + (void)setOfflineMode:(BOOL)enabled { [defaultInstance setOfflineMode:enabled]; } -+ (void)addPermanentCallbackParameter:(NSString *)key - andValue:(NSString *)value { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance addPermanentCallbackParameter:key andValue:value]; -} - -+ (void)addPermanentPartnerParameter:(NSString *)key - andValue:(NSString *)value { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance addPermanentPartnerParameter:key andValue:value]; - -} - - + (id)getInstance { static Adjust * defaultInstance = nil; static dispatch_once_t onceToken; @@ -152,20 +138,6 @@ - (void)setOfflineMode:(BOOL)enabled { [self.activityHandler setOfflineMode:enabled]; } -- (void)addPermanentCallbackParameter:(NSString *)key - andValue:(NSString *)value { - if (![self checkActivityHandler]) return; - [self.activityHandler addPermanentCallbackParameter:key andValue:value]; -} - -- (void)addPermanentPartnerParameter:(NSString *)key - andValue:(NSString *)value { - if (![self checkActivityHandler]) return; - [self.activityHandler addPermanentPartnerParameter:key andValue:value]; - -} - - #pragma mark - private - (BOOL) checkActivityHandler { diff --git a/example/example/ExampleAdjustHelper.m b/example/example/ExampleAdjustHelper.m index 7a55cdda3..ed85b87f1 100644 --- a/example/example/ExampleAdjustHelper.m +++ b/example/example/ExampleAdjustHelper.m @@ -35,12 +35,6 @@ + (void) initAdjust: (NSObject *) adjustDelegate { // set maximum waited to get the attribution //[adjustConfig setAttributionMaxTimeMilliseconds:10000]; - // add callback parameters to all events and sessions - //[adjustConfig addPermanentCallbackParameter:@"key" andValue:@"value"]; - - // add partner parameteres to all events and sessions - //[adjustConfig addPermanentPartnerParameter:@"foo" andValue:@"bar"]; - Adjust * adjust = [Adjust getInstance]; [adjust appDidLaunch:adjustConfig]; } @@ -50,13 +44,13 @@ + (void) triggerEvent { ADJEvent * event = [ADJEvent eventWithEventToken:@"gd6a8u"]; // add revenue 1 cent of an euro - [event setRevenue:0.01 currency:@"EUR"]; + [event setRevenue:0.015 currency:@"EUR"]; // add callback parameters to this parameter - //[event addCallbackParameter:@"key" andValue:@"value"]; + [event addCallbackParameter:@"keyEvent" andValue:@"value"]; // add partner parameteres to all events and sessions - //[event addPartnerParameter:@"foo" andValue:@"bar"]; + [event addPartnerParameter:@"fooEvent" andValue:@"bar"]; Adjust * adjust = [Adjust getInstance]; [adjust trackEvent:event]; From 15394ba54d8ef61f579b00c5d95eed95b7e2204d Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 2 Dec 2014 17:31:18 +0100 Subject: [PATCH 24/86] Timer cancel --- Adjust/ADJActivityHandler.m | 6 ++++-- Adjust/ADJAttributionHandler.h | 2 ++ Adjust/ADJAttributionHandler.m | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 5f59463e5..90fa720e8 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -324,8 +324,10 @@ - (void)startInternal { self.activityState.sessionCount]; } - if (self.activityState.askIn) { - [self.attributionHandler getAttribution]; + if (self.attribution == nil || self.activityState.askIn) { + if (![self.attributionHandler isWaitingInAskIn]) { + [self.attributionHandler getAttribution]; + } } } diff --git a/Adjust/ADJAttributionHandler.h b/Adjust/ADJAttributionHandler.h index a93272b97..6776c994e 100644 --- a/Adjust/ADJAttributionHandler.h +++ b/Adjust/ADJAttributionHandler.h @@ -20,6 +20,8 @@ - (void)getAttribution; +- (BOOL)isWaitingInAskIn; + @end @interface ADJAttributionHandler : NSObject diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 382aeff51..4a42a272c 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -72,6 +72,10 @@ - (void) getAttribution { }); } +- (BOOL) isWaitingInAskIn { + return self.askInTimer != nil; +} + #pragma mark - internal -(void) checkAttributionInternal:(NSDictionary *)jsonDict { if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; @@ -107,6 +111,10 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { -(void) getAttributionInternal { [self.logger verbose:@"%@", self.attributionPackage.extendedString]; + if (self.askInTimer != nil) { + [self.askInTimer cancel]; + self.askInTimer = nil; + } NSMutableURLRequest *request = [self request]; NSError *requestError; From db445bf261fb13128f0e0496951aea76ae362b8e Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 3 Dec 2014 15:16:18 +0100 Subject: [PATCH 25/86] Revenue parameter --- Adjust/ADJPackageBuilder.m | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 9e36a1d06..fbf6e5e30 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -50,8 +50,7 @@ - (ADJActivityPackage *)buildSessionPackage { - (ADJActivityPackage *)buildEventPackage:(ADJEvent *) event{ NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setInt:self.activityState.eventCount forKey:@"event_count"]; - NSString * amountString = [self amountString:event]; - [self parameters:parameters setString:amountString forKey:@"amount"]; + [self parameters:parameters setNumber:event.revenue forKey:@"revenue"]; [self parameters:parameters setString:event.currency forKey:@"currency"]; [self parameters:parameters setString:event.eventToken forKey:@"event_token"]; @@ -173,18 +172,6 @@ - (void) constructUserAgent:(ADJUserAgent *)userAgent [self parameters:parameters setString:userAgent.mobileNetworkCode forKey:@"mobile_network_code"]; } - -- (NSString *)amountString:(ADJEvent*)event { - if (event.revenue == nil || [event.revenue doubleValue] == 0) { - return nil; - } - double revenue = [event.revenue doubleValue]; - int amountInMillis = round(1000 * revenue); - event.revenue = [NSNumber numberWithDouble:(amountInMillis / 1000.0)]; // now rounded to one decimal point - NSString *amountString = [NSNumber numberWithInt:amountInMillis].stringValue; - return amountString; -} - - (NSString *)eventSuffix:(ADJEvent*)event { if (event.revenue == nil) { return [NSString stringWithFormat:@" '%@'", event.eventToken]; @@ -244,13 +231,22 @@ - (void)parameters:(NSMutableDictionary *)parameters setBool:(BOOL)value forKey: } - (void)parameters:(NSMutableDictionary *)parameters setNumberBool:(NSNumber *)value forKey:(NSString *)key { - if (value == nil); + if (value == nil) return; BOOL boolValue = [value boolValue]; [self parameters:parameters setBool:boolValue forKey:key]; } +- (void)parameters:(NSMutableDictionary *)parameters setNumber:(NSNumber *)value forKey:(NSString *)key { + if (value == nil); + + NSString * numberString = [value stringValue]; + + [self parameters:parameters setString:numberString forKey:key]; +} + + - (NSMutableDictionary *) joinParamters:(NSMutableDictionary *)permanentParameters parameters:(NSMutableDictionary *)parameters { if (permanentParameters == nil) { From 9dd578b11a0d13839994a4ee5f84b06eb3c791f0 Mon Sep 17 00:00:00 2001 From: Pedro Filipe Date: Wed, 3 Dec 2014 18:37:49 +0100 Subject: [PATCH 26/86] Readme first draft --- README.md | 272 +++++++++++++++++++++++------------------------------- 1 file changed, 116 insertions(+), 156 deletions(-) diff --git a/README.md b/README.md index 904b56768..20402e7cf 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,13 @@ If you're using [CocoaPods][cocoapods], you can add the following line to your `Podfile` and continue with [step 3](#step3): ```ruby -pod 'Adjust', :git => 'git://github.com/adjust/ios_sdk.git', :tag => 'v3.4.0' +pod 'Adjust', :git => 'git://github.com/adjust/ios_sdk.git', :tag => 'v4.0.0' ``` +## Example app + +There is an example app located inside the extracted folder named `example`. In it, you can open the Xcode project and see how the adjust SDK can be integrated. + ### 1. Get the SDK Download the latest version from our [releases page][releases]. Extract the @@ -48,40 +52,36 @@ and `iAd.framework`. Change the attribute `Required` to `Optional`. ### 4. Integrate Adjust into your app +Inside the example app, you can find the class `ExampleAdjustHelper` with the static method `initAdjust` that contains the minimum configuration and the optional ones commented. + +The `ADJConfig` object is where all optional configurations can be set before calling `appDidLaunch` method in the `Adjust` class. + +#### Minimum configuration + In the Project Navigator open the source file your Application Delegate. Add the `import` statement at the top of the file. In the `didFinishLaunching` or `didFinishLaunchingWithOptions` method of your App Delegate add the following calls to `Adjust`: ```objc +#import "ADJConfig.h" #import "Adjust.h" // ... -[Adjust appDidLaunch:@"{YourAppToken}"]; -[Adjust setLogLevel:AILogLevelInfo]; -[Adjust setEnvironment:AIEnvironmentSandbox]; +NSString * yourAppToken = @"{YourAppToken}"; +NSString * enviroment = AIEnvironmentSandbox; +ADJConfig * adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; +[Adjust appDidLaunch:adjustConfig]; ``` ![][delegate] Replace `{YourAppToken}` with your App Token. You can find in your [dashboard]. -You can increase or decrease the amount of logs you see by calling -`setLogLevel:` with one of the following parameters: - -```objc -[Adjust setLogLevel:AILogLevelVerbose]; // enable all logging -[Adjust setLogLevel:AILogLevelDebug]; // enable more logging -[Adjust setLogLevel:AILogLevelInfo]; // the default -[Adjust setLogLevel:AILogLevelWarn]; // disable info logging -[Adjust setLogLevel:AILogLevelError]; // disable warnings as well -[Adjust setLogLevel:AILogLevelAssert]; // disable errors as well -``` - Depending on whether or not you build your app for testing or for production -you must call `setEnvironment:` with one of these parameters: +you must set `enviroment` with one of these values: ```objc -[Adjust setEnvironment:AIEnvironmentSandbox]; -[Adjust setEnvironment:AIEnvironmentProduction]; +NSString * enviroment = AIEnvironmentSandbox; +NSString * enviroment = AIEnvironmentProduction; ``` **Important:** This value should be set to `AIEnvironmentSandbox` if and only @@ -93,6 +93,70 @@ We use this environment to distinguish between real traffic and artificial traffic from test devices. It is very important that you keep this value meaningful at all times! Especially if you are tracking revenue. +#### Logging + +You can increase or decrease the amount of logs you see in tests by calling +`setLogLevel:` on the `ADJConfig` object with one of the following parameters: + +```objc +[adjustConfig setLogLevel:ADJLogLevelVerbose]; // enable all logging +[adjustConfig setLogLevel:AILogLevelDebug]; // enable more logging +[adjustConfig setLogLevel:AILogLevelInfo]; // the default +[adjustConfig setLogLevel:AILogLevelWarn]; // disable info logging +[adjustConfig setLogLevel:AILogLevelError]; // disable warnings as well +[adjustConfig setLogLevel:AILogLevelAssert]; // disable errors as well +``` + +#### Attribution callback + +At install time, you can be notified of tracker attribution information. Due to the nature +of this information, it is not synchronous and can take some time before is available. +Follow these steps to implement the optional delegate protocol in your app delegate. + +Please make sure to consider [applicable attribution data policies.][attribution-data] + +1. Open `AppDelegate.h` and add the `ADJConfig.h` import and the `AdjustDelegate` + declaration. + + ```objc + #import "Adjust.h" + + @interface AppDelegate : UIResponder + ``` + +2. Open `AppDelegate.m` and add the following delegate callback function to + your app delegate implementation. + + ```objc + - (void)adjustAttributionCallback:(ADJAttribution *)attribution { + } + ``` + +3. When you are configuring the `ADJConfig` object, set the adjust delegate by calling `setDelegate` with the `AdjustDelegate` instace. + + ```objc + [adjustConfig setDelegate:self]; // if configuration is in the `AppDelegate.m` + [adjustConfig setDelegate:adjustDelegate]; // if configuration is set in another class, see example app + ``` + +The delegate function will get called once somewhere after the install. 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. + +#### Enable 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 by adding the following line to the `ADJConfig` object: + +```objc +[adjustConfig setEventBufferingEnabled:YES]; +``` ### 5. Build your app @@ -128,24 +192,29 @@ every tap on a button. You would have to create a new Event Token in your `buttonDown` method you could then add the following line to track the click: ```objc -[Adjust trackEvent:@"abc123"]; +ADJEvent * event = [ADJEvent eventWithEventToken:@"abc123"]; +[Adjust trackEvent:event]; ``` +Before calling the `trackEvent` method, you can configure the `ADJEvent` object + +Inside the example app, you can find the class `ExampleAdjustHelper` with the static method `triggerEvent` that contains an example how to trigger an event. + +The `ADJEvent` object is where all optional configurations can be set before calling the `trackEvent` method in the `Adjust` class. + +#### Callback URK + You can also register a callback URL for that event in your [dashboard] and we will send a GET request to that URL whenever the event gets tracked. In that -case you can also put some key-value-pairs in a dictionary and pass it to the -`trackEvent` method. We will then append these named parameters to your -callback URL. +case you can add a key-value-pair to `addCallbackParameter` method of `ADJEvent`. +We will then append these named parameters to your callback URL. For example, suppose you have registered the URL -`http://www.adjust.com/callback` for your event with Event Token `abc123` and -execute the following lines: +`http://www.adjust.com/callback` then add following lines to the `ADJEvent` object: ```objc -NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; -[parameters setObject:@"value" forKey:@"key"]; -[parameters setObject:@"bar" forKey:@"foo"]; -[Adjust trackEvent:@"abc123" withParameters:parameters]; +[event addCallbackParameter:@"key" andValue:@"value"]; +[event addCallbackParameter:@"foo" andValue:@"bar"]; ``` In that case we would track the event and send a request to: @@ -159,33 +228,15 @@ device. Also note that we don't store any of your custom parameters, but only append them to your callbacks. If you haven't registered a callback for an event, these parameters won't even be read. -### 7. Add tracking of revenue +#### Track revenue If your users can generate revenue by clicking on advertisements or making in-app purchases you can track those revenues. If, for example, a click is -worth one cent, you could make the following call to track that revenue: - -```objc -[Adjust trackRevenue:1.0]; -``` - -The parameter is supposed to be in cents and will get rounded to one decimal -point. If you want to differentiate between different kinds of revenue you can -get different Event Tokens for each kind. Again, you need to create those Event -Tokens in your [dashboard]. In that case you would make a call like this: +worth one cent of an Euro, you can add the following calll to the `ADJEvent` object to track +that revenue: ```objc -[Adjust trackRevenue:1.0 forEvent:@"abc123"]; -``` - -Again, you can register a callback and provide a dictionary of named -parameters, just like it worked with normal events. - -```objc -NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; -[parameters setObject:@"value" forKey:@"key"]; -[parameters setObject:@"bar" forKey:@"foo"]; -[Adjust trackRevenue:1.0 forEvent:@"abc123" withParameters:parameters]; +[event setRevenue:0.01 currency:@"EUR"]; ``` You can also pass in an optional transaction ID to avoid tracking duplicate @@ -193,7 +244,7 @@ revenues. The last ten transaction IDs are remembered and revenue events with duplicate transaction IDs are skipped. This is especially useful for In-App Purchase tracking. See an example below. -If you want to track In-App Purchases, please make sure to call `trackRevenue` +If you want to track In-App Purchases, please make sure to call `trackEvent` after `finishTransaction` in `paymentQueue:updatedTransaction` only if the state changed to `SKPaymentTransactionStatePurchased`: @@ -204,10 +255,10 @@ state changed to `SKPaymentTransactionStatePurchased`: case SKPaymentTransactionStatePurchased: [self finishTransaction:transaction]; - [Adjust trackRevenue:... - transactionId:transaction.transactionIdentifier // avoid duplicates - forEvent:... - withParameters:...]; + ADJEvent * event = [ADJEvent eventWithEventToken:...]; + [event setRevenue:... currency:...]; + [event setTransactionId:transaction.transactionIdentifier]; // avoid duplicates + [Adjust trackEvent:event]; break; // more cases @@ -219,7 +270,7 @@ state changed to `SKPaymentTransactionStatePurchased`: If you want to track all revenues in the same currency you might want to use [AEPriceMatrix][AEPriceMatrix] to do simple tier based currency conversion. -### 8. Handle reattributions with deep linking +### 7. Handle reattributions with deep linking You can also set up the adjust SDK to read deep links that come to your app, also known as custom URL schemes in iOS. We will only read the data that is @@ -237,97 +288,7 @@ or add the method `openURL` and add the following call to adjust: } ``` -### 9. Receive delegate callbacks - -Every time your app tries to track a session, an event or some revenue, you can -be notified about the success of that operation and receive additional -information about the current install. Follow these steps to implement the -optional delegate protocol in your app delegate. - -Please make sure to consider [applicable attribution data policies.][attribution-data] - -1. Open `AppDelegate.h` and add the `Adjust.h` import and the `AdjustDelegate` - declaration. - - ```objc - #import "Adjust.h" - - @interface AppDelegate : UIResponder - ``` - -2. Open `AppDelegate.m` and set the adjust delegate in `didFinishLaunching` - where you already set the adjust environment. - - ```objc - [Adjust setEnvironment:AIEnvironmentSandbox]; - [Adjust setDelegate:self]; - ``` - -3. Still in `AppDelegate.m` add the following delegate callback function to - your app delegate implementation. - - ```objc - - (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData { - } - ``` - -4. Implement the delegate function. - -The delegate function will get called every time any activity was tracked or -failed to track. Within the delegate function you have access to the -`responseData` parameter. Here is a quick summary of its attributes: - -- `AIActivityKind activityKind` indicates what kind of activity was tracked. It - has one of these values: - - ``` - AIActivityKindSession - AIActivityKindEvent - AIActivityKindRevenue - AIActivityKindReattribution - ``` - -- `NSString activityKindString` human readable version of the activity kind. - Possible values: - - ``` - session - event - revenue - reattribution - ``` - -- `BOOL success` indicates whether or not the tracking attempt was - successful. -- `BOOL willRetry` is true when the request failed, but will be - retried. -- `NSString error` an error message when the activity failed to track or - the response could not be parsed. Is `nil` otherwise. -- `NSString trackerToken` the tracker token of the current install. Is `nil` if - request failed or response could not be parsed. -- `NSString trackerName` the tracker name of the current install. Is `nil` if - request failed or response could not be parsed. -- `NSString network` the network grouping level of the current install. Is `nil` if - request failed, unavailable or response could not be parsed. -- `NSString campaign` the campaign grouping level of the current install. Is `nil` if - request failed, unavailable or response could not be parsed. -- `NSString adgroup` the ad group grouping level of the current install. Is `nil` if - request failed, unavailable or response could not be parsed. -- `NSString creative` the creative grouping level of the current install. Is `nil` if - request failed, unavailable or response could not be parsed. - -### 10. Enable 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 by adding the following line after your `setEnvironment:` call -in the `didFinishLaunching` method of your Application Delegate: - -```objc -[Adjust setEventBufferingEnabled:YES]; -``` - -### 11. Disable tracking +#### 8. Disable tracking You can disable the adjust SDK from tracking by invoking the method `setEnabled` with the enabled parameter as `NO`. This setting is remembered @@ -341,19 +302,18 @@ You can verify if the adjust SDK is currently active with the method `isEnabled`. It is always possible to activate the adjust SDK by invoking `setEnabled` with the enabled parameter as `YES`. -### 12. Push token +#### 9. Offline mode -If your app receives notifications you can save the push token in the adjust SDK. -In the Project Navigator open the source file your Application Delegate. Find -or add the method `didRegisterForRemoteNotificationsWithDeviceToken` and add the following call to adjust: +You can put the adjust SDK in offline mode, preventing from tracking while in +offline mode. When disabled, the tracking done in offline mode will be sent. +Call the method `setOfflineMode` with the enabled parameter as `YES` to put it +on offline mode, and `NO` to disable it. ```objc -- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken -{ - [Adjust setDeviceToken:deviceToken]; -} +[Adjust setOfflineMode:YES]; ``` + [adjust.com]: http://adjust.com [cocoapods]: http://cocoapods.org [dashboard]: http://adjust.com From 60aeda30affc630c593a1ee77ea1cb9e1a31f598 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 13:45:26 +0100 Subject: [PATCH 27/86] Correct last interval paramter --- Adjust/ADJPackageBuilder.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index fbf6e5e30..905596d2b 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -36,7 +36,7 @@ - (id)initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo - (ADJActivityPackage *)buildSessionPackage { NSMutableDictionary *parameters = [self defaultParameters]; - [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"callback_params"]; + [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"last_interval"]; ADJActivityPackage *sessionPackage = [self defaultActivityPackage]; sessionPackage.path = @"/startup"; From a259f7c9db31df1d999ce3acbeb71f1bddc2f2d9 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 13:46:01 +0100 Subject: [PATCH 28/86] Interval timer to start immediately --- Adjust/ADJTimer.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adjust/ADJTimer.m b/Adjust/ADJTimer.m index 92b94c5cf..212f194c6 100644 --- a/Adjust/ADJTimer.m +++ b/Adjust/ADJTimer.m @@ -44,7 +44,7 @@ - (id)initWithInterval:(uint64_t)interval self.source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); if (self.source != nil) { dispatch_source_set_timer(self.source, - dispatch_walltime(NULL, interval), + dispatch_walltime(NULL, 0), interval, leeway); dispatch_source_set_event_handler(self.source, block); From 0d6067f49e3e755da472b1e83864c8687967b5f9 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 13:46:37 +0100 Subject: [PATCH 29/86] Time format milliseconds with dot --- Adjust/ADJUtil.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 0417ead0a..61ae3618e 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -17,10 +17,9 @@ static NSString * const kBaseUrl = @"https://app.adjust.com"; static NSString * const kClientSdk = @"ios4.0.0"; -static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss:SSS'Z'Z"; +static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'Z"; static NSDateFormatter * dateFormat; - #pragma mark - @implementation ADJUtil @@ -160,7 +159,6 @@ + (void)writeObject:(id)object } else { [logger error:@"Failed to write %@ file", objectName]; } - } + (NSString *) queryString:(NSDictionary *)parameters { From 6afae7199f281bf13ecc4419e715231ac086e331 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 13:47:10 +0100 Subject: [PATCH 30/86] Remove attribution max time from example --- example/example/ExampleAdjustHelper.m | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/example/example/ExampleAdjustHelper.m b/example/example/ExampleAdjustHelper.m index ed85b87f1..b7253417d 100644 --- a/example/example/ExampleAdjustHelper.m +++ b/example/example/ExampleAdjustHelper.m @@ -11,12 +11,10 @@ #import "ADJLogger.h" #import "ADJEvent.h" -static NSString * const appToken = @"dgau42x652ul"; - @implementation ExampleAdjustHelper + (void) initAdjust: (NSObject *) adjustDelegate { - NSString * yourAppToken = appToken; + NSString * yourAppToken = @"dgau42x652ul"; NSString * enviroment = AIEnvironmentSandbox; ADJConfig * adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; @@ -32,9 +30,6 @@ + (void) initAdjust: (NSObject *) adjustDelegate { // set an attribution delegate [adjustConfig setDelegate:adjustDelegate]; - // set maximum waited to get the attribution - //[adjustConfig setAttributionMaxTimeMilliseconds:10000]; - Adjust * adjust = [Adjust getInstance]; [adjust appDidLaunch:adjustConfig]; } From 788326de82f4a78b1fcaf688543d921abdf5691e Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 13:48:03 +0100 Subject: [PATCH 31/86] Example app workspace file --- .../project.xcworkspace/contents.xcworkspacedata | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 example/example.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/example/example.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/example.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..e35a4f1df --- /dev/null +++ b/example/example.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + From 84cbe9de6d75f0666d4511b631e90d5f4a17a0f9 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 16:10:09 +0100 Subject: [PATCH 32/86] Event isValid --- Adjust/ADJActivityHandler.m | 32 +------------------------------- Adjust/ADJEvent.h | 2 ++ Adjust/ADJEvent.m | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 90fa720e8..0d904c360 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -71,7 +71,6 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig { self.logger = ADJAdjustFactory.logger; [self addNotificationObserver]; self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); - self.logger = ADJAdjustFactory.logger; _enabled = YES; dispatch_async(self.internalQueue, ^{ @@ -346,9 +345,7 @@ - (void)eventInternal:(ADJEvent *)event // check consistency if (![self checkAppTokenNotNil:self.adjustConfig.appToken]) return; if (![self checkActivityState:self.activityState]) return; - if (![self checkEventTokenNotNil:event.eventToken]) return; - if (![self checkEventTokenLength:event.eventToken]) return; - if (![self checkAmount:event.revenue]) return; + if (![event isValid]) return; if (![self checkTransactionId:event.transactionId]) return; if (!self.activityState.enabled) { @@ -558,33 +555,6 @@ - (BOOL)checkAppTokenNotNil:(NSString *)appToken { return YES; } -- (BOOL)checkEventTokenNotNil:(NSString *)eventToken { - if (eventToken == nil) { - [self.logger error:@"Missing Event Token"]; - return NO; - } - return YES; -} - -- (BOOL)checkEventTokenLength:(NSString *)eventToken { - if (eventToken == nil) { - return YES; - } - if (eventToken.length != 6) { - [self.logger error:@"Malformed Event Token '%@'", eventToken]; - return NO; - } - return YES; -} - -- (BOOL)checkAmount:(NSNumber *)amount { - if (amount != nil && [amount doubleValue] < 0.0) { - [self.logger error:@"Invalid amount %.1f", [amount doubleValue]]; - return NO; - } - return YES; -} - - (BOOL) checkTransactionId:(NSString *)transactionId { if (transactionId == nil || transactionId.length == 0) { return YES; // no transaction ID given diff --git a/Adjust/ADJEvent.h b/Adjust/ADJEvent.h index 116cdf8a5..9e7f870f2 100644 --- a/Adjust/ADJEvent.h +++ b/Adjust/ADJEvent.h @@ -30,4 +30,6 @@ // check currency correctness, warn if weird - (void) setTransactionId:(NSString *)transactionId; +- (BOOL) isValid; + @end diff --git a/Adjust/ADJEvent.m b/Adjust/ADJEvent.m index 48b36db88..af1ee4181 100644 --- a/Adjust/ADJEvent.m +++ b/Adjust/ADJEvent.m @@ -7,6 +7,7 @@ // #import "ADJEvent.h" +#import "ADJAdjustFactory.h" #pragma mark - @@ -52,6 +53,36 @@ - (void) setTransactionId:(NSString *)transactionId { _transactionId = transactionId; } +- (BOOL) isValid { + + id logger = ADJAdjustFactory.logger; + + if (self.eventToken == nil) { + [logger error:@"Missing Event Token"]; + return NO; + } + + if (self.eventToken.length != 6) { + [logger error:@"Malformed Event Token '%@'", self.eventToken]; + return NO; + } + + if (self.revenue != nil) { + double amount = [self.revenue doubleValue]; + if (amount < 0.0) { + [logger error:@"Invalid amount %.1f", amount]; + return NO; + } + + if (self.currency == nil) { + [logger error:@"Currency must be set with revenue"]; + return NO; + } + } + + return YES; +} + -(id)copyWithZone:(NSZone *)zone { ADJEvent* copy = [[[self class] allocWithZone:zone] init]; From 33702fc952acbfc72bf277f399d4de87266b8b15 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 16:10:59 +0100 Subject: [PATCH 33/86] Adjust refac static default instance --- Adjust/Adjust.m | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index e55f661d4..e1acd4823 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -25,48 +25,39 @@ @interface Adjust() @implementation Adjust + (void)appDidLaunch:(ADJConfig *)adjustConfig { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance appDidLaunch:adjustConfig]; + [[Adjust getInstance] appDidLaunch:adjustConfig]; } + (void)trackEvent:(ADJEvent *)event { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance trackEvent:event]; + [[Adjust getInstance] trackEvent:event]; } + (void)trackSubsessionStart { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance trackSubsessionStart]; + [[Adjust getInstance] trackSubsessionStart]; } + (void)trackSubsessionEnd { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance trackSubsessionEnd]; + [[Adjust getInstance] trackSubsessionEnd]; } + (void)setEnabled:(BOOL)enabled { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance setEnabled:enabled]; + [[Adjust getInstance] setEnabled:enabled]; } + (BOOL)isEnabled { - Adjust * defaultInstance = [Adjust getInstance]; - return [defaultInstance isEnabled]; + return [[Adjust getInstance] isEnabled]; } + (void)appWillOpenUrl:(NSURL *)url { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance appWillOpenUrl:url]; + [[Adjust getInstance] appWillOpenUrl:url]; } + (void)setDeviceToken:(NSData *)deviceToken { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance setDeviceToken:deviceToken]; + [[Adjust getInstance] setDeviceToken:deviceToken]; } + (void)setOfflineMode:(BOOL)enabled { - Adjust * defaultInstance = [Adjust getInstance]; - [defaultInstance setOfflineMode:enabled]; + [[Adjust getInstance] setOfflineMode:enabled]; } + (id)getInstance { From 99c1e494e1da2058d116223c2ee9b7c98f511759 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 16:14:23 +0100 Subject: [PATCH 34/86] Remove bridge --- Adjust.xcodeproj/project.pbxproj | 32 -- AdjustBridge/AdjustBridge.h | 17 - AdjustBridge/AdjustBridge.js.txt | 39 -- AdjustBridge/AdjustBridge.m | 85 ---- .../WebViewJavascriptBridge.h | 44 -- .../WebViewJavascriptBridge.js.txt | 116 ----- .../WebViewJavascriptBridge.m | 407 ------------------ README.md | 3 +- doc/webApp.md | 234 ---------- 9 files changed, 1 insertion(+), 976 deletions(-) delete mode 100644 AdjustBridge/AdjustBridge.h delete mode 100644 AdjustBridge/AdjustBridge.js.txt delete mode 100644 AdjustBridge/AdjustBridge.m delete mode 100755 AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.h delete mode 100755 AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.js.txt delete mode 100755 AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.m delete mode 100644 doc/webApp.md diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index 1eb9ebbc7..78eb1ac95 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -24,8 +24,6 @@ 969952D21A01309200928462 /* ADJAttribution.m in Sources */ = {isa = PBXBuildFile; fileRef = 969952D11A01309200928462 /* ADJAttribution.m */; }; 96CD2BE01A13BFC600A40AFB /* NSString+ADJAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD2BDD1A13BFC600A40AFB /* NSString+ADJAdditions.m */; }; 96CD2BE11A13BFC600A40AFB /* UIDevice+ADJAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD2BDF1A13BFC600A40AFB /* UIDevice+ADJAdditions.m */; }; - 96CD4478192A546F0029A1AA /* AdjustBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD4473192A546F0029A1AA /* AdjustBridge.m */; }; - 96CD4479192A546F0029A1AA /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 96CD4477192A546F0029A1AA /* WebViewJavascriptBridge.m */; }; 96E5E38118BBB48A008E7B30 /* Adjust.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E34D18BBB48A008E7B30 /* Adjust.m */; }; 96E5E38B18BBB48A008E7B30 /* ADJActivityHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36318BBB48A008E7B30 /* ADJActivityHandler.m */; }; 96E5E38C18BBB48A008E7B30 /* ADJActivityKind.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E36518BBB48A008E7B30 /* ADJActivityKind.m */; }; @@ -108,16 +106,10 @@ 969952CE1A012F5300928462 /* ADJAttributionHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAttributionHandler.m; sourceTree = ""; }; 969952D01A01309200928462 /* ADJAttribution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJAttribution.h; sourceTree = ""; }; 969952D11A01309200928462 /* ADJAttribution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAttribution.m; sourceTree = ""; }; - 96ADB109192E0175006E1D9D /* AdjustBridge.js.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AdjustBridge.js.txt; sourceTree = ""; }; 96CD2BDC1A13BFC600A40AFB /* NSString+ADJAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+ADJAdditions.h"; sourceTree = ""; }; 96CD2BDD1A13BFC600A40AFB /* NSString+ADJAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+ADJAdditions.m"; sourceTree = ""; }; 96CD2BDE1A13BFC600A40AFB /* UIDevice+ADJAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+ADJAdditions.h"; sourceTree = ""; }; 96CD2BDF1A13BFC600A40AFB /* UIDevice+ADJAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+ADJAdditions.m"; sourceTree = ""; }; - 96CD4472192A546F0029A1AA /* AdjustBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdjustBridge.h; sourceTree = ""; }; - 96CD4473192A546F0029A1AA /* AdjustBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdjustBridge.m; sourceTree = ""; }; - 96CD4475192A546F0029A1AA /* WebViewJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridge.h; sourceTree = ""; }; - 96CD4476192A546F0029A1AA /* WebViewJavascriptBridge.js.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebViewJavascriptBridge.js.txt; sourceTree = ""; }; - 96CD4477192A546F0029A1AA /* WebViewJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge.m; sourceTree = ""; }; 96E5E34C18BBB48A008E7B30 /* Adjust.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Adjust.h; sourceTree = ""; }; 96E5E34D18BBB48A008E7B30 /* Adjust.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Adjust.m; sourceTree = ""; }; 96E5E36218BBB48A008E7B30 /* ADJActivityHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityHandler.h; sourceTree = ""; }; @@ -203,7 +195,6 @@ isa = PBXGroup; children = ( 960FCF491A1B9ACE00282BD4 /* example.xcodeproj */, - 96CD4471192A546F0029A1AA /* AdjustBridge */, 96E5E39A18BBB49E008E7B30 /* AdjustTests */, 96E5E34B18BBB48A008E7B30 /* Adjust */, 9679920F18BBAE2800394606 /* Frameworks */, @@ -243,27 +234,6 @@ path = ADJAdditions; sourceTree = ""; }; - 96CD4471192A546F0029A1AA /* AdjustBridge */ = { - isa = PBXGroup; - children = ( - 96ADB109192E0175006E1D9D /* AdjustBridge.js.txt */, - 96CD4472192A546F0029A1AA /* AdjustBridge.h */, - 96CD4473192A546F0029A1AA /* AdjustBridge.m */, - 96CD4474192A546F0029A1AA /* WebViewJavascriptBridge */, - ); - path = AdjustBridge; - sourceTree = ""; - }; - 96CD4474192A546F0029A1AA /* WebViewJavascriptBridge */ = { - isa = PBXGroup; - children = ( - 96CD4475192A546F0029A1AA /* WebViewJavascriptBridge.h */, - 96CD4476192A546F0029A1AA /* WebViewJavascriptBridge.js.txt */, - 96CD4477192A546F0029A1AA /* WebViewJavascriptBridge.m */, - ); - path = WebViewJavascriptBridge; - sourceTree = ""; - }; 96E5E34B18BBB48A008E7B30 /* Adjust */ = { isa = PBXGroup; children = ( @@ -438,7 +408,6 @@ buildActionMask = 2147483647; files = ( 96E5E38118BBB48A008E7B30 /* Adjust.m in Sources */, - 96CD4479192A546F0029A1AA /* WebViewJavascriptBridge.m in Sources */, 96E5E38B18BBB48A008E7B30 /* ADJActivityHandler.m in Sources */, 96E5E39618BBB48A008E7B30 /* ADJRequestHandler.m in Sources */, 96E5E39918BBB48A008E7B30 /* ADJUtil.m in Sources */, @@ -456,7 +425,6 @@ 96E5E39418BBB48A008E7B30 /* ADJPackageBuilder.m in Sources */, 960A8BB91A029A8000F2BB95 /* ADJConfig.m in Sources */, 96E5E39218BBB48A008E7B30 /* ADJAdjustFactory.m in Sources */, - 96CD4478192A546F0029A1AA /* AdjustBridge.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/AdjustBridge/AdjustBridge.h b/AdjustBridge/AdjustBridge.h deleted file mode 100644 index 442bd66e3..000000000 --- a/AdjustBridge/AdjustBridge.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// AdjustBridge.h -// Adjust -// -// Created by Pedro Filipe on 19/05/14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// - -#import -#import - -@interface AdjustBridge : NSObject - -+ (void)loadBridge:(NSObject *) webViewDelegate - webView:(UIWebView *) webView; - -@end diff --git a/AdjustBridge/AdjustBridge.js.txt b/AdjustBridge/AdjustBridge.js.txt deleted file mode 100644 index 8a3f2c6dc..000000000 --- a/AdjustBridge/AdjustBridge.js.txt +++ /dev/null @@ -1,39 +0,0 @@ -window.AdjustBridge = (function () { - - var bridge = {}; - - var adjustPrefix = 'adjust_'; - - function setBridgePrivate(bridgeParam) { - bridge = bridgeParam; - bridge.init(function(message, callback) { }); - } - - function trackEventPrivate (event) { - bridge.callHandler(adjustPrefix + 'trackEvent', - {'event': event}, - function(response) {}) - }; - - function setEnabledPrivate(enabled) { - bridge.callHandler(adjustPrefix + 'setEnabled', {'enabled': enabled}, function(response) { }); - }; - - function isEnabledPrivate(isEnabledReturnCallBack) { - bridge.callHandler(adjustPrefix + 'isEnabled', {}, function(isEnabledString) { - isEnabledReturnCallBack(isEnabledString) - }); - }; - - function openUrlPrivate(url) { - bridge.callHandler(adjustPrefix + 'openUrl', {'url': url}, function(response) { }); - }; - - return { - setBridge: setBridgePrivate, - trackEvent: trackEventPrivate, - setEnabled: setEnabledPrivate, - isEnabled: isEnabledPrivate, - openUrl: openUrlPrivate - }; -})(); diff --git a/AdjustBridge/AdjustBridge.m b/AdjustBridge/AdjustBridge.m deleted file mode 100644 index b9ed19d74..000000000 --- a/AdjustBridge/AdjustBridge.m +++ /dev/null @@ -1,85 +0,0 @@ -// -// AdjustBridge.m -// Adjust -// -// Created by Pedro Filipe on 19/05/14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// - -#import "AdjustBridge.h" -#import "WebViewJavascriptBridge.h" -#import "ADJEvent.h" -#import "Adjust.h" - -static NSString * const kAdjustJsPrefix = @"adjust_"; - -static WebViewJavascriptBridge* _AdjustBridge = nil; -static id adjustBridgeInstance = nil; - -@implementation AdjustBridge - -- (id) init { - self = [super init]; - return self; -} - -+ (void) loadBridge:(NSObject *) webViewDelegate - webView:(UIWebView *) webView { - if (_AdjustBridge) { return; } - - _AdjustBridge = [WebViewJavascriptBridge bridgeForWebView:webView webViewDelegate:webViewDelegate handler:^(id data, WVJBResponseCallback responseCallback) { - }]; - - [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@trackEvent", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { - - // TODO, test - ADJEvent * event= [data objectForKey:@"event"]; - /* - NSString* eventToken = [data objectForKey:@"eventToken"]; - NSDictionary* parameters = [data objectForKey:@"parameters"]; - NSNumber* revenue = [data objectForKey:@"revenue"]; - NSString* currency = [data objectForKey:@"currency"]; - - AIEvent* event = [[AIEvent alloc] initWithEventToken:eventToken]; - - if (parameters != nil) { - for (NSString* key in parameters) { - NSString* value = [parameters objectForKey:key]; - [event addCallbackParameter:key andValue:value]; - } - } - - if (revenue != nil) { - [event setRevenue:[revenue doubleValue] currency:currency]; - } - */ - [Adjust trackEvent:event]; - }]; - - [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@setEnabled", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { - - BOOL enabled = [[data objectForKey:@"enabled"] boolValue]; - [Adjust setEnabled:enabled]; - }]; - - [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@isEnabled", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { - - BOOL isEnabled = [Adjust isEnabled]; - - responseCallback([NSNumber numberWithBool:isEnabled]); - }]; - - [_AdjustBridge registerHandler:[NSString stringWithFormat:@"%@openUrl", kAdjustJsPrefix] handler:^(id data, WVJBResponseCallback responseCallback) { - - NSURL* url = [[NSURL alloc] initWithString:[data objectForKey:@"url"]]; - [Adjust appWillOpenUrl:url]; - }]; - - if (![[webView stringByEvaluatingJavaScriptFromString:@"typeof AdjustBridge == 'object'"] isEqualToString:@"true"]) { - NSBundle *bundle = [NSBundle mainBundle]; - NSString *filePath = [bundle pathForResource:@"AdjustBridge.js" ofType:@"txt"]; - NSString *js = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; - [webView stringByEvaluatingJavaScriptFromString:js]; - } -} -@end diff --git a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.h b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.h deleted file mode 100755 index e70b0fba7..000000000 --- a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// WebViewJavascriptBridge.h -// ExampleApp-iOS -// -// Created by Marcus Westin on 6/14/13. -// Copyright (c) 2013 Marcus Westin. All rights reserved. -// - -#import -#import - -#define kCustomProtocolScheme @"wvjbscheme" -#define kQueueHasMessage @"__WVJB_QUEUE_MESSAGE__" - -#if defined __MAC_OS_X_VERSION_MAX_ALLOWED - #import - #define WVJB_PLATFORM_OSX - #define WVJB_WEBVIEW_TYPE WebView - #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject -#elif defined __IPHONE_OS_VERSION_MAX_ALLOWED - #define WVJB_PLATFORM_IOS - #define WVJB_WEBVIEW_TYPE UIWebView - #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject -#endif - -typedef void (^WVJBResponseCallback)(id responseData); -typedef void (^WVJBHandler)(id data, WVJBResponseCallback responseCallback); - -@interface WebViewJavascriptBridge : WVJB_WEBVIEW_DELEGATE_TYPE - -+ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView handler:(WVJBHandler)handler; -+ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)handler; -+ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)handler resourceBundle:(NSBundle*)bundle; -+ (void)enableLogging; - -- (void)send:(id)message; -- (void)send:(id)message responseCallback:(WVJBResponseCallback)responseCallback; -- (void)registerHandler:(NSString*)handlerName handler:(WVJBHandler)handler; -- (void)callHandler:(NSString*)handlerName; -- (void)callHandler:(NSString*)handlerName data:(id)data; -- (void)callHandler:(NSString*)handlerName data:(id)data responseCallback:(WVJBResponseCallback)responseCallback; -- (void)reset; - -@end diff --git a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.js.txt b/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.js.txt deleted file mode 100755 index 86303713c..000000000 --- a/AdjustBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.js.txt +++ /dev/null @@ -1,116 +0,0 @@ -;(function() { - if (window.WebViewJavascriptBridge) { return } - var messagingIframe - var sendMessageQueue = [] - var receiveMessageQueue = [] - var messageHandlers = {} - - var CUSTOM_PROTOCOL_SCHEME = 'wvjbscheme' - var QUEUE_HAS_MESSAGE = '__WVJB_QUEUE_MESSAGE__' - - var responseCallbacks = {} - var uniqueId = 1 - - function _createQueueReadyIframe(doc) { - messagingIframe = doc.createElement('iframe') - messagingIframe.style.display = 'none' - doc.documentElement.appendChild(messagingIframe) - } - - function init(messageHandler) { - if (WebViewJavascriptBridge._messageHandler) { throw new Error('WebViewJavascriptBridge.init called twice') } - WebViewJavascriptBridge._messageHandler = messageHandler - var receivedMessages = receiveMessageQueue - receiveMessageQueue = null - for (var i=0; i 500) { - NSLog(@"WVJB %@: %@ [...]", action, [json substringToIndex:500]); - } else { - NSLog(@"WVJB %@: %@", action, json); - } -} - - - -/* Platform specific internals: OSX - **********************************/ -#if defined WVJB_PLATFORM_OSX - -- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)messageHandler resourceBundle:(NSBundle*)bundle{ - _messageHandler = messageHandler; - _webView = webView; - _webViewDelegate = webViewDelegate; - _messageHandlers = [NSMutableDictionary dictionary]; - - _webView.frameLoadDelegate = self; - _webView.resourceLoadDelegate = self; - _webView.policyDelegate = self; - - _resourceBundle = bundle; -} - -- (void) _platformSpecificDealloc { - _webView.frameLoadDelegate = nil; - _webView.resourceLoadDelegate = nil; - _webView.policyDelegate = nil; -} - -- (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)frame -{ - if (webView != _webView) { return; } - - if (![[webView stringByEvaluatingJavaScriptFromString:@"typeof WebViewJavascriptBridge == 'object'"] isEqualToString:@"true"]) { - NSBundle *bundle = _resourceBundle ? _resourceBundle : [NSBundle mainBundle]; - NSString *filePath = [bundle pathForResource:@"WebViewJavascriptBridge.js" ofType:@"txt"]; - NSString *js = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; - [webView stringByEvaluatingJavaScriptFromString:js]; - } - - if (_startupMessageQueue) { - for (id queuedMessage in _startupMessageQueue) { - [self _dispatchMessage:queuedMessage]; - } - _startupMessageQueue = nil; - } - - if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:didFinishLoadForFrame:)]) { - [_webViewDelegate webView:webView didFinishLoadForFrame:frame]; - } -} - -- (void)webView:(WebView *)webView didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - if (webView != _webView) { return; } - - if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)]) { - [_webViewDelegate webView:webView didFailLoadWithError:error forFrame:frame]; - } -} - -- (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 ([[url scheme] isEqualToString:kCustomProtocolScheme]) { - if ([[url host] isEqualToString:kQueueHasMessage]) { - [self _flushMessageQueue]; - } else { - NSLog(@"WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@://%@", kCustomProtocolScheme, [url path]); - } - [listener ignore]; - } else if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)]) { - [_webViewDelegate webView:webView decidePolicyForNavigationAction:actionInformation request:request frame:frame decisionListener:listener]; - } else { - [listener use]; - } -} - -- (void)webView:(WebView *)webView didCommitLoadForFrame:(WebFrame *)frame { - if (webView != _webView) { return; } - - if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:didCommitLoadForFrame:)]) { - [_webViewDelegate webView:webView didCommitLoadForFrame:frame]; - } -} - -- (NSURLRequest *)webView:(WebView *)webView resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource { - if (webView != _webView) { return request; } - - if (_webViewDelegate && [_webViewDelegate respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)]) { - return [_webViewDelegate webView:webView resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:dataSource]; - } - - return request; -} - - - -/* Platform specific internals: iOS - **********************************/ -#elif defined WVJB_PLATFORM_IOS - -- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(id)webViewDelegate handler:(WVJBHandler)messageHandler resourceBundle:(NSBundle*)bundle{ - _messageHandler = messageHandler; - _webView = webView; - _webViewDelegate = webViewDelegate; - _messageHandlers = [NSMutableDictionary dictionary]; - _webView.delegate = self; - _resourceBundle = bundle; -} - -- (void) _platformSpecificDealloc { - _webView.delegate = nil; -} - -- (void)webViewDidFinishLoad:(UIWebView *)webView { - if (webView != _webView) { return; } - - _numRequestsLoading--; - - if (_numRequestsLoading == 0 && ![[webView stringByEvaluatingJavaScriptFromString:@"typeof WebViewJavascriptBridge == 'object'"] isEqualToString:@"true"]) { - NSBundle *bundle = _resourceBundle ? _resourceBundle : [NSBundle mainBundle]; - NSString *filePath = [bundle pathForResource:@"WebViewJavascriptBridge.js" ofType:@"txt"]; - NSString *js = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; - [webView stringByEvaluatingJavaScriptFromString:js]; - } - - if (_startupMessageQueue) { - for (id queuedMessage in _startupMessageQueue) { - [self _dispatchMessage:queuedMessage]; - } - _startupMessageQueue = nil; - } - - __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; - if (strongDelegate && [strongDelegate respondsToSelector:@selector(webViewDidFinishLoad:)]) { - [strongDelegate webViewDidFinishLoad:webView]; - } -} - -- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { - if (webView != _webView) { return; } - - _numRequestsLoading--; - - __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; - if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) { - [strongDelegate webView:webView didFailLoadWithError:error]; - } -} - -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { - if (webView != _webView) { return YES; } - NSURL *url = [request URL]; - __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; - if ([[url scheme] isEqualToString:kCustomProtocolScheme]) { - if ([[url host] isEqualToString:kQueueHasMessage]) { - [self _flushMessageQueue]; - } else { - NSLog(@"WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@://%@", kCustomProtocolScheme, [url path]); - } - return NO; - } else if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { - return [strongDelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType]; - } else { - return YES; - } -} - -- (void)webViewDidStartLoad:(UIWebView *)webView { - if (webView != _webView) { return; } - - _numRequestsLoading++; - - __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate; - if (strongDelegate && [strongDelegate respondsToSelector:@selector(webViewDidStartLoad:)]) { - [strongDelegate webViewDidStartLoad:webView]; - } -} - -#endif - -@end diff --git a/README.md b/README.md index 20402e7cf..289cd0579 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## Summary This is the iOS SDK of adjust™. You can read more about adjust™ at -[adjust.com]. If your app is a iOS Web App, consult our [iOS Web App][webApp] guide. +[adjust.com]. ## Basic Installation @@ -326,7 +326,6 @@ on offline mode, and `NO` to disable it. [delegate]: https://raw.github.com/adjust/sdks/master/Resources/ios/delegate3.png [run]: https://raw.github.com/adjust/sdks/master/Resources/ios/run3.png [AEPriceMatrix]: https://github.com/adjust/AEPriceMatrix -[webApp]: https://github.com/adjust/ios_sdk/blob/master/doc/webApp.md [attribution-data]: https://github.com/adjust/sdks/blob/master/doc/attribution-data.md ## License diff --git a/doc/webApp.md b/doc/webApp.md deleted file mode 100644 index 9dfb36f8e..000000000 --- a/doc/webApp.md +++ /dev/null @@ -1,234 +0,0 @@ -## Summary - -This is the guide to the iOS SDK of adjust.com™ for Web Apps. You can read more about adjust.com™ at -[adjust.com]. - -It provides a bridge from Javascript to native Objective-C calls using the [WebViewJavascriptBridge] plugin. -This plugin is a thin layer that allows to make calls from and to Javascript and Objective-C in iOS simple and easy. - -## Basic Installation - -### 1. Install the adjust iOS SDK - -To install the native iOS SDK of adjust, follow the `Basic Installation` chapter at our [GitHub page][ios_installation]. - -### 2. Add the Javascript bridge to your project - -In Xcode's Project Navigator locate the `Supporting Files` group (or any other -group of your choice). From Finder drag the `AdjustBridge` subdirectory into -Xcode's `Supporting Files` group. - -![][drag_bridge] - -In the dialog `Choose options for adding these files` make sure to check the -checkbox to `Copy items into destination group's folder` and select the upper -radio button to `Create groups for any added folders`. - -![][add_bridge] - -### 3. Integrate AdjustBridge into your app - -In the Project Navigator open the source file your View Controller. Add -the `import` statement at the top of the file. In the `viewDidLoad` or -`viewWillAppear` method of your Web View Delegate add the following -calls to `AdjustBridge`: - -```objc -#import "Adjust.h" -// ... -UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; -// ... -[AdjustBridge loadBridge:self webView:webView]; -// ... -``` - -![][delegate_bridge] - -### 4. Integrate AdjustBrige into your WebView - -To use the Javascript bridge of on your WebView, it must be configured like the [WebViewJavascriptBridge][js_setup] plugin in section `4)`. Include the following Javascript code to intialize the adjust iOS Javascript bridge: - -```js -function connectWebViewJavascriptBridge(callback) { - if (window.WebViewJavascriptBridge) { - callback(WebViewJavascriptBridge) - } else { - document.addEventListener('WebViewJavascriptBridgeReady', function() { - callback(WebViewJavascriptBridge) - }, false) - } -} - -connectWebViewJavascriptBridge(function(bridge) { - AdjustBridge.setBridge(bridge); - - // put calls to AdjustBridge here -}) -``` - -![][bridge_js] - -## Additional features - -Once you integrated the adjust iOS Javascript bridge SDK into your project, you can take advantage -of the following features. Remember that you have only access to the bridge inside the callback that initializes it. - -### 5. Add tracking of custom events. - -You can tell adjust about every event you want. Suppose you want to track -every tap on a button. You would have to create a new Event Token in your -[dashboard]. Let's say that Event Token is `abc123`. In your button's -`onClick` event you could then add the following line to track the click: - -```js -AdjustBridge.trackEvent('abc123'); -``` - -You can also register a callback URL for that event in your [dashboard] and we -will send a GET request to that URL whenever the event gets tracked. In that -case you can also put some key-value-pairs in a JSON object and pass it to the -`trackEvent` function. We will then append these named parameters to your -callback URL. - -For example, suppose you have registered the URL -`http://www.adjust.com/callback` for your event with Event Token `abc123` and -execute the following lines: - -```js -var parameters = {'key': 'value', 'foo': 'bar'}; -AdjustBridge.trackEvent('abc123', parameters); -``` - -In that case we would track the event and send a request to: - - http://www.adjust.com/callback?key=value&foo=bar - -It should be mentioned that we support a variety of placeholders like `{idfa}` -that can be used as parameter values. In the resulting callback this -placeholder would be replaced with the ID for Advertisers of the current -device. Also note that we don't store any of your custom parameters, but only -append them to your callbacks. If you haven't registered a callback for an -event, these parameters won't even be read. - -### 6. Add tracking of revenue - -If your users can generate revenue by clicking on advertisements or making -in-app purchases you can track those revenues. If, for example, a click is -worth one cent, you could make the following call to track that revenue: - -```js -AdjustBridge.trackRevenue(1.0); -``` - -The parameter is supposed to be in cents and will get rounded to one decimal -point. If you want to differentiate between different kinds of revenue you can -get different Event Tokens for each kind. Again, you need to create those Event -Tokens in your [dashboard]. In that case you would make a call like this: - -```js -AdjustBridge.trackRevenue(1.0, 'abc123'); -``` - -Again, you can register a callback and provide a JSON object of named -parameters, just like it worked with normal events. - -```js -var parameters = {'key': 'value', 'foo': 'bar'}; -AdjustBridge.trackRevenue(1.0, 'abc123', parameters); -``` - -If you want to track all revenues in the same currency you might want to use -[AEPriceMatrix][AEPriceMatrix] to do simple tier based currency conversion. - -### 7. Handle reattributions with deep linking - -You can also set up the adjust SDK to read deep links that come to your app, -also known as custom URL schemes in iOS. We will only read the data that is -injected by adjust tracker URLs. This is essential if you are planning to run -retargeting or re-engagement campaigns with deep links. - -Send the captured url to the function `openUrl` of our Javascript bridge. - -### 8. Receive delegate callbacks - -Every time your app tries to track a session, an event or some revenue, you can -be notified about the success of that operation and receive additional -information about the current install. In Javascript is as simple as passing a -callback function to out AdjustBridge: - -```js -AdjustBridge.setResponseDelegate(function (responseData) { - // ... -}); -``` - -The delegate callback will get called every time any activity was tracked or -failed to track. Within the delegate callback you have access to the -`responseData` parameter. Here is a quick summary of its attributes: - -- `activityKind` indicates what kind of activity was tracked. It - has one of these values: - - ``` - 'session' - 'event' - 'revenue' - 'reattribution' - ``` - -- `success` indicates whether or not the tracking attempt was - successful. -- `willRetry` is true when the request failed, but will be - retried. -- `error` an error message when the activity failed to track or - the response could not be parsed. Is `undefined` otherwise. -- `trackerToken` the tracker token of the current install. Is `undefined` if - request failed or response could not be parsed. -- `trackerName` the tracker name of the current install. Is `undefined` if - request failed or response could not be parsed. - -### 9. Enable 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 by adding the following line after your `setEnvironment:` call -in the `didFinishLaunching` method of your Application Delegate: - -```objc -[Adjust setEventBufferingEnabled:YES]; -``` - -### 10. Disable tracking - -You can disable the adjust SDK from tracking by invoking the function -`setEnabled` with the enabled parameter as `false`. This setting is remembered -between sessions, but it can only be activated after the first session. - -```js -AdjustBridge.setEnabled(false); -``` - -You can verify if the adjust SDK is currently active with the function -`isEnabled`. Pass a callback function with the parameter value as the boolean that -indicates whether adjust SDK is active or not. - -```js -AdjustBridge.isEnabled(function (isEnabledBool) { - if (isEnabledBool) - // ... -} -``` - -It is always possible to activate the adjust SDK by invoking -`setEnabled` with the enabled parameter as `true`. - -[adjust.com]: http://adjust.com -[dashboard]: http://adjust.com -[WebViewJavascriptBridge]: https://github.com/marcuswestin/WebViewJavascriptBridge -[ios_installation]: https://github.com/adjust/ios_sdk#basic-installation -[AEPriceMatrix]: https://github.com/adjust/AEPriceMatrix -[drag_bridge]: https://raw.githubusercontent.com/adjust/sdks/master/Resources/ios/drag_bridge.png -[add_bridge]: https://raw.githubusercontent.com/adjust/sdks/master/Resources/ios/add_bridge.png -[delegate_bridge]: https://raw.githubusercontent.com/adjust/sdks/master/Resources/ios/delegate_bridge.png -[bridge_js]: https://raw.githubusercontent.com/adjust/sdks/master/Resources/ios/bridge_js.png -[js_setup]: https://github.com/marcuswestin/WebViewJavascriptBridge#setup--examples-ios--osx From 1c5ccce04f77c8b17ab0c35f5046daf47c3d074b Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 16:41:27 +0100 Subject: [PATCH 35/86] Refac user agent into device info --- Adjust.xcodeproj/project.pbxproj | 6 - Adjust/ADJActivityHandler.m | 21 +--- Adjust/ADJDeviceInfo.h | 16 ++- Adjust/ADJDeviceInfo.m | 124 ++++++++++++++++++++- Adjust/ADJPackageBuilder.m | 73 ++++++------ Adjust/ADJUserAgent.h | 27 ----- Adjust/ADJUserAgent.m | 129 ---------------------- example/example.xcodeproj/project.pbxproj | 8 +- 8 files changed, 174 insertions(+), 230 deletions(-) delete mode 100644 Adjust/ADJUserAgent.h delete mode 100644 Adjust/ADJUserAgent.m diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index 78eb1ac95..fa018f01a 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -14,7 +14,6 @@ 96325E8B190E8D6200A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 96325E8C190E8D6B00A97911 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E84190E5CD900A97911 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 965307F61A000DA400107FF9 /* ADJDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 965307F51A000DA400107FF9 /* ADJDeviceInfo.m */; }; - 965307F81A000DCC00107FF9 /* ADJUserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 965307F71A000DCC00107FF9 /* ADJUserAgent.m */; }; 9679921118BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; }; 9679921F18BBAE2800394606 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921E18BBAE2800394606 /* XCTest.framework */; }; 9679922018BBAE2800394606 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921018BBAE2800394606 /* Foundation.framework */; }; @@ -94,9 +93,7 @@ 96325E84190E5CD900A97911 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 96325E86190E5CE400A97911 /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iAd.framework; path = System/Library/Frameworks/iAd.framework; sourceTree = SDKROOT; }; 9644B7EA19F148F3008576FC /* ADJDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJDeviceInfo.h; sourceTree = ""; }; - 9653078119FFD56900107FF9 /* ADJUserAgent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADJUserAgent.h; sourceTree = ""; }; 965307F51A000DA400107FF9 /* ADJDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJDeviceInfo.m; sourceTree = ""; }; - 965307F71A000DCC00107FF9 /* ADJUserAgent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserAgent.m; sourceTree = ""; }; 9679920D18BBAE2800394606 /* libAdjust.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAdjust.a; sourceTree = BUILT_PRODUCTS_DIR; }; 9679921018BBAE2800394606 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 9679921D18BBAE2800394606 /* AdjustTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AdjustTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -266,8 +263,6 @@ 9609BC6919EEA55800E02303 /* ADJEvent.m */, 9644B7EA19F148F3008576FC /* ADJDeviceInfo.h */, 965307F51A000DA400107FF9 /* ADJDeviceInfo.m */, - 9653078119FFD56900107FF9 /* ADJUserAgent.h */, - 965307F71A000DCC00107FF9 /* ADJUserAgent.m */, 969952CD1A012F5300928462 /* ADJAttributionHandler.h */, 969952CE1A012F5300928462 /* ADJAttributionHandler.m */, 969952D01A01309200928462 /* ADJAttribution.h */, @@ -420,7 +415,6 @@ 96E5E38E18BBB48A008E7B30 /* ADJActivityState.m in Sources */, 9609BC6A19EEA55800E02303 /* ADJEvent.m in Sources */, 96E5E39518BBB48A008E7B30 /* ADJPackageHandler.m in Sources */, - 965307F81A000DCC00107FF9 /* ADJUserAgent.m in Sources */, 96E5E39318BBB48A008E7B30 /* ADJLogger.m in Sources */, 96E5E39418BBB48A008E7B30 /* ADJPackageBuilder.m in Sources */, 960A8BB91A029A8000F2BB95 /* ADJConfig.m in Sources */, diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 0d904c360..ee9c77e2d 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -15,10 +15,8 @@ #import "ADJTimer.h" #import "ADJUtil.h" #import "UIDevice+ADJAdditions.h" -#import "NSString+ADJAdditions.h" #import "ADJAdjustFactory.h" #import "ADJAttributionHandler.h" -#include "ADJUserAgent.h" static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAttributionFilename = @"AdjustIoAttribution"; @@ -211,7 +209,7 @@ - (void) setAskIn:(BOOL)askIn { #pragma mark - internal - (void)initInternal:(ADJConfig *)adjustConfig { self.adjustConfig = adjustConfig; - self.deviceInfo = [[ADJDeviceInfo alloc] init]; + self.deviceInfo = [ADJDeviceInfo deviceInfoWithSdkPrefix:adjustConfig.sdkPrefix]; if ([adjustConfig.environment isEqualToString:AIEnvironmentProduction]) { [self.logger setLogLevel:ADJLogLevelAssert]; @@ -219,23 +217,6 @@ - (void)initInternal:(ADJConfig *)adjustConfig { [self.logger setLogLevel:adjustConfig.logLevel]; } - NSString *macAddress = UIDevice.currentDevice.adjMacAddress; - NSString *macShort = macAddress.aiRemoveColons; - - self.deviceInfo.macSha1 = macAddress.aiSha1; - self.deviceInfo.macShortMd5 = macShort.aiMd5; - self.deviceInfo.trackingEnabled = UIDevice.currentDevice.adjTrackingEnabled; - self.deviceInfo.idForAdvertisers = UIDevice.currentDevice.adjIdForAdvertisers; - self.deviceInfo.fbAttributionId = UIDevice.currentDevice.adjFbAttributionId; - self.deviceInfo.userAgent = ADJUserAgent.userAgent; - self.deviceInfo.vendorId = UIDevice.currentDevice.adjVendorId; - - if (adjustConfig.sdkPrefix == nil) { - self.deviceInfo.clientSdk = ADJUtil.clientSdk; - } else { - self.deviceInfo.clientSdk = [NSString stringWithFormat:@"%@@%@", adjustConfig.sdkPrefix, ADJUtil.clientSdk]; - } - [self.logger info:@"Tracking of macMd5 is %@", adjustConfig.macMd5TrackingEnabled ? @"enabled" : @"disabled"]; if (adjustConfig.eventBufferingEnabled) { diff --git a/Adjust/ADJDeviceInfo.h b/Adjust/ADJDeviceInfo.h index 02b5eea75..1e4f4c724 100644 --- a/Adjust/ADJDeviceInfo.h +++ b/Adjust/ADJDeviceInfo.h @@ -7,7 +7,6 @@ // #import -#import "ADJUserAgent.h" @interface ADJDeviceInfo : NSObject @@ -19,6 +18,19 @@ @property (nonatomic, copy) NSString *vendorId; @property (nonatomic, copy) NSString *pushToken; @property (nonatomic, copy) NSString *clientSdk; -@property (nonatomic, copy) ADJUserAgent *userAgent; +@property (nonatomic, copy) NSString *bundeIdentifier; +@property (nonatomic, copy) NSString *bundleVersion; +@property (nonatomic, copy) NSString *deviceType; +@property (nonatomic, copy) NSString *deviceName; +@property (nonatomic, copy) NSString *osName; +@property (nonatomic, copy) NSString *systemVersion; +@property (nonatomic, copy) NSString *languageCode; +@property (nonatomic, copy) NSString *countryCode; +@property (nonatomic, copy) NSString *networkType; +@property (nonatomic, copy) NSString *mobileCountryCode; +@property (nonatomic, copy) NSString *mobileNetworkCode; + +- (id) initWithSdkPrefix:(NSString *)sdkPrefix; ++ (ADJDeviceInfo *)deviceInfoWithSdkPrefix:(NSString *)sdkPrefix; @end diff --git a/Adjust/ADJDeviceInfo.m b/Adjust/ADJDeviceInfo.m index a742302b6..9ec7f7e43 100644 --- a/Adjust/ADJDeviceInfo.m +++ b/Adjust/ADJDeviceInfo.m @@ -7,9 +7,121 @@ // #import "ADJDeviceInfo.h" +#import "UIDevice+ADJAdditions.h" +#import "NSString+ADJAdditions.h" +#import "ADJUtil.h" + +#import +#import +#import +#import + +static NSString * const kWiFi = @"WIFI"; +static NSString * const kWWAN = @"WWAN"; @implementation ADJDeviceInfo ++ (ADJDeviceInfo *) deviceInfoWithSdkPrefix:(NSString *)sdkPrefix { + return [[ADJDeviceInfo alloc] initWithSdkPrefix:sdkPrefix]; +} + +- (id) initWithSdkPrefix:(NSString *)sdkPrefix { + self = [super init]; + if (self == nil) return nil; + + NSString *macAddress = UIDevice.currentDevice.adjMacAddress; + NSString *macShort = macAddress.aiRemoveColons; + UIDevice *device = UIDevice.currentDevice; + NSLocale *locale = NSLocale.currentLocale; + NSBundle *bundle = NSBundle.mainBundle; + NSDictionary *infoDictionary = bundle.infoDictionary; + CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; + CTCarrier *carrier = [networkInfo subscriberCellularProvider]; + + self.macSha1 = macAddress.aiSha1; + self.macShortMd5 = macShort.aiMd5; + self.trackingEnabled = UIDevice.currentDevice.adjTrackingEnabled; + self.idForAdvertisers = UIDevice.currentDevice.adjIdForAdvertisers; + self.fbAttributionId = UIDevice.currentDevice.adjFbAttributionId; + self.vendorId = UIDevice.currentDevice.adjVendorId; + self.bundeIdentifier = [infoDictionary objectForKey:(NSString *)kCFBundleIdentifierKey]; + self.bundleVersion = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]; + self.languageCode = [locale objectForKey:NSLocaleLanguageCode]; + self.countryCode = [locale objectForKey:NSLocaleCountryCode]; + self.osName = @"ios"; + self.deviceType = device.adjDeviceType; + self.deviceName = device.adjDeviceName; + self.systemVersion = device.systemVersion; + self.networkType = [self getNetworkStatus]; + self.mobileCountryCode = [carrier mobileCountryCode]; + self.mobileNetworkCode = [carrier mobileNetworkCode]; + + if (sdkPrefix == nil) { + self.clientSdk = ADJUtil.clientSdk; + } else { + self.clientSdk = [NSString stringWithFormat:@"%@@%@", sdkPrefix, ADJUtil.clientSdk]; + } + + return self; +} + +// from https://developer.apple.com/library/ios/samplecode/Reachability/ +- (NSString *)getNetworkStatus { + + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + + const struct sockaddr_in * hostAddress = &zeroAddress; + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *) hostAddress); + + SCNetworkReachabilityFlags flags; + if(!SCNetworkReachabilityGetFlags(reachability, &flags)) { + return nil; + } + + if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) + { + return nil; + } + + 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... + */ + return kWiFi; + } + + 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... + */ + return kWiFi; + } + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + /* + ... but WWAN connections are OK if the calling application is using the CFNetwork APIs. + */ + return kWWAN; + } + + return nil; +} + + -(id)copyWithZone:(NSZone *)zone { ADJDeviceInfo* copy = [[[self class] allocWithZone:zone] init]; @@ -22,7 +134,17 @@ -(id)copyWithZone:(NSZone *)zone copy.vendorId = [self.vendorId copyWithZone:zone]; copy.pushToken = [self.pushToken copyWithZone:zone]; copy.clientSdk = [self.clientSdk copyWithZone:zone]; - copy.userAgent = [self.userAgent copyWithZone:zone]; + copy.bundeIdentifier = [self.bundeIdentifier copyWithZone:zone]; + copy.bundleVersion = [self.bundleVersion copyWithZone:zone]; + copy.deviceType = [self.deviceType copyWithZone:zone]; + copy.deviceName = [self.deviceName copyWithZone:zone]; + copy.osName = [self.osName copyWithZone:zone]; + copy.systemVersion = [self.systemVersion copyWithZone:zone]; + copy.languageCode = [self.languageCode copyWithZone:zone]; + copy.countryCode = [self.countryCode copyWithZone:zone]; + copy.networkType = [self.networkType copyWithZone:zone]; + copy.mobileCountryCode = [self.mobileCountryCode copyWithZone:zone]; + copy.mobileNetworkCode = [self.mobileNetworkCode copyWithZone:zone]; } return copy; diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 905596d2b..8b2838196 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -118,58 +118,53 @@ - (ADJActivityPackage *)defaultActivityPackage { - (NSMutableDictionary *)defaultParameters { NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; - [self constructDeviceInfo:self.deviceInfo withParameter:parameters andConfig:self.adjustConfig]; - [self constructActivityState:self.activityState withParamters:parameters]; + [self injectDeviceInfo:self.deviceInfo andConfig:self.adjustConfig intoParameters:parameters]; + [self injectActivityState:self.activityState intoParamters:parameters]; [self parameters:parameters setBool:!self.hasDelegate forKey:@"needs_attribution_data"]; return parameters; } -- (void) constructDeviceInfo:(ADJDeviceInfo *)deviceInfo - withParameter:(NSMutableDictionary *) parameters - andConfig:(ADJConfig*) adjustConfig{ - - [self constructUserAgent:deviceInfo.userAgent withParameters:parameters]; +- (void) injectDeviceInfo:(ADJDeviceInfo *)deviceInfo + andConfig:(ADJConfig*) adjustConfig + intoParameters:(NSMutableDictionary *) parameters +{ + [self parameters:parameters setString:deviceInfo.macSha1 forKey:@"mac_sha1"]; + [self parameters:parameters setString:deviceInfo.idForAdvertisers forKey:@"idfa"]; + [self parameters:parameters setString:deviceInfo.fbAttributionId forKey:@"fb_id"]; + [self parameters:parameters setInt:deviceInfo.trackingEnabled forKey:@"tracking_enabled"]; + [self parameters:parameters setString:deviceInfo.vendorId forKey:@"idfv"]; + [self parameters:parameters setString:deviceInfo.pushToken forKey:@"push_token"]; + [self parameters:parameters setString:deviceInfo.bundeIdentifier forKey:@"bundle_id"]; + [self parameters:parameters setString:deviceInfo.bundleVersion forKey:@"app_version"]; + [self parameters:parameters setString:deviceInfo.deviceType forKey:@"device_type"]; + [self parameters:parameters setString:deviceInfo.deviceName forKey:@"device_name"]; + [self parameters:parameters setString:deviceInfo.osName forKey:@"os_name"]; + [self parameters:parameters setString:deviceInfo.systemVersion forKey:@"os_version"]; + [self parameters:parameters setString:deviceInfo.languageCode forKey:@"language"]; + [self parameters:parameters setString:deviceInfo.countryCode forKey:@"country"]; + [self parameters:parameters setString:deviceInfo.networkType forKey:@"network_type"]; + [self parameters:parameters setString:deviceInfo.mobileCountryCode forKey:@"mobile_country_code"]; + [self parameters:parameters setString:deviceInfo.mobileNetworkCode forKey:@"mobile_network_code"]; - [self parameters:parameters setString:deviceInfo.macSha1 forKey:@"mac_sha1"]; - [self parameters:parameters setString:deviceInfo.idForAdvertisers forKey:@"idfa"]; - [self parameters:parameters setString:deviceInfo.fbAttributionId forKey:@"fb_id"]; - [self parameters:parameters setInt:deviceInfo.trackingEnabled forKey:@"tracking_enabled"]; - [self parameters:parameters setString:deviceInfo.vendorId forKey:@"idfv"]; - [self parameters:parameters setString:deviceInfo.pushToken forKey:@"push_token"]; if (adjustConfig.macMd5TrackingEnabled) { - [self parameters:parameters setString:deviceInfo.macShortMd5 forKey:@"mac_md5"]; + [self parameters:parameters setString:deviceInfo.macShortMd5 forKey:@"mac_md5"]; } - [self parameters:parameters setString:adjustConfig.appToken forKey:@"app_token"]; - [self parameters:parameters setString:adjustConfig.environment forKey:@"environment"]; + [self parameters:parameters setString:adjustConfig.appToken forKey:@"app_token"]; + [self parameters:parameters setString:adjustConfig.environment forKey:@"environment"]; } -- (void) constructActivityState:(ADJActivityState *)activityState - withParamters:(NSMutableDictionary *)parameters { - [self parameters:parameters setDate1970:activityState.createdAt forKey:@"created_at"]; - [self parameters:parameters setInt:activityState.sessionCount forKey:@"session_count"]; - [self parameters:parameters setInt:activityState.subsessionCount forKey:@"subsession_count"]; - [self parameters:parameters setDuration:activityState.sessionLength forKey:@"session_length"]; - [self parameters:parameters setDuration:activityState.timeSpent forKey:@"time_spent"]; - [self parameters:parameters setString:activityState.uuid forKey:@"ios_uuid"]; - -} +- (void) injectActivityState:(ADJActivityState *)activityState + intoParamters:(NSMutableDictionary *)parameters { + [self parameters:parameters setDate1970:activityState.createdAt forKey:@"created_at"]; + [self parameters:parameters setInt:activityState.sessionCount forKey:@"session_count"]; + [self parameters:parameters setInt:activityState.subsessionCount forKey:@"subsession_count"]; + [self parameters:parameters setDuration:activityState.sessionLength forKey:@"session_length"]; + [self parameters:parameters setDuration:activityState.timeSpent forKey:@"time_spent"]; + [self parameters:parameters setString:activityState.uuid forKey:@"ios_uuid"]; -- (void) constructUserAgent:(ADJUserAgent *)userAgent - withParameters:(NSMutableDictionary *) parameters { - [self parameters:parameters setString:userAgent.bundeIdentifier forKey:@"bundle_id"]; - [self parameters:parameters setString:userAgent.bundleVersion forKey:@"app_version"]; - [self parameters:parameters setString:userAgent.deviceType forKey:@"device_type"]; - [self parameters:parameters setString:userAgent.deviceName forKey:@"device_name"]; - [self parameters:parameters setString:userAgent.osName forKey:@"os_name"]; - [self parameters:parameters setString:userAgent.systemVersion forKey:@"os_version"]; - [self parameters:parameters setString:userAgent.languageCode forKey:@"language"]; - [self parameters:parameters setString:userAgent.countryCode forKey:@"country"]; - [self parameters:parameters setString:userAgent.networkType forKey:@"network_type"]; - [self parameters:parameters setString:userAgent.mobileCountryCode forKey:@"mobile_country_code"]; - [self parameters:parameters setString:userAgent.mobileNetworkCode forKey:@"mobile_network_code"]; } - (NSString *)eventSuffix:(ADJEvent*)event { diff --git a/Adjust/ADJUserAgent.h b/Adjust/ADJUserAgent.h deleted file mode 100644 index 3d558e28f..000000000 --- a/Adjust/ADJUserAgent.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// ADJUserAgent.h -// adjust -// -// Created by Pedro Filipe on 28/10/14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// - -#import - -@interface ADJUserAgent : NSObject - -@property (nonatomic, copy) NSString *bundeIdentifier; -@property (nonatomic, copy) NSString *bundleVersion; -@property (nonatomic, copy) NSString *deviceType; -@property (nonatomic, copy) NSString *deviceName; -@property (nonatomic, copy) NSString *osName; -@property (nonatomic, copy) NSString *systemVersion; -@property (nonatomic, copy) NSString *languageCode; -@property (nonatomic, copy) NSString *countryCode; -@property (nonatomic, copy) NSString *networkType; -@property (nonatomic, copy) NSString *mobileCountryCode; -@property (nonatomic, copy) NSString *mobileNetworkCode; - -+ (ADJUserAgent *)userAgent; - -@end diff --git a/Adjust/ADJUserAgent.m b/Adjust/ADJUserAgent.m deleted file mode 100644 index d0e23c47b..000000000 --- a/Adjust/ADJUserAgent.m +++ /dev/null @@ -1,129 +0,0 @@ -// -// ADJUserAgent.m -// adjust -// -// Created by Pedro Filipe on 28/10/14. -// Copyright (c) 2014 adjust GmbH. All rights reserved. -// - -#import "ADJUserAgent.h" -#import "UIDevice+ADJAdditions.h" - -#import -#import - -#import -#import - - -static NSString * const kWiFi = @"WIFI"; -static NSString * const kWWAN = @"WWAN"; - - -@implementation ADJUserAgent - --(id)copyWithZone:(NSZone *)zone -{ - ADJUserAgent * copy = [[[self class] allocWithZone:zone] init]; - if (copy) { - copy.bundeIdentifier = [self.bundeIdentifier copyWithZone:zone]; - copy.bundleVersion = [self.bundleVersion copyWithZone:zone]; - copy.deviceType = [self.deviceType copyWithZone:zone]; - copy.deviceName = [self.deviceName copyWithZone:zone]; - copy.osName = [self.osName copyWithZone:zone]; - copy.systemVersion = [self.systemVersion copyWithZone:zone]; - copy.languageCode = [self.languageCode copyWithZone:zone]; - copy.countryCode = [self.countryCode copyWithZone:zone]; - copy.networkType = [self.networkType copyWithZone:zone]; - copy.mobileCountryCode = [self.mobileCountryCode copyWithZone:zone]; - copy.mobileNetworkCode = [self.mobileNetworkCode copyWithZone:zone]; - } - - return copy; -} - -+ (ADJUserAgent *)userAgent { - - ADJUserAgent * userAgent = [[ADJUserAgent alloc] init]; - - UIDevice *device = UIDevice.currentDevice; - NSLocale *locale = NSLocale.currentLocale; - NSBundle *bundle = NSBundle.mainBundle; - NSDictionary *infoDictionary = bundle.infoDictionary; - CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; - CTCarrier *carrier = [networkInfo subscriberCellularProvider]; - - userAgent.bundeIdentifier = [infoDictionary objectForKey:(NSString *)kCFBundleIdentifierKey]; - userAgent.bundleVersion = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]; - userAgent.languageCode = [locale objectForKey:NSLocaleLanguageCode]; - userAgent.countryCode = [locale objectForKey:NSLocaleCountryCode]; - userAgent.osName = @"ios"; - - userAgent.deviceType = device.adjDeviceType; - userAgent.deviceName = device.adjDeviceName; - userAgent.systemVersion = device.systemVersion; - userAgent.networkType = [ADJUserAgent getNetworkStatus]; - - userAgent.mobileCountryCode = [carrier mobileCountryCode]; - userAgent.mobileNetworkCode = [carrier mobileNetworkCode]; - - return userAgent; -} - -// from https://developer.apple.com/library/ios/samplecode/Reachability/ -+ (NSString *)getNetworkStatus { - - struct sockaddr_in zeroAddress; - bzero(&zeroAddress, sizeof(zeroAddress)); - zeroAddress.sin_len = sizeof(zeroAddress); - zeroAddress.sin_family = AF_INET; - - const struct sockaddr_in * hostAddress = &zeroAddress; - SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *) hostAddress); - - SCNetworkReachabilityFlags flags; - if(!SCNetworkReachabilityGetFlags(reachability, &flags)) { - return nil; - } - - if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) - { - return nil; - } - - 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... - */ - return kWiFi; - } - - 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... - */ - return kWiFi; - } - } - - if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) - { - /* - ... but WWAN connections are OK if the calling application is using the CFNetwork APIs. - */ - return kWWAN; - } - - return nil; -} - -@end diff --git a/example/example.xcodeproj/project.pbxproj b/example/example.xcodeproj/project.pbxproj index be5256ab4..60f5daa45 100644 --- a/example/example.xcodeproj/project.pbxproj +++ b/example/example.xcodeproj/project.pbxproj @@ -30,7 +30,6 @@ 960FCF891A1B9B7D00282BD4 /* ADJUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF6E1A1B9B7D00282BD4 /* ADJUtil.m */; }; 960FCF8A1A1B9B7D00282BD4 /* ADJEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF701A1B9B7D00282BD4 /* ADJEvent.m */; }; 960FCF8B1A1B9B7D00282BD4 /* ADJDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF721A1B9B7D00282BD4 /* ADJDeviceInfo.m */; }; - 960FCF8C1A1B9B7D00282BD4 /* ADJUserAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF741A1B9B7D00282BD4 /* ADJUserAgent.m */; }; 960FCF8D1A1B9B7D00282BD4 /* ADJAttributionHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF761A1B9B7D00282BD4 /* ADJAttributionHandler.m */; }; 960FCF8E1A1B9B7D00282BD4 /* ADJAttribution.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF781A1B9B7D00282BD4 /* ADJAttribution.m */; }; 960FCF8F1A1B9B7D00282BD4 /* ADJConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF7A1A1B9B7D00282BD4 /* ADJConfig.m */; }; @@ -93,8 +92,6 @@ 960FCF701A1B9B7D00282BD4 /* ADJEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJEvent.m; sourceTree = ""; }; 960FCF711A1B9B7D00282BD4 /* ADJDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJDeviceInfo.h; sourceTree = ""; }; 960FCF721A1B9B7D00282BD4 /* ADJDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJDeviceInfo.m; sourceTree = ""; }; - 960FCF731A1B9B7D00282BD4 /* ADJUserAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJUserAgent.h; sourceTree = ""; }; - 960FCF741A1B9B7D00282BD4 /* ADJUserAgent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUserAgent.m; sourceTree = ""; }; 960FCF751A1B9B7D00282BD4 /* ADJAttributionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJAttributionHandler.h; sourceTree = ""; }; 960FCF761A1B9B7D00282BD4 /* ADJAttributionHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAttributionHandler.m; sourceTree = ""; }; 960FCF771A1B9B7D00282BD4 /* ADJAttribution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJAttribution.h; sourceTree = ""; }; @@ -228,8 +225,6 @@ 960FCF701A1B9B7D00282BD4 /* ADJEvent.m */, 960FCF711A1B9B7D00282BD4 /* ADJDeviceInfo.h */, 960FCF721A1B9B7D00282BD4 /* ADJDeviceInfo.m */, - 960FCF731A1B9B7D00282BD4 /* ADJUserAgent.h */, - 960FCF741A1B9B7D00282BD4 /* ADJUserAgent.m */, 960FCF751A1B9B7D00282BD4 /* ADJAttributionHandler.h */, 960FCF761A1B9B7D00282BD4 /* ADJAttributionHandler.m */, 960FCF771A1B9B7D00282BD4 /* ADJAttribution.h */, @@ -363,7 +358,6 @@ 960FCF841A1B9B7D00282BD4 /* ADJLogger.m in Sources */, 960FCF831A1B9B7D00282BD4 /* ADJAdjustFactory.m in Sources */, 960FCF8A1A1B9B7D00282BD4 /* ADJEvent.m in Sources */, - 960FCF8C1A1B9B7D00282BD4 /* ADJUserAgent.m in Sources */, 960FCF7C1A1B9B7D00282BD4 /* NSString+ADJAdditions.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -557,6 +551,7 @@ 960FCF451A1B9ACE00282BD4 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 960FCF461A1B9ACE00282BD4 /* Build configuration list for PBXNativeTarget "exampleTests" */ = { isa = XCConfigurationList; @@ -565,6 +560,7 @@ 960FCF481A1B9ACE00282BD4 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; From f7a086c1cee4b188b3ddb65798366ce6481ac503 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 16:42:52 +0100 Subject: [PATCH 36/86] Remove sanitization --- Adjust/ADJUtil.m | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 61ae3618e..89a0fc66b 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -31,28 +31,6 @@ + (NSString *)clientSdk { return kClientSdk; } -#pragma mark - sanitization -+ (NSString *)sanitizeU:(NSString *)string { - return [self.class sanitize:string defaultString:@"unknown"]; -} - -+ (NSString *)sanitizeZ:(NSString *)string { - return [self.class sanitize:string defaultString:@"zz"]; -} - -+ (NSString *)sanitize:(NSString *)string defaultString:(NSString *)defaultString { - if (string == nil) { - return defaultString; - } - - NSString *result = [string stringByReplacingOccurrencesOfString:@" " withString:@""]; - if (result.length == 0) { - return defaultString; - } - - return result; -} - // inspired by https://gist.github.com/kevinbarrett/2002382 + (void)excludeFromBackup:(NSString *)path { NSURL *url = [NSURL fileURLWithPath:path]; From a4ed53884d2892642c40f2d69eae7f138c5d11ea Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 16:51:41 +0100 Subject: [PATCH 37/86] Rename NSString extension --- Adjust/ADJAdditions/NSString+ADJAdditions.h | 13 ++++++------ Adjust/ADJAdditions/NSString+ADJAdditions.m | 23 ++++++--------------- Adjust/ADJAdditions/UIDevice+ADJAdditions.m | 14 ++++++------- Adjust/ADJAttributionHandler.m | 2 +- Adjust/ADJDeviceInfo.m | 6 +++--- Adjust/ADJRequestHandler.m | 2 +- Adjust/ADJUtil.m | 4 ++-- 7 files changed, 26 insertions(+), 38 deletions(-) diff --git a/Adjust/ADJAdditions/NSString+ADJAdditions.h b/Adjust/ADJAdditions/NSString+ADJAdditions.h index 09271fe0f..6b170ad5e 100644 --- a/Adjust/ADJAdditions/NSString+ADJAdditions.h +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.h @@ -9,14 +9,13 @@ @interface NSString(ADJAdditions) -- (NSString *)aiTrim; -- (NSString *)aiQuote; -- (NSString *)aiMd5; -- (NSString *)aiSha1; -- (NSString *)aiUrlEncode; -- (NSString *)aiRemoveColons; +- (NSString *)adjTrim; +- (NSString *)adjMd5; +- (NSString *)adjSha1; +- (NSString *)adjUrlEncode; +- (NSString *)adjRemoveColons; -+ (NSString *)aiJoin:(NSString *)strings, ...; ++ (NSString *)adjJoin:(NSString *)strings, ...; + (BOOL) adjIsEqual:(NSString *)first toString:(NSString *)second; @end diff --git a/Adjust/ADJAdditions/NSString+ADJAdditions.m b/Adjust/ADJAdditions/NSString+ADJAdditions.m index ed07f3833..11af74c8a 100644 --- a/Adjust/ADJAdditions/NSString+ADJAdditions.m +++ b/Adjust/ADJAdditions/NSString+ADJAdditions.m @@ -12,22 +12,11 @@ @implementation NSString(ADJAdditions) -- (NSString *)aiTrim { +- (NSString *)adjTrim { return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } -- (NSString *)aiQuote { - if (self == nil) { - return nil; - } - - if ([self rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]].location == NSNotFound) { - return self; - } - return [NSString stringWithFormat:@"'%@'", self]; -} - -- (NSString *)aiMd5 { +- (NSString *)adjMd5 { const char *cStr = [self UTF8String]; unsigned char digest[16]; CC_MD5(cStr, (CC_LONG)strlen(cStr), digest); @@ -39,7 +28,7 @@ - (NSString *)aiMd5 { return output; } -- (NSString *)aiSha1 { +- (NSString *)adjSha1 { const char *cstr = [self cStringUsingEncoding:NSUTF8StringEncoding]; NSData *data = [NSData dataWithBytes:cstr length:self.length]; uint8_t digest[CC_SHA1_DIGEST_LENGTH]; @@ -52,7 +41,7 @@ - (NSString *)aiSha1 { return output; } --(NSString *)aiUrlEncode { +-(NSString *)adjUrlEncode { return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( NULL, (CFStringRef)self, @@ -61,11 +50,11 @@ -(NSString *)aiUrlEncode { CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding))); } -- (NSString *)aiRemoveColons { +- (NSString *)adjRemoveColons { return [self stringByReplacingOccurrencesOfString:@":" withString:@""]; } -+ (NSString *)aiJoin:(NSString *)first, ... { ++ (NSString *)adjJoin:(NSString *)first, ... { NSString *iter, *result = first; va_list strings; va_start(strings, first); diff --git a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m index 4c7b6998a..ec9b65eaa 100644 --- a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m +++ b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m @@ -26,9 +26,9 @@ @implementation UIDevice(ADJAdditions) - (BOOL)adjTrackingEnabled { #if !ADJUST_NO_IDFA - NSString *className = [NSString aiJoin:@"A", @"S", @"identifier", @"manager", nil]; - NSString *keyManager = [NSString aiJoin:@"shared", @"manager", nil]; - NSString *keyEnabled = [NSString aiJoin:@"is", @"advertising", @"tracking", @"enabled", nil]; + NSString *className = [NSString adjJoin:@"A", @"S", @"identifier", @"manager", nil]; + NSString *keyManager = [NSString adjJoin:@"shared", @"manager", nil]; + NSString *keyEnabled = [NSString adjJoin:@"is", @"advertising", @"tracking", @"enabled", nil]; Class class = NSClassFromString(className); if (class) { @@ -55,10 +55,10 @@ - (BOOL)adjTrackingEnabled { - (NSString *)adjIdForAdvertisers { #if !ADJUST_NO_IDFA - NSString *className = [NSString aiJoin:@"A", @"S", @"identifier", @"manager", nil]; - NSString *keyManager = [NSString aiJoin:@"shared", @"manager", nil]; - NSString *keyIdentifier = [NSString aiJoin:@"advertising", @"identifier", nil]; - NSString *keyString = [NSString aiJoin:@"UUID", @"string", nil]; + NSString *className = [NSString adjJoin:@"A", @"S", @"identifier", @"manager", nil]; + NSString *keyManager = [NSString adjJoin:@"shared", @"manager", nil]; + NSString *keyIdentifier = [NSString adjJoin:@"advertising", @"identifier", nil]; + NSString *keyString = [NSString adjJoin:@"UUID", @"string", nil]; Class class = NSClassFromString(className); if (class) { diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 4a42a272c..c976f42d9 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -136,7 +136,7 @@ -(void) getAttributionInternal { NSDictionary *jsonDict = [ADJUtil buildJsonDict:responseString]; if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) { - [self.logger error:@"Failed to parse json attribution response: %@", responseString.aiTrim]; + [self.logger error:@"Failed to parse json attribution response: %@", responseString.adjTrim]; return; } diff --git a/Adjust/ADJDeviceInfo.m b/Adjust/ADJDeviceInfo.m index 9ec7f7e43..953588737 100644 --- a/Adjust/ADJDeviceInfo.m +++ b/Adjust/ADJDeviceInfo.m @@ -30,7 +30,7 @@ - (id) initWithSdkPrefix:(NSString *)sdkPrefix { if (self == nil) return nil; NSString *macAddress = UIDevice.currentDevice.adjMacAddress; - NSString *macShort = macAddress.aiRemoveColons; + NSString *macShort = macAddress.adjRemoveColons; UIDevice *device = UIDevice.currentDevice; NSLocale *locale = NSLocale.currentLocale; NSBundle *bundle = NSBundle.mainBundle; @@ -38,8 +38,8 @@ - (id) initWithSdkPrefix:(NSString *)sdkPrefix { CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; CTCarrier *carrier = [networkInfo subscriberCellularProvider]; - self.macSha1 = macAddress.aiSha1; - self.macShortMd5 = macShort.aiMd5; + self.macSha1 = macAddress.adjSha1; + self.macShortMd5 = macShort.adjMd5; self.trackingEnabled = UIDevice.currentDevice.adjTrackingEnabled; self.idForAdvertisers = UIDevice.currentDevice.adjIdForAdvertisers; self.fbAttributionId = UIDevice.currentDevice.adjFbAttributionId; diff --git a/Adjust/ADJRequestHandler.m b/Adjust/ADJRequestHandler.m index 1365f60e5..5bc703e21 100644 --- a/Adjust/ADJRequestHandler.m +++ b/Adjust/ADJRequestHandler.m @@ -90,7 +90,7 @@ - (void)sendInternal:(ADJActivityPackage *)package sendToPackageHandler:(BOOL)se if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) { NSString * activityKindString = ADJActivityKindToString(package.activityKind); - [self.logger error:@"Failed to parse json %@ response: %@", activityKindString, responseString.aiTrim]; + [self.logger error:@"Failed to parse json %@ response: %@", activityKindString, responseString.adjTrim]; if (sendToPackageHandler) { [self.packageHandler closeFirstPackage]; } diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 89a0fc66b..9a5ed33d8 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -143,14 +143,14 @@ + (NSString *) queryString:(NSDictionary *)parameters { NSMutableArray *pairs = [NSMutableArray array]; for (NSString *key in parameters) { NSString *value = [parameters objectForKey:key]; - NSString *escapedValue = [value aiUrlEncode]; + NSString *escapedValue = [value adjUrlEncode]; NSString *pair = [NSString stringWithFormat:@"%@=%@", key, escapedValue]; [pairs addObject:pair]; } double now = [NSDate.date timeIntervalSince1970]; NSString *dateString = [ADJUtil formatSeconds1970:now]; - NSString *escapedDate = [dateString aiUrlEncode]; + NSString *escapedDate = [dateString adjUrlEncode]; NSString *sentAtPair = [NSString stringWithFormat:@"%@=%@", @"sent_at", escapedDate]; [pairs addObject:sentAtPair]; From ff0943c182f9188319f9fcccec2a0517ccff315f Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 16:53:59 +0100 Subject: [PATCH 38/86] Attribution hash from tracker name --- Adjust/ADJAttribution.m | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Adjust/ADJAttribution.m b/Adjust/ADJAttribution.m index edf2252a3..5f85cb162 100644 --- a/Adjust/ADJAttribution.m +++ b/Adjust/ADJAttribution.m @@ -110,17 +110,7 @@ - (BOOL)isEqual:(id)object { } - (NSUInteger)hash { - NSUInteger prime = 31; - NSUInteger result = 1; - - result = prime * result + [self.trackerToken hash]; - result = prime * result + [self.trackerName hash]; - result = prime * result + [self.network hash]; - result = prime * result + [self.campaign hash]; - result = prime * result + [self.adgroup hash]; - result = prime * result + [self.creative hash]; - - return result; + return [self.trackerName hash]; } #pragma mark NSCoding From cf69568cfab0272b5afdb426c042eda04d1957e6 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 16:54:36 +0100 Subject: [PATCH 39/86] Renamed adjustAttributionCallback --- Adjust/ADJActivityHandler.m | 4 ++-- Adjust/ADJConfig.h | 8 +------- example/example/AppDelegate.m | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index ee9c77e2d..9236a9f4a 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -183,10 +183,10 @@ - (BOOL)updateAttribution:(ADJAttribution *)attribution { } - (void)launchAttributionDelegate{ - if (![self.delegate respondsToSelector:@selector(adjustAttributionCallback:)]) { + if (![self.delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { return; } - [self.delegate performSelectorOnMainThread:@selector(adjustAttributionCallback:) + [self.delegate performSelectorOnMainThread:@selector(adjustAttributionChanged:) withObject:self.attribution waitUntilDone:NO]; } diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index fc1cfa060..e2049e512 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -16,13 +16,7 @@ @protocol AdjustDelegate @optional -/** - * Optional delegate method that will get called when a tracking attempt finished - * - * @param responseData The response data containing information about the activity - * and it's server response. See AIResponseData for details. - */ -- (void)adjustAttributionCallback:(ADJAttribution *)attribution; +- (void)adjustAttributionChanged:(ADJAttribution *)attribution; @end diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m index f06d29dd6..63df41405 100644 --- a/example/example/AppDelegate.m +++ b/example/example/AppDelegate.m @@ -44,7 +44,7 @@ - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } -- (void)adjustAttributionCallback:(ADJAttribution *)attribution { +- (void)adjustAttributionChanged:(ADJAttribution *)attribution { NSLog(@"adjust attribution %@", attribution); } From 358e56cfbe465bf5823c52189ca595d5cd186ebc Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 17:02:29 +0100 Subject: [PATCH 40/86] Fix offline mode --- Adjust/ADJActivityHandler.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 9236a9f4a..3edbe32a5 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -43,6 +43,7 @@ @interface ADJActivityHandler() @property (nonatomic, copy) ADJConfig *adjustConfig; @property (nonatomic, assign) BOOL enabled; +@property (nonatomic, assign) BOOL offline; @property (nonatomic, copy) ADJDeviceInfo* deviceInfo; @@ -190,12 +191,16 @@ - (void)launchAttributionDelegate{ withObject:self.attribution waitUntilDone:NO]; } -- (void)setOfflineMode:(BOOL)enabled { - if (enabled) { +- (void)setOfflineMode:(BOOL)isOffline { + if (isOffline) { + self.offline = YES; [self endInternal]; + [self.logger info:@"Pausing package handler to put in offline mode"]; } else { + self.offline = NO; [self.packageHandler resumeSending]; [self startTimer]; + [self.logger info:@"Resuming package handler to put in online mode"]; } } @@ -255,7 +260,9 @@ - (void)startInternal { return; } - [self.packageHandler resumeSending]; + if (!self.offline) { + [self.packageHandler resumeSending]; + } [self startTimer]; double now = [NSDate.date timeIntervalSince1970]; From 023232532ef2d8d87229db0d2b735020aa599b05 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 17:11:59 +0100 Subject: [PATCH 41/86] Format pointer vars --- Adjust/ADJActivityHandler.m | 12 ++++++------ Adjust/ADJAttribution.m | 2 +- Adjust/ADJAttributionHandler.m | 12 ++++++------ Adjust/ADJPackageBuilder.h | 6 +++--- Adjust/ADJPackageBuilder.m | 4 ++-- Adjust/ADJRequestHandler.m | 2 +- Adjust/ADJUtil.m | 2 +- Adjust/Adjust.m | 2 +- example/example/ExampleAdjustHelper.m | 14 ++++++-------- example/example/ViewController.m | 2 +- 10 files changed, 28 insertions(+), 30 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 3edbe32a5..e8b4bb5a7 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -106,7 +106,7 @@ - (void)finishedTrackingWithResponse:(NSDictionary *)jsonDict{ - (void)launchDeepLink:(NSDictionary *)jsonDict{ if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; - NSString * deepLink = [jsonDict objectForKey:@"deeplink"]; + NSString *deepLink = [jsonDict objectForKey:@"deeplink"]; if (deepLink == nil) return; NSURL* deepLinkUrl = [NSURL URLWithString:deepLink]; @@ -237,10 +237,10 @@ - (void)initInternal:(ADJConfig *)adjustConfig { class:[ADJActivityState class]]; self.packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:self]; - ADJPackageBuilder * attributionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + ADJPackageBuilder *attributionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState andConfig:self.adjustConfig]; - ADJActivityPackage * attributionPackage = [attributionBuilder buildAttributionPackage]; + ADJActivityPackage *attributionPackage = [attributionBuilder buildAttributionPackage]; self.attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self withMaxDelay:nil withAttributionPackage:attributionPackage]; @@ -366,7 +366,7 @@ - (void)eventInternal:(ADJEvent *)event - (void) appWillOpenUrlInternal:(NSURL *)url { NSArray* queryArray = [url.query componentsSeparatedByString:@"&"]; NSMutableDictionary* adjustDeepLinks = [NSMutableDictionary dictionary]; - ADJAttribution * attribution = [[ADJAttribution alloc] init]; + ADJAttribution *attribution = [[ADJAttribution alloc] init]; BOOL adjustParamsFound = NO; for (NSString* fieldValuePair in queryArray) { @@ -394,13 +394,13 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { return; } - ADJPackageBuilder * clickBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState andConfig:self.adjustConfig]; clickBuilder.deeplinkParameters = adjustDeepLinks; clickBuilder.attribution = attribution; - ADJActivityPackage * clickPackage = [clickBuilder buildClickPackage:@"deeplink"]; + ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"deeplink"]; [self.packageHandler sendClickPackage:clickPackage]; } diff --git a/Adjust/ADJAttribution.m b/Adjust/ADJAttribution.m index 5f85cb162..774dc6134 100644 --- a/Adjust/ADJAttribution.m +++ b/Adjust/ADJAttribution.m @@ -60,7 +60,7 @@ - (BOOL)isEqualToAttribution:(ADJAttribution *)attribution { } - (NSDictionary *)dictionary { - NSMutableDictionary * responseDataDic = [NSMutableDictionary dictionary]; + NSMutableDictionary *responseDataDic = [NSMutableDictionary dictionary]; if (self.trackerToken != nil) { [responseDataDic setObject:self.trackerToken forKey:@"trackerToken"]; diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index c976f42d9..0c25153bc 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -81,9 +81,9 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; NSDictionary* jsonAttribution = [jsonDict objectForKey:@"attribution"]; - ADJAttribution * attribution = [ADJAttribution dataWithJsonDict:jsonAttribution]; + ADJAttribution *attribution = [ADJAttribution dataWithJsonDict:jsonAttribution]; - NSNumber * timer_milliseconds = [jsonDict objectForKey:@"ask_in"]; + NSNumber *timer_milliseconds = [jsonDict objectForKey:@"ask_in"]; if (timer_milliseconds == nil) { BOOL updated = [self.activityHandler updateAttribution:attribution]; @@ -164,10 +164,10 @@ - (NSMutableURLRequest *)request { } - (NSURL *)url { - NSString * parameters = [ADJUtil queryString:self.attributionPackage.parameters]; - NSString * relativePath = [NSString stringWithFormat:@"%@?%@", self.attributionPackage.path, parameters]; - NSURL * baseUrl = [NSURL URLWithString:ADJUtil.baseUrl]; - NSURL * url = [NSURL URLWithString:relativePath relativeToURL:baseUrl]; + NSString *parameters = [ADJUtil queryString:self.attributionPackage.parameters]; + NSString *relativePath = [NSString stringWithFormat:@"%@?%@", self.attributionPackage.path, parameters]; + NSURL *baseUrl = [NSURL URLWithString:ADJUtil.baseUrl]; + NSURL *url = [NSURL URLWithString:relativePath relativeToURL:baseUrl]; return url; } diff --git a/Adjust/ADJPackageBuilder.h b/Adjust/ADJPackageBuilder.h index 6cd740f20..1b22fee17 100644 --- a/Adjust/ADJPackageBuilder.h +++ b/Adjust/ADJPackageBuilder.h @@ -18,9 +18,9 @@ @property (nonatomic, copy) ADJActivityState *activityState; @property (nonatomic, copy) ADJConfig *adjustConfig; @property (nonatomic, assign) BOOL hasDelegate; -@property (nonatomic, copy) ADJAttribution * attribution; -@property (nonatomic, copy) NSDate * iAdImpressionDate; -@property (nonatomic, copy) NSDate * appPurchaseDate; +@property (nonatomic, copy) ADJAttribution *attribution; +@property (nonatomic, copy) NSDate *iAdImpressionDate; +@property (nonatomic, copy) NSDate *appPurchaseDate; @property (nonatomic, copy) NSDictionary* deeplinkParameters; - (id) initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 8b2838196..ce990f01f 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -236,7 +236,7 @@ - (void)parameters:(NSMutableDictionary *)parameters setNumberBool:(NSNumber *)v - (void)parameters:(NSMutableDictionary *)parameters setNumber:(NSNumber *)value forKey:(NSString *)key { if (value == nil); - NSString * numberString = [value stringValue]; + NSString *numberString = [value stringValue]; [self parameters:parameters setString:numberString forKey:key]; } @@ -251,7 +251,7 @@ - (NSMutableDictionary *) joinParamters:(NSMutableDictionary *)permanentParamete return permanentParameters; } - NSMutableDictionary * joinedParameters = [[NSMutableDictionary alloc] initWithDictionary:permanentParameters]; + NSMutableDictionary *joinedParameters = [[NSMutableDictionary alloc] initWithDictionary:permanentParameters]; [joinedParameters addEntriesFromDictionary:parameters]; return joinedParameters; diff --git a/Adjust/ADJRequestHandler.m b/Adjust/ADJRequestHandler.m index 5bc703e21..264e06c68 100644 --- a/Adjust/ADJRequestHandler.m +++ b/Adjust/ADJRequestHandler.m @@ -89,7 +89,7 @@ - (void)sendInternal:(ADJActivityPackage *)package sendToPackageHandler:(BOOL)se NSDictionary *jsonDict = [ADJUtil buildJsonDict:responseString]; if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) { - NSString * activityKindString = ADJActivityKindToString(package.activityKind); + NSString *activityKindString = ADJActivityKindToString(package.activityKind); [self.logger error:@"Failed to parse json %@ response: %@", activityKindString, responseString.adjTrim]; if (sendToPackageHandler) { [self.packageHandler closeFirstPackage]; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 9a5ed33d8..8717afee5 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -18,7 +18,7 @@ static NSString * const kClientSdk = @"ios4.0.0"; static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'Z"; -static NSDateFormatter * dateFormat; +static NSDateFormatter *dateFormat; #pragma mark - @implementation ADJUtil diff --git a/Adjust/Adjust.m b/Adjust/Adjust.m index e1acd4823..da25d6abf 100644 --- a/Adjust/Adjust.m +++ b/Adjust/Adjust.m @@ -61,7 +61,7 @@ + (void)setOfflineMode:(BOOL)enabled { } + (id)getInstance { - static Adjust * defaultInstance = nil; + static Adjust *defaultInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ defaultInstance = [[self alloc] init]; diff --git a/example/example/ExampleAdjustHelper.m b/example/example/ExampleAdjustHelper.m index b7253417d..1f52b149a 100644 --- a/example/example/ExampleAdjustHelper.m +++ b/example/example/ExampleAdjustHelper.m @@ -14,9 +14,9 @@ @implementation ExampleAdjustHelper + (void) initAdjust: (NSObject *) adjustDelegate { - NSString * yourAppToken = @"dgau42x652ul"; - NSString * enviroment = AIEnvironmentSandbox; - ADJConfig * adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; + NSString *yourAppToken = @"dgau42x652ul"; + NSString *enviroment = AIEnvironmentSandbox; + ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; // change the log level [adjustConfig setLogLevel:ADJLogLevelVerbose]; @@ -30,13 +30,12 @@ + (void) initAdjust: (NSObject *) adjustDelegate { // set an attribution delegate [adjustConfig setDelegate:adjustDelegate]; - Adjust * adjust = [Adjust getInstance]; - [adjust appDidLaunch:adjustConfig]; + [Adjust appDidLaunch:adjustConfig]; } + (void) triggerEvent { - ADJEvent * event = [ADJEvent eventWithEventToken:@"gd6a8u"]; + ADJEvent *event = [ADJEvent eventWithEventToken:@"gd6a8u"]; // add revenue 1 cent of an euro [event setRevenue:0.015 currency:@"EUR"]; @@ -47,8 +46,7 @@ + (void) triggerEvent { // add partner parameteres to all events and sessions [event addPartnerParameter:@"fooEvent" andValue:@"bar"]; - Adjust * adjust = [Adjust getInstance]; - [adjust trackEvent:event]; + [Adjust trackEvent:event]; } @end diff --git a/example/example/ViewController.m b/example/example/ViewController.m index e23ff199d..3ca08f0f3 100644 --- a/example/example/ViewController.m +++ b/example/example/ViewController.m @@ -39,7 +39,7 @@ - (IBAction)clickTrackEvent:(UIButton *)sender { [ExampleAdjustHelper triggerEvent]; } - (IBAction)clickDisableSdk:(UIButton *)sender { - NSString * txtDisableSdk = self.btnDisableSdk.titleLabel.text; + NSString *txtDisableSdk = self.btnDisableSdk.titleLabel.text; if ([txtDisableSdk hasPrefix:@"Disable"]) { [Adjust setEnabled:NO]; From 9be0b7677fc3865f0d8bea0335a14e6c76fa0407 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 17:14:36 +0100 Subject: [PATCH 42/86] Change queues priority --- Adjust/ADJAttributionHandler.m | 2 +- Adjust/ADJRequestHandler.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 0c25153bc..420bb9bca 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -46,7 +46,7 @@ - (id)initWithActivityHandler:(id) activityHandler self = [super init]; if (self == nil) return nil; - self.internalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); + self.internalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); self.activityHandler = activityHandler; self.logger = ADJAdjustFactory.logger; self.attributionPackage = attributionPackage; diff --git a/Adjust/ADJRequestHandler.m b/Adjust/ADJRequestHandler.m index 264e06c68..972d16c40 100644 --- a/Adjust/ADJRequestHandler.m +++ b/Adjust/ADJRequestHandler.m @@ -54,7 +54,7 @@ - (void)sendPackage:(ADJActivityPackage *)activityPackage { } - (void)sendClickPackage:(ADJActivityPackage *)clickPackage { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self sendInternal:clickPackage sendToPackageHandler:NO]; }); } From 6485b4a6e0e7fd114c759c69e1b443fdb06d1a44 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 17:15:47 +0100 Subject: [PATCH 43/86] Fix has delegate parameter --- Adjust/ADJPackageBuilder.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index ce990f01f..4203c3ff9 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -25,7 +25,7 @@ - (id)initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo self.activityState = activityState; self.adjustConfig = adjustConfig; - if (adjustConfig.delegate) { + if (adjustConfig.delegate != nil) { self.hasDelegate = YES; } else { self.hasDelegate = NO; @@ -99,7 +99,7 @@ - (ADJActivityPackage *)buildAttributionPackage { [self parameters:parameters setString:self.adjustConfig.appToken forKey:@"app_token"]; [self parameters:parameters setString:self.adjustConfig.environment forKey:@"environment"]; [self parameters:parameters setString:self.activityState.uuid forKey:@"ios_uuid"]; - [self parameters:parameters setBool:!self.hasDelegate forKey:@"needs_attribution_data"]; + [self parameters:parameters setBool:self.hasDelegate forKey:@"needs_attribution_data"]; ADJActivityPackage *attributionPackage = [self defaultActivityPackage]; attributionPackage.path = @"/attribution"; @@ -120,7 +120,7 @@ - (NSMutableDictionary *)defaultParameters { [self injectDeviceInfo:self.deviceInfo andConfig:self.adjustConfig intoParameters:parameters]; [self injectActivityState:self.activityState intoParamters:parameters]; - [self parameters:parameters setBool:!self.hasDelegate forKey:@"needs_attribution_data"]; + [self parameters:parameters setBool:self.hasDelegate forKey:@"needs_attribution_data"]; return parameters; } From 54d9f3d47d21ac2b23787720a3b3fd44bccf1f57 Mon Sep 17 00:00:00 2001 From: Pedro Filipe Date: Thu, 4 Dec 2014 17:43:00 +0100 Subject: [PATCH 44/86] First draft of migration --- doc/migrate.md | 77 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/doc/migrate.md b/doc/migrate.md index df6e41af9..64485d2cd 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -1,4 +1,79 @@ -## Migrate your adjust SDK for iOS to v3.4.0 from v3.0.0 +## Migrate your adjust SDK for iOS to v4.0.0 from v3.4.0 + +We changed the way to configure the SDK after launching. It should be done before with a new object `ADJConfig`. See an example of how it would look before and after the migration: + +```objc +// before migration + +// AppDelegate.h +#import "Adjust.h" +@interface AppDelegate : UIResponder + +// AppDelegate.m + +[Adjust appDidLaunch:@"{YourAppToken}"]; +[Adjust setLogLevel:AILogLevelInfo]; +[Adjust setEnvironment:AIEnvironmentSandbox]; +[Adjust setDelegate:self]; + +// ... +- (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData { + // ... +} +// after migration + +// AppDelegate.h +#import "ADJConfig.h" +@interface AppDelegate : UIResponder + +// AppDelegate.m +#import "Adjust.h" + +NSString *yourAppToken = @"{YourAppToken}"; +NSString *enviroment = AIEnvironmentSandbox; +ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; +[adjustConfig setLogLevel:ADJLogLevelVerbose]; +[adjustConfig setDelegate:self]; +[Adjust appDidLaunch:adjustConfig]; + +// ... +- (void)adjustAttributionChanged:(ADJAttribution *)attribution { + // ... +} +``` + +We also changed the way to track events and revenues. Now it is all configured with the `ADJEvent` object. You can follow another example of how an event/revenue would be tracked before and after the migration: + +```objc +// before the migration +#import "Adjust.h" + +NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; +[parameters setObject:@"value" forKey:@"key"]; +[parameters setObject:@"bar" forKey:@"foo"]; + +[Adjust trackEvent:@"abc123" withParameters:parameters]; + +//[Adjust trackRevenue:1.0]; not possible in the version. You will have to create an app token +[Adjust trackRevenue:1.0 transactionId:transaction.transactionIdentifier forEvent:@"xyz987"]; + +// after the migration +#import "ADJEvent.h" +#import "Adjust.h" + +ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"]; +[event addCallbackParameter:@"key" andValue:@"value"]; +[event addCallbackParameter:@"foo" andValue:@"bar"]; +[Adjust trackEvent:event]; + +ADJEvent *revenue = [ADJEvent eventWithEventToken:@"xyz987"]; +[revenue setRevenue:0.01 currency:@"EUR"]; // You have to include the currency +[revenue setTransactionId:transaction.transactionIdentifier]; +[Adjust trackEvent:revenue]; + +``` + +## Additional steps if you come from v3.0.0 We added an optional parameter `transactionId` to our `trackRevenue` methods. If you are tracking In-App Purchases you might want to pass in the transaction identifier provided by Apple to avoid duplicate revenue tracking. It should look roughly like this: From 8a4cedfefd6ee8176c7191de4f832c02c28ba1c5 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 4 Dec 2014 19:25:10 +0100 Subject: [PATCH 45/86] Build Attribution handler --- Adjust/ADJActivityHandler.m | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index e8b4bb5a7..2b019701d 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -237,13 +237,8 @@ - (void)initInternal:(ADJConfig *)adjustConfig { class:[ADJActivityState class]]; self.packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:self]; - ADJPackageBuilder *attributionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo - andActivityState:self.activityState - andConfig:self.adjustConfig]; - ADJActivityPackage *attributionPackage = [attributionBuilder buildAttributionPackage]; - self.attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self - withMaxDelay:nil - withAttributionPackage:attributionPackage]; + + self.attributionHandler = [self buildAttributionHandler]; self.attribution = [ADJUtil readObject:kAttributionFilename objectName:kAttributionName @@ -252,6 +247,18 @@ - (void)initInternal:(ADJConfig *)adjustConfig { [self startInternal]; } +- (id) buildAttributionHandler { + ADJPackageBuilder *attributionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + andActivityState:self.activityState + andConfig:self.adjustConfig]; + ADJActivityPackage *attributionPackage = [attributionBuilder buildAttributionPackage]; + id attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self + withMaxDelay:nil + withAttributionPackage:attributionPackage]; + + return attributionHandler; +} + - (void)startInternal { if (![self checkAppTokenNotNil:self.adjustConfig.appToken]) return; From 62df0cf295d694286df5a89d445c0be2015af1b7 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 11:31:24 +0100 Subject: [PATCH 46/86] Refac write read objects --- Adjust/ADJActivityHandler.m | 54 +++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 2b019701d..959eac85b 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -20,8 +20,6 @@ static NSString * const kActivityStateFilename = @"AdjustIoActivityState"; static NSString * const kAttributionFilename = @"AdjustIoAttribution"; -static NSString * const kActivityStateName = @"activity state"; -static NSString * const kAttributionName = @"attribution"; static NSString * const kAdjustPrefix = @"adjust_"; static const char * const kInternalQueueName = "io.adjust.ActivityQueue"; @@ -126,7 +124,7 @@ - (void)setEnabled:(BOOL)enabled { _enabled = enabled; if (self.activityState != nil) { self.activityState.enabled = enabled; - [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [self writeActivityState]; } if (enabled) { [self trackSubsessionStart]; @@ -178,7 +176,7 @@ - (BOOL)updateAttribution:(ADJAttribution *)attribution { return NO; } self.attribution = attribution; - [ADJUtil writeObject:self.attribution filename:kAttributionFilename objectName:kAttributionName]; + [self writeAttribution]; return YES; } @@ -206,9 +204,7 @@ - (void)setOfflineMode:(BOOL)isOffline { - (void) setAskIn:(BOOL)askIn { self.activityState.askIn = askIn; - [ADJUtil writeObject:self.activityState - filename:kActivityStateFilename - objectName:kActivityStateName]; + [self writeActivityState]; } #pragma mark - internal @@ -232,17 +228,13 @@ - (void)initInternal:(ADJConfig *)adjustConfig { [[UIDevice currentDevice] adjSetIad:self]; - self.activityState = [ADJUtil readObject:kActivityStateFilename - objectName:kActivityStateName - class:[ADJActivityState class]]; + [self readAttribution]; self.packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:self]; self.attributionHandler = [self buildAttributionHandler]; - self.attribution = [ADJUtil readObject:kAttributionFilename - objectName:kAttributionName - class:[ADJAttribution class]]; + [self readAttribution]; [self startInternal]; } @@ -283,7 +275,7 @@ - (void)startInternal { [self transferSessionPackage]; [self.activityState resetSessionAttributes:now]; self.activityState.enabled = _enabled; - [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [self writeActivityState]; return; } @@ -291,7 +283,7 @@ - (void)startInternal { if (lastInterval < 0) { [self.logger error:@"Time travel!"]; self.activityState.lastActivity = now; - [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [self writeActivityState]; return; } @@ -303,7 +295,7 @@ - (void)startInternal { [self transferSessionPackage]; [self.activityState resetSessionAttributes:now]; - [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [self writeActivityState]; return; } @@ -312,7 +304,7 @@ - (void)startInternal { self.activityState.subsessionCount++; self.activityState.sessionLength += lastInterval; self.activityState.lastActivity = now; - [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [self writeActivityState]; [self.logger info:@"Processed Subsession %d of Session %d", self.activityState.subsessionCount, self.activityState.sessionCount]; @@ -332,7 +324,7 @@ - (void)endInternal { [self stopTimer]; double now = [NSDate.date timeIntervalSince1970]; [self updateActivityState:now]; - [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [self writeActivityState]; } - (void)eventInternal:(ADJEvent *)event @@ -367,7 +359,7 @@ - (void)eventInternal:(ADJEvent *)event [self.packageHandler sendFirstPackage]; } - [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [self writeActivityState]; } - (void) appWillOpenUrlInternal:(NSURL *)url { @@ -472,6 +464,28 @@ - (BOOL)updateActivityState:(double)now { return (lastInterval > ADJAdjustFactory.subsessionInterval); } +- (void)writeActivityState { + [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:@"activity state"]; +} + +- (void)writeAttribution { + [ADJUtil writeObject:self.attribution filename:kAttributionFilename objectName:@"attribution"]; +} + +- (void)readActivityState { + self.activityState = [ADJUtil readObject:kActivityStateFilename + objectName:@"activity state" + class:[ADJActivityState class]]; +} + +- (void)readAttribution { + self.attribution = [ADJUtil readObject:kAttributionFilename + objectName:@"attribution" + class:[ADJAttribution class]]; +} + + + - (void)transferSessionPackage { ADJPackageBuilder *sessionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState @@ -504,7 +518,7 @@ - (void)timerFired { [self.packageHandler sendFirstPackage]; double now = [NSDate.date timeIntervalSince1970]; if ([self updateActivityState:now]) { - [ADJUtil writeObject:self.activityState filename:kActivityStateFilename objectName:kActivityStateName]; + [self writeActivityState]; } } From 04e5b8949e143d58df38b0ac68ee0e18dd42402c Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 11:33:43 +0100 Subject: [PATCH 47/86] Escape url key --- Adjust/ADJUtil.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 8717afee5..a301e6f57 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -144,7 +144,8 @@ + (NSString *) queryString:(NSDictionary *)parameters { for (NSString *key in parameters) { NSString *value = [parameters objectForKey:key]; NSString *escapedValue = [value adjUrlEncode]; - NSString *pair = [NSString stringWithFormat:@"%@=%@", key, escapedValue]; + NSString *escapedKey = [key adjUrlEncode]; + NSString *pair = [NSString stringWithFormat:@"%@=%@", escapedKey, escapedValue]; [pairs addObject:pair]; } From 6f7375199bc2129779c3700e1d99197bc7e4aa9e Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 11:35:45 +0100 Subject: [PATCH 48/86] Rename iad click time --- Adjust/ADJActivityHandler.m | 6 ++---- Adjust/ADJPackageBuilder.h | 4 ++-- Adjust/ADJPackageBuilder.m | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 959eac85b..4b1ddbbcc 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -160,8 +160,8 @@ - (void)setIadDate:(NSDate *)iAdImpressionDate withPurchaseDate:(NSDate *)appPur andActivityState:self.activityState andConfig:self.adjustConfig]; - [clickBuilder setIAdImpressionDate:iAdImpressionDate]; - [clickBuilder setAppPurchaseDate:appPurchaseDate]; + [clickBuilder setClickTime:iAdImpressionDate]; + [clickBuilder setPurchaseDate:appPurchaseDate]; ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad"]; [self.packageHandler sendClickPackage:clickPackage]; @@ -484,8 +484,6 @@ - (void)readAttribution { class:[ADJAttribution class]]; } - - - (void)transferSessionPackage { ADJPackageBuilder *sessionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState diff --git a/Adjust/ADJPackageBuilder.h b/Adjust/ADJPackageBuilder.h index 1b22fee17..cd95c9068 100644 --- a/Adjust/ADJPackageBuilder.h +++ b/Adjust/ADJPackageBuilder.h @@ -19,8 +19,8 @@ @property (nonatomic, copy) ADJConfig *adjustConfig; @property (nonatomic, assign) BOOL hasDelegate; @property (nonatomic, copy) ADJAttribution *attribution; -@property (nonatomic, copy) NSDate *iAdImpressionDate; -@property (nonatomic, copy) NSDate *appPurchaseDate; +@property (nonatomic, copy) NSDate *clickTime; +@property (nonatomic, copy) NSDate *purchaseDate; @property (nonatomic, copy) NSDictionary* deeplinkParameters; - (id) initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 4203c3ff9..dada6b0da 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -70,8 +70,8 @@ - (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource{ NSMutableDictionary *parameters = [self defaultParameters]; [self parameters:parameters setString:@"source" forKey:clickSource]; [self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"params"]; - [self parameters:parameters setDate:self.iAdImpressionDate forKey:@"click_time"]; - [self parameters:parameters setDate:self.appPurchaseDate forKey:@"purchase_time"]; + [self parameters:parameters setDate:self.clickTime forKey:@"click_time"]; + [self parameters:parameters setDate:self.purchaseDate forKey:@"purchase_time"]; if (self.attribution != nil) { [self parameters:parameters setString:self.attribution.trackerName forKey:@"tracker"]; @@ -234,7 +234,7 @@ - (void)parameters:(NSMutableDictionary *)parameters setNumberBool:(NSNumber *)v } - (void)parameters:(NSMutableDictionary *)parameters setNumber:(NSNumber *)value forKey:(NSString *)key { - if (value == nil); + if (value == nil) return; NSString *numberString = [value stringValue]; From ba8ce6a2326a4b63301bf16848d71c9d856ced58 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 11:36:37 +0100 Subject: [PATCH 49/86] Rename AIEnvironment --- Adjust/ADJActivityHandler.m | 2 +- Adjust/ADJConfig.m | 4 ++-- Adjust/Adjust.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 4b1ddbbcc..ff71e15e5 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -212,7 +212,7 @@ - (void)initInternal:(ADJConfig *)adjustConfig { self.adjustConfig = adjustConfig; self.deviceInfo = [ADJDeviceInfo deviceInfoWithSdkPrefix:adjustConfig.sdkPrefix]; - if ([adjustConfig.environment isEqualToString:AIEnvironmentProduction]) { + if ([adjustConfig.environment isEqualToString:ADJEnvironmentProduction]) { [self.logger setLogLevel:ADJLogLevelAssert]; } else { [self.logger setLogLevel:adjustConfig.logLevel]; diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index e708387dd..57fd20818 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -39,10 +39,10 @@ - (id) initWithAppToken:(NSString *)appToken - (BOOL) checkEnvironment:(NSString *)environment { id logger = ADJAdjustFactory.logger; - if ([environment isEqualToString:AIEnvironmentSandbox]) { + if ([environment isEqualToString:ADJEnvironmentSandbox]) { [logger assert:@"SANDBOX: Adjust will run in Sandbox mode. Use this setting for testing. Don't forget to set the environment to AIEnvironmentProduction before publishing!"]; return YES; - } else if ([environment isEqualToString:AIEnvironmentProduction]) { + } else if ([environment isEqualToString:ADJEnvironmentProduction]) { [logger assert:@"PRODUCTION: Adjust will run in Production mode. Use this setting only for the build that you want to publish. Set the environment to AIEnvironmentSandbox if you want to test your app!"]; return YES; } diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index 19d1f1c40..db1a503d4 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -14,8 +14,8 @@ /** * Constants for our supported tracking environments. */ -static NSString * const AIEnvironmentSandbox = @"sandbox"; -static NSString * const AIEnvironmentProduction = @"production"; +static NSString * const ADJEnvironmentSandbox = @"sandbox"; +static NSString * const ADJEnvironmentProduction = @"production"; /** * The main interface to Adjust. From f677484efdf56592a4cce40fd8a53891f5a90962 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 11:37:08 +0100 Subject: [PATCH 50/86] Remove example helper --- example/example.xcodeproj/project.pbxproj | 6 --- example/example/AppDelegate.h | 2 +- example/example/AppDelegate.m | 21 ++++++++- example/example/ExampleAdjustHelper.h | 17 -------- example/example/ExampleAdjustHelper.m | 52 ----------------------- example/example/ViewController.m | 14 +++++- 6 files changed, 33 insertions(+), 79 deletions(-) delete mode 100644 example/example/ExampleAdjustHelper.h delete mode 100644 example/example/ExampleAdjustHelper.m diff --git a/example/example.xcodeproj/project.pbxproj b/example/example.xcodeproj/project.pbxproj index 60f5daa45..47ae34035 100644 --- a/example/example.xcodeproj/project.pbxproj +++ b/example/example.xcodeproj/project.pbxproj @@ -33,7 +33,6 @@ 960FCF8D1A1B9B7D00282BD4 /* ADJAttributionHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF761A1B9B7D00282BD4 /* ADJAttributionHandler.m */; }; 960FCF8E1A1B9B7D00282BD4 /* ADJAttribution.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF781A1B9B7D00282BD4 /* ADJAttribution.m */; }; 960FCF8F1A1B9B7D00282BD4 /* ADJConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF7A1A1B9B7D00282BD4 /* ADJConfig.m */; }; - 960FCF921A1B9E6800282BD4 /* ExampleAdjustHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 960FCF911A1B9E6800282BD4 /* ExampleAdjustHelper.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -98,8 +97,6 @@ 960FCF781A1B9B7D00282BD4 /* ADJAttribution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJAttribution.m; sourceTree = ""; }; 960FCF791A1B9B7D00282BD4 /* ADJConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJConfig.h; sourceTree = ""; }; 960FCF7A1A1B9B7D00282BD4 /* ADJConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJConfig.m; sourceTree = ""; }; - 960FCF901A1B9E6800282BD4 /* ExampleAdjustHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleAdjustHelper.h; sourceTree = ""; }; - 960FCF911A1B9E6800282BD4 /* ExampleAdjustHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleAdjustHelper.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -149,8 +146,6 @@ 960FCF301A1B9ACE00282BD4 /* Images.xcassets */, 960FCF321A1B9ACE00282BD4 /* LaunchScreen.xib */, 960FCF231A1B9ACE00282BD4 /* Supporting Files */, - 960FCF901A1B9E6800282BD4 /* ExampleAdjustHelper.h */, - 960FCF911A1B9E6800282BD4 /* ExampleAdjustHelper.m */, ); path = example; sourceTree = ""; @@ -342,7 +337,6 @@ 960FCF8E1A1B9B7D00282BD4 /* ADJAttribution.m in Sources */, 960FCF821A1B9B7D00282BD4 /* ADJActivityState.m in Sources */, 960FCF2C1A1B9ACE00282BD4 /* ViewController.m in Sources */, - 960FCF921A1B9E6800282BD4 /* ExampleAdjustHelper.m in Sources */, 960FCF7D1A1B9B7D00282BD4 /* UIDevice+ADJAdditions.m in Sources */, 960FCF291A1B9ACE00282BD4 /* AppDelegate.m in Sources */, 960FCF881A1B9B7D00282BD4 /* ADJTimer.m in Sources */, diff --git a/example/example/AppDelegate.h b/example/example/AppDelegate.h index a3335390b..87b7001d2 100644 --- a/example/example/AppDelegate.h +++ b/example/example/AppDelegate.h @@ -7,7 +7,7 @@ // #import -#import "ADJConfig.h" +#import "Adjust.h" @interface AppDelegate : UIResponder diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m index 63df41405..384247813 100644 --- a/example/example/AppDelegate.m +++ b/example/example/AppDelegate.m @@ -18,7 +18,26 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. - [ExampleAdjustHelper initAdjust:self]; + + // configure adjust + NSString *yourAppToken = @"{YourAppToken}"; + NSString *enviroment = ADJEnvironmentSandbox; + ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; + + // change the log level + [adjustConfig setLogLevel:ADJLogLevelVerbose]; + + // enable event buffering + //[adjustConfig setEventBufferingEnabled:YES]; + + // disable MAC MD5 tracking + //[adjustConfig setMacMd5TrackingEnabled:NO]; + + // set an attribution delegate + [adjustConfig setDelegate:self]; + + [Adjust appDidLaunch:adjustConfig]; + return YES; } diff --git a/example/example/ExampleAdjustHelper.h b/example/example/ExampleAdjustHelper.h deleted file mode 100644 index 19c99cc9a..000000000 --- a/example/example/ExampleAdjustHelper.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// AdjustInit.h -// example -// -// Created by Pedro Filipe on 18/11/14. -// Copyright (c) 2014 adjust. All rights reserved. -// - -#import -#import "ADJConfig.h" - -@interface ExampleAdjustHelper : NSObject - -+ (void) initAdjust: (NSObject *)adjustDelegate; - -+ (void) triggerEvent; -@end diff --git a/example/example/ExampleAdjustHelper.m b/example/example/ExampleAdjustHelper.m deleted file mode 100644 index 1f52b149a..000000000 --- a/example/example/ExampleAdjustHelper.m +++ /dev/null @@ -1,52 +0,0 @@ -// -// AdjustInit.m -// example -// -// Created by Pedro Filipe on 18/11/14. -// Copyright (c) 2014 adjust. All rights reserved. -// - -#import "ExampleAdjustHelper.h" -#import "Adjust.h" -#import "ADJLogger.h" -#import "ADJEvent.h" - -@implementation ExampleAdjustHelper - -+ (void) initAdjust: (NSObject *) adjustDelegate { - NSString *yourAppToken = @"dgau42x652ul"; - NSString *enviroment = AIEnvironmentSandbox; - ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; - - // change the log level - [adjustConfig setLogLevel:ADJLogLevelVerbose]; - - // enable event buffering - //[adjustConfig setEventBufferingEnabled:YES]; - - // disable MAC MD5 tracking - //[adjustConfig setMacMd5TrackingEnabled:NO]; - - // set an attribution delegate - [adjustConfig setDelegate:adjustDelegate]; - - [Adjust appDidLaunch:adjustConfig]; -} - -+ (void) triggerEvent { - - ADJEvent *event = [ADJEvent eventWithEventToken:@"gd6a8u"]; - - // add revenue 1 cent of an euro - [event setRevenue:0.015 currency:@"EUR"]; - - // add callback parameters to this parameter - [event addCallbackParameter:@"keyEvent" andValue:@"value"]; - - // add partner parameteres to all events and sessions - [event addPartnerParameter:@"fooEvent" andValue:@"bar"]; - - [Adjust trackEvent:event]; -} - -@end diff --git a/example/example/ViewController.m b/example/example/ViewController.m index 3ca08f0f3..0de666761 100644 --- a/example/example/ViewController.m +++ b/example/example/ViewController.m @@ -8,7 +8,6 @@ #import "ViewController.h" #import "Adjust.h" -#import "ExampleAdjustHelper.h" @interface ViewController () @@ -36,7 +35,18 @@ - (void)didReceiveMemoryWarning { // Dispose of any resources that can be recreated. } - (IBAction)clickTrackEvent:(UIButton *)sender { - [ExampleAdjustHelper triggerEvent]; + ADJEvent *event = [ADJEvent eventWithEventToken:@"{YourEventToken}"]; + + // add revenue 1 cent of an euro + [event setRevenue:0.015 currency:@"EUR"]; + + // add callback parameters to this parameter + [event addCallbackParameter:@"key" andValue:@"value"]; + + // add partner parameteres to all events and sessions + [event addPartnerParameter:@"foo" andValue:@"bar"]; + + [Adjust trackEvent:event]; } - (IBAction)clickDisableSdk:(UIButton *)sender { NSString *txtDisableSdk = self.btnDisableSdk.titleLabel.text; From b9220eb11c911b872058a4ab5db91a06143276c4 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 12:04:24 +0100 Subject: [PATCH 51/86] Refac NSNULL cast --- Adjust/ADJActivityHandler.m | 2 +- Adjust/ADJAttribution.m | 2 +- Adjust/ADJAttributionHandler.m | 4 ++-- Adjust/ADJRequestHandler.m | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index ff71e15e5..05329a520 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -102,7 +102,7 @@ - (void)finishedTrackingWithResponse:(NSDictionary *)jsonDict{ } - (void)launchDeepLink:(NSDictionary *)jsonDict{ - if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; + if (jsonDict == nil || jsonDict == (id)[NSNull null]) return; NSString *deepLink = [jsonDict objectForKey:@"deeplink"]; if (deepLink == nil) return; diff --git a/Adjust/ADJAttribution.m b/Adjust/ADJAttribution.m index 774dc6134..004aaf2e5 100644 --- a/Adjust/ADJAttribution.m +++ b/Adjust/ADJAttribution.m @@ -19,7 +19,7 @@ - (id)initWithJsonDict:(NSDictionary *)jsonDict { self = [super init]; if (self == nil) return nil; - if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) { + if (jsonDict == nil || jsonDict == (id)[NSNull null]) { return nil; } diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 420bb9bca..00d0c0be3 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -78,7 +78,7 @@ - (BOOL) isWaitingInAskIn { #pragma mark - internal -(void) checkAttributionInternal:(NSDictionary *)jsonDict { - if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; + if (jsonDict == nil || jsonDict == (id)[NSNull null]) return; NSDictionary* jsonAttribution = [jsonDict objectForKey:@"attribution"]; ADJAttribution *attribution = [ADJAttribution dataWithJsonDict:jsonAttribution]; @@ -135,7 +135,7 @@ -(void) getAttributionInternal { NSDictionary *jsonDict = [ADJUtil buildJsonDict:responseString]; - if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) { + if (jsonDict == nil || jsonDict == (id)[NSNull null]) { [self.logger error:@"Failed to parse json attribution response: %@", responseString.adjTrim]; return; } diff --git a/Adjust/ADJRequestHandler.m b/Adjust/ADJRequestHandler.m index 972d16c40..3e931e419 100644 --- a/Adjust/ADJRequestHandler.m +++ b/Adjust/ADJRequestHandler.m @@ -88,7 +88,7 @@ - (void)sendInternal:(ADJActivityPackage *)package sendToPackageHandler:(BOOL)se NSDictionary *jsonDict = [ADJUtil buildJsonDict:responseString]; - if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) { + if (jsonDict == nil || jsonDict == (id)[NSNull null]) { NSString *activityKindString = ADJActivityKindToString(package.activityKind); [self.logger error:@"Failed to parse json %@ response: %@", activityKindString, responseString.adjTrim]; if (sendToPackageHandler) { @@ -132,7 +132,7 @@ - (NSData *)bodyForParameters:(NSDictionary *)parameters { } - (void) checkMessageResponse:(NSDictionary *)jsonDict { - if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; + if (jsonDict == nil || jsonDict == (id)[NSNull null]) return; NSString* messageResponse = [jsonDict objectForKey:@"message"]; if (messageResponse != nil) { @@ -141,7 +141,7 @@ - (void) checkMessageResponse:(NSDictionary *)jsonDict { } - (void)checkErrorResponse:(NSDictionary *)jsonDict { - if (jsonDict == nil || jsonDict == (NSDictionary *)[NSNull null]) return; + if (jsonDict == nil || jsonDict == (id)[NSNull null]) return; NSString* errorResponse = [jsonDict objectForKey:@"error"]; if (errorResponse != nil) { From d4f45e95744e33d7434953f6103722ee6e88f761 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 12:04:50 +0100 Subject: [PATCH 52/86] Warn repeated key in events --- Adjust/ADJEvent.m | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Adjust/ADJEvent.m b/Adjust/ADJEvent.m index af1ee4181..81a05a3e8 100644 --- a/Adjust/ADJEvent.m +++ b/Adjust/ADJEvent.m @@ -10,6 +10,9 @@ #import "ADJAdjustFactory.h" #pragma mark - +@interface ADJEvent() +@property (nonatomic, retain) id logger; +@end @implementation ADJEvent @@ -22,26 +25,35 @@ - (id) initWithEventToken:(NSString *)eventToken { if (self == nil) return nil; self.eventToken = eventToken; + self.logger = ADJAdjustFactory.logger; return self; } - (void) addCallbackParameter:(NSString *)key andValue:(NSString *)value { - if (_callbackParameters == nil) { - _callbackParameters = [[NSMutableDictionary alloc] init]; + if (self.callbackParameters == nil) { + self.callbackParameters = [[NSMutableDictionary alloc] init]; + } + + if ([self.callbackParameters objectForKey:key]) { + [self.logger warn:@"key %@ will be overwritten", key]; } - [_callbackParameters setObject:value forKey:key]; + [self.callbackParameters setObject:value forKey:key]; } - (void) addPartnerParameter:(NSString *)key andValue:(NSString *)value { - if (_partnerParameters == nil) { - _partnerParameters = [[NSMutableDictionary alloc] init]; + if (self.partnerParameters == nil) { + self.partnerParameters = [[NSMutableDictionary alloc] init]; } - [_partnerParameters setObject:value forKey:key]; + if ([self.partnerParameters objectForKey:key]) { + [self.logger warn:@"key %@ will be overwritten", key]; + } + + [self.partnerParameters setObject:value forKey:key]; } - (void) setRevenue:(double) amount currency:(NSString *)currency{ @@ -55,27 +67,25 @@ - (void) setTransactionId:(NSString *)transactionId { - (BOOL) isValid { - id logger = ADJAdjustFactory.logger; - if (self.eventToken == nil) { - [logger error:@"Missing Event Token"]; + [self.logger error:@"Missing Event Token"]; return NO; } if (self.eventToken.length != 6) { - [logger error:@"Malformed Event Token '%@'", self.eventToken]; + [self.logger error:@"Malformed Event Token '%@'", self.eventToken]; return NO; } if (self.revenue != nil) { double amount = [self.revenue doubleValue]; if (amount < 0.0) { - [logger error:@"Invalid amount %.1f", amount]; + [self.logger error:@"Invalid amount %.1f", amount]; return NO; } if (self.currency == nil) { - [logger error:@"Currency must be set with revenue"]; + [self.logger error:@"Currency must be set with revenue"]; return NO; } } From 89305f2eaae2a6a7b0eaf996c2c0e291c57c1e0b Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 12:29:29 +0100 Subject: [PATCH 53/86] Example with event buttons --- example/example/AppDelegate.m | 15 ++++--- example/example/Base.lproj/Main.storyboard | 36 ++++++++-------- example/example/ViewController.m | 49 ++++++++++------------ 3 files changed, 49 insertions(+), 51 deletions(-) diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m index 384247813..7b8a77e2a 100644 --- a/example/example/AppDelegate.m +++ b/example/example/AppDelegate.m @@ -7,7 +7,6 @@ // #import "AppDelegate.h" -#import "ExampleAdjustHelper.h" @interface AppDelegate () @@ -38,9 +37,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [Adjust appDidLaunch:adjustConfig]; + // put the SDK in offline mode + //[Adjust setOfflineMode:YES]; + + // disable the SDK + //[Adjust setEnabled:NO]; + return YES; } +- (void)adjustAttributionChanged:(ADJAttribution *)attribution { + NSLog(@"adjust attribution %@", attribution); +} + - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. @@ -63,8 +72,4 @@ - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } -- (void)adjustAttributionChanged:(ADJAttribution *)attribution { - NSLog(@"adjust attribution %@", attribution); -} - @end diff --git a/example/example/Base.lproj/Main.storyboard b/example/example/Base.lproj/Main.storyboard index e9454e8b3..2b03dfca6 100644 --- a/example/example/Base.lproj/Main.storyboard +++ b/example/example/Base.lproj/Main.storyboard @@ -1,7 +1,7 @@ - + - + @@ -17,49 +17,49 @@ - - - - + + + + diff --git a/example/example/ViewController.m b/example/example/ViewController.m index 0de666761..18e2f4a3c 100644 --- a/example/example/ViewController.m +++ b/example/example/ViewController.m @@ -11,10 +11,10 @@ @interface ViewController () -@property (weak, nonatomic) IBOutlet UIButton *btnTrackEvent; -@property (weak, nonatomic) IBOutlet UIButton *btnDisableSdk; -@property (weak, nonatomic) IBOutlet UIButton *btnSetOfflineMode; -@property (weak, nonatomic) IBOutlet UIButton *btnSetOnlineMode; +@property (weak, nonatomic) IBOutlet UIButton *btnTrackSimpleEvent; +@property (weak, nonatomic) IBOutlet UIButton *btnTrackRevenueEvent; +@property (weak, nonatomic) IBOutlet UIButton *btnTrackEventWithCallback; +@property (weak, nonatomic) IBOutlet UIButton *btnTrackEventWithPartner; @end @@ -26,7 +26,7 @@ - (void)viewDidLoad { BOOL isEnabled = [Adjust isEnabled]; if (!isEnabled) { - [self.btnDisableSdk setTitle:@"Enable SDK" forState:UIControlStateNormal]; + [self.btnTrackRevenueEvent setTitle:@"Enable SDK" forState:UIControlStateNormal]; } } @@ -34,41 +34,34 @@ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -- (IBAction)clickTrackEvent:(UIButton *)sender { +- (IBAction)clickTrackSimpleEvent:(UIButton *)sender { + ADJEvent *event = [ADJEvent eventWithEventToken:@"{YourEventToken}"]; + + [Adjust trackEvent:event]; +} +- (IBAction)clickTrackRevenueEvent:(UIButton *)sender { ADJEvent *event = [ADJEvent eventWithEventToken:@"{YourEventToken}"]; // add revenue 1 cent of an euro [event setRevenue:0.015 currency:@"EUR"]; + [Adjust trackEvent:event]; +} +- (IBAction)clickEventWithCallback:(UIButton *)sender { + ADJEvent *event = [ADJEvent eventWithEventToken:@"{YourEventToken}"]; + // add callback parameters to this parameter [event addCallbackParameter:@"key" andValue:@"value"]; - // add partner parameteres to all events and sessions - [event addPartnerParameter:@"foo" andValue:@"bar"]; - [Adjust trackEvent:event]; } -- (IBAction)clickDisableSdk:(UIButton *)sender { - NSString *txtDisableSdk = self.btnDisableSdk.titleLabel.text; +- (IBAction)clickEventWithPartner:(UIButton *)sender { + ADJEvent *event = [ADJEvent eventWithEventToken:@"{YourEventToken}"]; - if ([txtDisableSdk hasPrefix:@"Disable"]) { - [Adjust setEnabled:NO]; - } else { - [Adjust setEnabled:YES]; - } + // add partner parameteres to all events and sessions + [event addPartnerParameter:@"foo" andValue:@"bar"]; - BOOL isEnabled = [Adjust isEnabled]; - if (!isEnabled) { - [self.btnDisableSdk setTitle:@"Enable SDK" forState:UIControlStateNormal]; - } else { - [self.btnDisableSdk setTitle:@"Disable SDK" forState:UIControlStateNormal]; - } -} -- (IBAction)clickSetOfflineMode:(UIButton *)sender { - [Adjust setOfflineMode:YES]; -} -- (IBAction)clickSetOnlineMode:(UIButton *)sender { - [Adjust setOfflineMode:NO]; + [Adjust trackEvent:event]; } @end From dc8c1974087ef9d0f798c11cafc90b6e4c111347 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 12:41:10 +0100 Subject: [PATCH 54/86] Rename askingAttribution --- Adjust/ADJActivityHandler.h | 2 +- Adjust/ADJActivityHandler.m | 6 +-- Adjust/ADJActivityState.h | 2 +- Adjust/ADJActivityState.m | 76 +++++++++++++++++----------------- Adjust/ADJAttributionHandler.m | 4 +- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Adjust/ADJActivityHandler.h b/Adjust/ADJActivityHandler.h index bf578ffbd..88de85ae7 100644 --- a/Adjust/ADJActivityHandler.h +++ b/Adjust/ADJActivityHandler.h @@ -26,7 +26,7 @@ - (ADJAttribution*) attribution; - (void) setAttribution:(ADJAttribution*)attribution; -- (void) setAskIn:(BOOL)askIn; +- (void) setAskingAttribution:(BOOL)askingAttribution; - (BOOL) updateAttribution:(ADJAttribution*) attribution; - (void) setIadDate:(NSDate*)iAdImpressionDate withPurchaseDate:(NSDate*)appPurchaseDate; diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 05329a520..fc354d592 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -202,8 +202,8 @@ - (void)setOfflineMode:(BOOL)isOffline { } } -- (void) setAskIn:(BOOL)askIn { - self.activityState.askIn = askIn; +- (void) setAskingAttribution:(BOOL)askingAttribution { + self.activityState.askingAttribution = askingAttribution; [self writeActivityState]; } @@ -310,7 +310,7 @@ - (void)startInternal { self.activityState.sessionCount]; } - if (self.attribution == nil || self.activityState.askIn) { + if (self.attribution == nil || self.activityState.askingAttribution) { if (![self.attributionHandler isWaitingInAskIn]) { [self.attributionHandler getAttribution]; } diff --git a/Adjust/ADJActivityState.h b/Adjust/ADJActivityState.h index 15d7caacd..8fa50a7c5 100644 --- a/Adjust/ADJActivityState.h +++ b/Adjust/ADJActivityState.h @@ -12,7 +12,7 @@ // persistent data @property (nonatomic, copy) NSString *uuid; @property (nonatomic, assign) BOOL enabled; -@property (nonatomic, assign) BOOL askIn; +@property (nonatomic, assign) BOOL askingAttribution; // global counters @property (nonatomic, assign) int eventCount; diff --git a/Adjust/ADJActivityState.m b/Adjust/ADJActivityState.m index c428ee882..060faf47c 100644 --- a/Adjust/ADJActivityState.m +++ b/Adjust/ADJActivityState.m @@ -31,7 +31,7 @@ - (id)init { self.lastInterval = -1; self.transactionIds = [NSMutableArray arrayWithCapacity:kTransactionIdCount]; self.enabled = YES; - self.askIn = NO; + self.askingAttribution = NO; return self; } @@ -73,19 +73,19 @@ - (id)initWithCoder:(NSCoder *)decoder { self = [super init]; if (self == nil) return nil; - self.eventCount = [decoder decodeIntForKey:@"eventCount"]; - self.sessionCount = [decoder decodeIntForKey:@"sessionCount"]; - self.subsessionCount = [decoder decodeIntForKey:@"subsessionCount"]; - self.sessionLength = [decoder decodeDoubleForKey:@"sessionLength"]; - self.timeSpent = [decoder decodeDoubleForKey:@"timeSpent"]; - self.createdAt = [decoder decodeDoubleForKey:@"createdAt"]; - self.lastActivity = [decoder decodeDoubleForKey:@"lastActivity"]; - self.uuid = [decoder decodeObjectForKey:@"uuid"]; - self.transactionIds = [decoder decodeObjectForKey:@"transactionIds"]; - self.enabled = [decoder decodeBoolForKey:@"enabled"]; - self.askIn = [decoder decodeBoolForKey:@"askIn"]; - - // create UUID for migrating devices + self.eventCount = [decoder decodeIntForKey:@"eventCount"]; + self.sessionCount = [decoder decodeIntForKey:@"sessionCount"]; + self.subsessionCount = [decoder decodeIntForKey:@"subsessionCount"]; + self.sessionLength = [decoder decodeDoubleForKey:@"sessionLength"]; + self.timeSpent = [decoder decodeDoubleForKey:@"timeSpent"]; + self.createdAt = [decoder decodeDoubleForKey:@"createdAt"]; + self.lastActivity = [decoder decodeDoubleForKey:@"lastActivity"]; + self.uuid = [decoder decodeObjectForKey:@"uuid"]; + self.transactionIds = [decoder decodeObjectForKey:@"transactionIds"]; + self.enabled = [decoder decodeBoolForKey:@"enabled"]; + self.askingAttribution = [decoder decodeBoolForKey:@"askingAttribution"]; + + // default values for migrating devices if (self.uuid == nil) { self.uuid = [UIDevice.currentDevice adjCreateUuid]; } @@ -98,8 +98,8 @@ - (id)initWithCoder:(NSCoder *)decoder { self.enabled = YES; } - if (![decoder containsValueForKey:@"askIn"]) { - self.askIn = NO; + if (![decoder containsValueForKey:@"askingAttribution"]) { + self.askingAttribution = NO; } self.lastInterval = -1; @@ -108,34 +108,34 @@ - (id)initWithCoder:(NSCoder *)decoder { } - (void)encodeWithCoder:(NSCoder *)encoder { - [encoder encodeInt:self.eventCount forKey:@"eventCount"]; - [encoder encodeInt:self.sessionCount forKey:@"sessionCount"]; - [encoder encodeInt:self.subsessionCount forKey:@"subsessionCount"]; - [encoder encodeDouble:self.sessionLength forKey:@"sessionLength"]; - [encoder encodeDouble:self.timeSpent forKey:@"timeSpent"]; - [encoder encodeDouble:self.createdAt forKey:@"createdAt"]; - [encoder encodeDouble:self.lastActivity forKey:@"lastActivity"]; - [encoder encodeObject:self.uuid forKey:@"uuid"]; - [encoder encodeObject:self.transactionIds forKey:@"transactionIds"]; - [encoder encodeBool:self.enabled forKey:@"enabled"]; - [encoder encodeBool:self.askIn forKey:@"askIn"]; + [encoder encodeInt:self.eventCount forKey:@"eventCount"]; + [encoder encodeInt:self.sessionCount forKey:@"sessionCount"]; + [encoder encodeInt:self.subsessionCount forKey:@"subsessionCount"]; + [encoder encodeDouble:self.sessionLength forKey:@"sessionLength"]; + [encoder encodeDouble:self.timeSpent forKey:@"timeSpent"]; + [encoder encodeDouble:self.createdAt forKey:@"createdAt"]; + [encoder encodeDouble:self.lastActivity forKey:@"lastActivity"]; + [encoder encodeObject:self.uuid forKey:@"uuid"]; + [encoder encodeObject:self.transactionIds forKey:@"transactionIds"]; + [encoder encodeBool:self.enabled forKey:@"enabled"]; + [encoder encodeBool:self.askingAttribution forKey:@"askingAttribution"]; } -(id)copyWithZone:(NSZone *)zone { ADJActivityState* copy = [[[self class] allocWithZone:zone] init]; if (copy) { - copy.sessionCount = self.sessionCount; - copy.subsessionCount = self.subsessionCount; - copy.sessionLength = self.sessionLength; - copy.timeSpent = self.timeSpent; - copy.createdAt = self.createdAt; - copy.uuid = [self.uuid copyWithZone:zone]; - copy.lastInterval = self.lastInterval; - copy.eventCount = self.eventCount; - copy.enabled = self.enabled; - copy.lastActivity = self.lastActivity; - copy.askIn = self.askIn; + copy.sessionCount = self.sessionCount; + copy.subsessionCount = self.subsessionCount; + copy.sessionLength = self.sessionLength; + copy.timeSpent = self.timeSpent; + copy.createdAt = self.createdAt; + copy.uuid = [self.uuid copyWithZone:zone]; + copy.lastInterval = self.lastInterval; + copy.eventCount = self.eventCount; + copy.enabled = self.enabled; + copy.lastActivity = self.lastActivity; + copy.askingAttribution = self.askingAttribution; // transactionIds not copied } diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 00d0c0be3..f962f9bc7 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -92,12 +92,12 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { [self.activityHandler launchAttributionDelegate]; } - [self.activityHandler setAskIn:NO]; + [self.activityHandler setAskingAttribution:NO]; return; }; - [self.activityHandler setAskIn:YES]; + [self.activityHandler setAskingAttribution:YES]; if (self.askInTimer != nil) { [self.askInTimer cancel]; } From ef2500b7967db6ad34a98d64a543b153b45c69a8 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 14:05:20 +0100 Subject: [PATCH 55/86] Change tests to v4 --- Adjust.xcodeproj/project.pbxproj | 12 ++++++ AdjustTests/AIActivityHandlerMock.m | 61 +++++++++++++++++----------- AdjustTests/AIActivityHandlerTests.m | 16 ++++++++ AdjustTests/AIPackageHandlerMock.h | 2 +- AdjustTests/AIPackageHandlerMock.m | 15 ++++--- AdjustTests/AIPackageHandlerTests.m | 7 +++- AdjustTests/AIRequestHandlerMock.m | 11 ++--- AdjustTests/AIRequestHandlerTests.m | 9 ++-- AdjustTests/AITestsUtil.h | 2 - AdjustTests/AITestsUtil.m | 6 --- 10 files changed, 91 insertions(+), 50 deletions(-) diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index fa018f01a..eda2046a7 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXBuildFile section */ + 9601C19D1A31DD7F00A9AE21 /* 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, ); }; }; + 9601C1A21A31DE0300A9AE21 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9601C1A11A31DE0300A9AE21 /* SystemConfiguration.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + 9601C1A31A31DE0D00A9AE21 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9601C1A11A31DE0300A9AE21 /* SystemConfiguration.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 9609BC6A19EEA55800E02303 /* ADJEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 9609BC6919EEA55800E02303 /* ADJEvent.m */; }; 960A8BB91A029A8000F2BB95 /* ADJConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 960A8BB81A029A8000F2BB95 /* ADJConfig.m */; }; 96325E89190E892000A97911 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96325E86190E5CE400A97911 /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; @@ -85,6 +89,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 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; }; 9609BC6819EEA55800E02303 /* ADJEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJEvent.h; sourceTree = ""; }; 9609BC6919EEA55800E02303 /* ADJEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJEvent.m; sourceTree = ""; }; 960A8BB71A029A8000F2BB95 /* ADJConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJConfig.h; sourceTree = ""; }; @@ -156,6 +162,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 9601C1A21A31DE0300A9AE21 /* SystemConfiguration.framework in Frameworks */, + 9601C19D1A31DD7F00A9AE21 /* CoreTelephony.framework in Frameworks */, 96325E8A190E892600A97911 /* AdSupport.framework in Frameworks */, 96325E89190E892000A97911 /* iAd.framework in Frameworks */, 9679921118BBAE2800394606 /* Foundation.framework in Frameworks */, @@ -167,6 +175,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 9601C1A31A31DE0D00A9AE21 /* SystemConfiguration.framework in Frameworks */, + 9601C1A01A31DD8900A9AE21 /* CoreTelephony.framework in Frameworks */, 96325E8C190E8D6B00A97911 /* AdSupport.framework in Frameworks */, 96325E8B190E8D6200A97911 /* iAd.framework in Frameworks */, 9679922518BBAE2800394606 /* libAdjust.a in Frameworks */, @@ -211,6 +221,8 @@ 9679920F18BBAE2800394606 /* Frameworks */ = { isa = PBXGroup; children = ( + 9601C1A11A31DE0300A9AE21 /* SystemConfiguration.framework */, + 9601C19C1A31DD7F00A9AE21 /* CoreTelephony.framework */, 96325E86190E5CE400A97911 /* iAd.framework */, 96325E84190E5CD900A97911 /* AdSupport.framework */, 9679921018BBAE2800394606 /* Foundation.framework */, diff --git a/AdjustTests/AIActivityHandlerMock.m b/AdjustTests/AIActivityHandlerMock.m index 1e27c8564..7e2237a6e 100644 --- a/AdjustTests/AIActivityHandlerMock.m +++ b/AdjustTests/AIActivityHandlerMock.m @@ -19,28 +19,18 @@ @interface AIActivityHandlerMock() @end @implementation AIActivityHandlerMock -/* -@synthesize environment; -@synthesize bufferEvents; -@synthesize trackMacMd5; -@synthesize delegate; -@synthesize isIad; -*/ -- (id)initWithAppToken:(NSString *)yourAppToken { + +- (id)initWithConfig:(ADJConfig *)adjustConfig { self = [super init]; if (self == nil) return nil; self.loggerMock = (AILoggerMock *) [ADJAdjustFactory logger]; - [self.loggerMock test:[prefix stringByAppendingFormat:@"initWithAppToken yourAppToken:%@", yourAppToken]]; + [self.loggerMock test:[prefix stringByAppendingFormat:@"initWithConfig"]]; return self; } -- (void)setSdkPrefix:(NSString *)sdkPrefix { - [self.loggerMock test:[prefix stringByAppendingFormat:@"setSdkPrefix sdkPrefix:%@", sdkPrefix]]; -} - - (void)trackSubsessionStart { [self.loggerMock test:[prefix stringByAppendingFormat:@"trackSubsessionStart"]]; } @@ -48,20 +38,13 @@ - (void)trackSubsessionEnd { [self.loggerMock test:[prefix stringByAppendingFormat:@"trackSubsessionEnd"]]; } -- (void)trackEvent:(NSString *)eventToken - withParameters:(NSDictionary *)parameters { - [self.loggerMock test:[prefix stringByAppendingFormat:@"trackEvent eventToken:%@ parameters:%@", eventToken, parameters]]; -} +- (void)trackEvent:(ADJEvent *)event { + [self.loggerMock test:[prefix stringByAppendingFormat:@"trackEvent"]]; -- (void)trackRevenue:(double)amount - transactionId:(NSString *)transactionId - forEvent:(NSString *)eventToken - withParameters:(NSDictionary *)parameters { - [self.loggerMock test:[prefix stringByAppendingFormat:@"trackRevenue amount:%f eventToken:%@ parameters:%@", amount, eventToken, parameters]]; } -- (void)finishedTrackingWithResponse:(AIResponseData *)response deepLink:(NSString *)deepLink{ - [self.loggerMock test:[prefix stringByAppendingFormat:@"finishedTrackingWithResponse response:%@", response]]; +- (void)finishedTrackingWithResponse:(NSDictionary *)jsonDict { + [self.loggerMock test:[prefix stringByAppendingFormat:@"finishedTrackingWithResponse response:%@", jsonDict]]; } - (void)setEnabled:(BOOL)enabled { @@ -81,4 +64,34 @@ - (void)setDeviceToken:(NSData *)pushToken { [self.loggerMock test:[prefix stringByAppendingFormat:@"savePushToken"]]; } +- (ADJAttribution*) attribution { + [self.loggerMock test:[prefix stringByAppendingFormat:@"attribution"]]; + return (ADJAttribution *)[NSNull null]; +} + +- (void) setAttribution:(ADJAttribution*)attribution { + [self.loggerMock test:[prefix stringByAppendingFormat:@"setAttribution"]]; +} + +- (void) setAskingAttribution:(BOOL)askingAttribution { + [self.loggerMock test:[prefix stringByAppendingFormat:@"setAskingAttribution"]]; +} + +- (BOOL) updateAttribution:(ADJAttribution*) attribution { + [self.loggerMock test:[prefix stringByAppendingFormat:@"updateAttribution"]]; + return NO; +} + +- (void) setIadDate:(NSDate*)iAdImpressionDate withPurchaseDate:(NSDate*)appPurchaseDate { + [self.loggerMock test:[prefix stringByAppendingFormat:@"setIadDate"]]; +} + +- (void) launchAttributionDelegate { + [self.loggerMock test:[prefix stringByAppendingFormat:@"launchAttributionDelegate"]]; +} + +- (void) setOfflineMode:(BOOL)enabled { + [self.loggerMock test:[prefix stringByAppendingFormat:@"setOfflineMode"]]; +} + @end diff --git a/AdjustTests/AIActivityHandlerTests.m b/AdjustTests/AIActivityHandlerTests.m index 26f86f021..083467577 100644 --- a/AdjustTests/AIActivityHandlerTests.m +++ b/AdjustTests/AIActivityHandlerTests.m @@ -55,6 +55,7 @@ - (void)reset { - (void)testFirstRun { + /* // reseting to make the test order independent [self reset]; @@ -136,9 +137,11 @@ - (void)testFirstRun // ending of first session XCTAssert([self.loggerMock containsMessage:ADJLogLevelInfo beginsWith:@"First session"], @"%@", self.loggerMock); + */ } - (void)testSessions { + /* // reseting to make the test order independent [self reset]; @@ -188,9 +191,11 @@ - (void)testSessions { // check that the package handler was paused XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler pauseSending"], @"%@", self.loggerMock); + */ } - (void)testEventsBuffered { + /* // reseting to make the test order independent [self reset]; @@ -288,9 +293,11 @@ - (void)testEventsBuffered { // check the event count in the logger XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 2 (revenue)"], @"%@", self.loggerMock); + */ } - (void)testEventsNotBuffered { + /* // reseting to make the test order independent [self reset]; @@ -383,10 +390,12 @@ - (void)testEventsNotBuffered { // check the event count in the logger XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 2 (revenue)"], @"%@", self.loggerMock); + */ } - (void)testChecks { + /* // reseting to make the test order independent [self reset]; @@ -451,10 +460,12 @@ - (void)testChecks { // check the invalid revenue token XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Malformed Event Token 'abc12'"], @"%@", self.loggerMock); + */ } - (void)testDisable { + /* // reseting to make the test order independent [self reset]; @@ -533,9 +544,11 @@ - (void)testDisable { // verify that it was also resumed XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler resumeSending"], @"%@", self.loggerMock); + */ } - (void)testOpenUrl { + /* // reseting to make the test order independent [self reset]; @@ -594,6 +607,7 @@ - (void)testOpenUrl { // check that sent the reattribution package XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Reattribution {\n foo = bar;\n key = value;\n}"], @"%@", self.loggerMock); + */ } - (void)testConversions { @@ -607,6 +621,7 @@ - (void)testConversions { } - (void)testfinishedTrackingWithResponse { + /* // reseting to make the test order independent [self reset]; @@ -621,5 +636,6 @@ - (void)testfinishedTrackingWithResponse { // check the deep link from the response XCTAssert([self.loggerMock containsMessage:ADJLogLevelError beginsWith:@"Unable to open deep link (testfinishedTrackingWithResponse://)"], @"%@", self.loggerMock); + */ } @end diff --git a/AdjustTests/AIPackageHandlerMock.h b/AdjustTests/AIPackageHandlerMock.h index 3d3be71e4..a847f0cfb 100644 --- a/AdjustTests/AIPackageHandlerMock.h +++ b/AdjustTests/AIPackageHandlerMock.h @@ -12,7 +12,7 @@ @property (nonatomic, strong) NSMutableArray *packageQueue; -@property (nonatomic, strong) AIResponseData *responseData; +@property (nonatomic, strong) NSDictionary *jsonDict; @property (nonatomic, strong) ADJActivityPackage * activityPackage; @end diff --git a/AdjustTests/AIPackageHandlerMock.m b/AdjustTests/AIPackageHandlerMock.m index fcb7245ae..15dd297cf 100644 --- a/AdjustTests/AIPackageHandlerMock.m +++ b/AdjustTests/AIPackageHandlerMock.m @@ -10,7 +10,6 @@ #import "AILoggerMock.h" #import "ADJAdjustFactory.h" #import "ADJActivityHandler.h" -#import "AIResponseData.h" static NSString * const prefix = @"AIPackageHandler "; @@ -23,10 +22,6 @@ @interface AIPackageHandlerMock() @implementation AIPackageHandlerMock -- (id)init { - return [self initWithActivityHandler:nil]; -} - - (id)initWithActivityHandler:(id)activityHandler { self = [super init]; if (self == nil) return nil; @@ -48,7 +43,7 @@ - (void)addPackage:(ADJActivityPackage *)package { - (void)sendFirstPackage { [self.loggerMock test:[prefix stringByAppendingString:@"sendFirstPackage"]]; - [self.activityHandler finishedTrackingWithResponse:[[AIResponseData alloc] init] deepLink:nil]; + [self.activityHandler finishedTrackingWithResponse:self.jsonDict]; } - (void)sendNextPackage { @@ -67,9 +62,13 @@ - (void)resumeSending { [self.loggerMock test:[prefix stringByAppendingString:@"resumeSending"]]; } -- (void)finishedTrackingActivity:(ADJActivityPackage *)activityPackage withResponse:(AIResponseData *)response jsonDict:(NSDictionary *)jsonDict { +- (void)finishedTrackingActivity:(NSDictionary *)jsonDict { [self.loggerMock test:[prefix stringByAppendingString:@"finishedTrackingActivity"]]; - self.responseData = response; + self.jsonDict = jsonDict; +} + +- (void)sendClickPackage:(ADJActivityPackage *) clickPackage { + [self.loggerMock test:[prefix stringByAppendingString:@"sendClickPackage"]]; } @end diff --git a/AdjustTests/AIPackageHandlerTests.m b/AdjustTests/AIPackageHandlerTests.m index 0a3fef37d..8edd2e75f 100644 --- a/AdjustTests/AIPackageHandlerTests.m +++ b/AdjustTests/AIPackageHandlerTests.m @@ -48,6 +48,7 @@ - (void)reset { - (void)testFirstPackage { + /* // reseting to make the test order independent [self reset]; @@ -94,9 +95,11 @@ - (void)testFirstPackage // check that the package was removed from the queue and 0 packages were written XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Package handler wrote 0 packages"], @"%@", self.loggerMock); + */ } - (void) testPaused { + /* // reseting to make the test order independent [self reset]; @@ -126,9 +129,11 @@ - (void) testPaused { // check that the package handler is paused XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Package handler is paused"], @"%@", self.loggerMock); + */ } - (void) testMultiplePackages { + /* // reseting to make the test order independent [self reset]; @@ -171,7 +176,7 @@ - (void) testMultiplePackages { // check that the package handler was already sending one package before XCTAssert([self.loggerMock containsMessage:ADJLogLevelVerbose beginsWith:@"Package handler is already sending"], @"%@", self.loggerMock); - + */ } @end diff --git a/AdjustTests/AIRequestHandlerMock.m b/AdjustTests/AIRequestHandlerMock.m index 3e3e3240c..1c106bf43 100644 --- a/AdjustTests/AIRequestHandlerMock.m +++ b/AdjustTests/AIRequestHandlerMock.m @@ -9,7 +9,6 @@ #import "AIRequestHandlerMock.h" #import "AILoggerMock.h" #import "ADJAdjustFactory.h" -#import "AIResponseData.h" static NSString * const prefix = @"AIRequestHandler "; @@ -40,16 +39,14 @@ - (void)sendPackage:(ADJActivityPackage *)activityPackage { [self.loggerMock test:[prefix stringByAppendingString:@"sendPackage"]]; NSDictionary *jsonDict; - AIResponseData *responseData; + if (self.connectionError) { jsonDict = nil; - responseData = [[AIResponseData alloc] initWithError:@"connection error"]; } else { jsonDict = @{@"tracker_token": @"token",@"tracker_name":@"name"}; - responseData = [[AIResponseData alloc] initWithJsonDict:jsonDict jsonString:@"{\"tracker_token\":\"token\",\"tracker_name\":\"name\"}"]; } - [self.packageHandler finishedTrackingActivity:activityPackage withResponse:responseData jsonDict:jsonDict]; + [self.packageHandler finishedTrackingActivity:jsonDict]; if (self.connectionError) { [self.packageHandler closeFirstPackage]; @@ -58,5 +55,9 @@ - (void)sendPackage:(ADJActivityPackage *)activityPackage { } } +- (void)sendClickPackage:(ADJActivityPackage *)clickPackage { + [self.loggerMock test:[prefix stringByAppendingString:@"sendClickPackage"]]; +} + @end diff --git a/AdjustTests/AIRequestHandlerTests.m b/AdjustTests/AIRequestHandlerTests.m index ff8a85745..b7f8d8427 100644 --- a/AdjustTests/AIRequestHandlerTests.m +++ b/AdjustTests/AIRequestHandlerTests.m @@ -13,7 +13,6 @@ #import "AIPackageHandlerMock.h" #import "AIRequestHandlerMock.h" #import "AITestsUtil.h" -#import "AIResponseData.h" @interface AIRequestHandlerTests : XCTestCase @@ -53,6 +52,7 @@ - (void)reset { - (void)testSendPackage { + /* // reseting to make the test order independent [self reset]; @@ -86,9 +86,11 @@ - (void)testSendPackage // check that the package handler was called to send the next package XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendNextPackage"], @"%@", self.loggerMock); + */ } - (void)testConnectionError { + /* // reseting to make the test order independent [self reset]; @@ -119,10 +121,12 @@ - (void)testConnectionError { // check that the package handler was called to close the package to retry later XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler closeFirstPackage"], @"%@", self.loggerMock); + */ } - (void)testResponseError { + /* // reseting to make the test order independent [self reset]; @@ -153,8 +157,7 @@ - (void)testResponseError { // check that the package handler was called to send the next package XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendNextPackage"], @"%@", self.loggerMock); - + */ } - @end diff --git a/AdjustTests/AITestsUtil.h b/AdjustTests/AITestsUtil.h index 96fcb9aa3..106e497bc 100644 --- a/AdjustTests/AITestsUtil.h +++ b/AdjustTests/AITestsUtil.h @@ -17,6 +17,4 @@ + (BOOL)deleteFile:(NSString *)filename logger:(AILoggerMock *)loggerMock; + (ADJActivityPackage *)buildEmptyPackage; -- (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData; - @end diff --git a/AdjustTests/AITestsUtil.m b/AdjustTests/AITestsUtil.m index eafeb1e43..70e54eca6 100644 --- a/AdjustTests/AITestsUtil.m +++ b/AdjustTests/AITestsUtil.m @@ -48,10 +48,4 @@ + (ADJActivityPackage *)buildEmptyPackage { return sessionPackage; } -- (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData { - AILoggerMock *loggerMock = (AILoggerMock *)ADJAdjustFactory.logger; - - [loggerMock test:@"AdjustDelegate adjustFinishedTrackingWithResponse"]; -} - @end From 73005a5b07c00d3ada7fcf5a2e6f9e968c332939 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 16:00:47 +0100 Subject: [PATCH 56/86] Change defaut logging --- Adjust/ADJActivityHandler.m | 4 +++- Adjust/ADJAttributionHandler.m | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index fc354d592..c0cae6488 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -218,7 +218,9 @@ - (void)initInternal:(ADJConfig *)adjustConfig { [self.logger setLogLevel:adjustConfig.logLevel]; } - [self.logger info:@"Tracking of macMd5 is %@", adjustConfig.macMd5TrackingEnabled ? @"enabled" : @"disabled"]; + if (!adjustConfig.macMd5TrackingEnabled) { + [self.logger info:@"Tracking of macMd5 is disabled"]; + } if (adjustConfig.eventBufferingEnabled) { [self.logger info:@"Event buffering is enabled"]; diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index f962f9bc7..826ffa4c2 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -142,8 +142,8 @@ -(void) getAttributionInternal { NSString* messageResponse = [jsonDict objectForKey:@"message"]; - if (statusCode == 200) { - [self.logger info:@"%@", messageResponse]; + if (statusCode != 200) { + [self.logger debug:@"%@", messageResponse]; } else { [self.logger error:@"%@", messageResponse]; } From d2774177d48dcad5bc1d8b36a25d4747404c5291 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 16:01:29 +0100 Subject: [PATCH 57/86] Rename andValue --- Adjust/ADJEvent.h | 4 ++-- Adjust/ADJEvent.m | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Adjust/ADJEvent.h b/Adjust/ADJEvent.h index 9e7f870f2..2dde2ef36 100644 --- a/Adjust/ADJEvent.h +++ b/Adjust/ADJEvent.h @@ -21,10 +21,10 @@ + (ADJEvent *)eventWithEventToken:(NSString *)eventToken; - (void) addCallbackParameter:(NSString *)key - andValue:(NSString *)value; + value:(NSString *)value; - (void) addPartnerParameter:(NSString *)key - andValue:(NSString *)value; + value:(NSString *)value; - (void) setRevenue:(double)amount currency:(NSString *)currency; // check currency correctness, warn if weird diff --git a/Adjust/ADJEvent.m b/Adjust/ADJEvent.m index 81a05a3e8..3905d3afd 100644 --- a/Adjust/ADJEvent.m +++ b/Adjust/ADJEvent.m @@ -31,7 +31,7 @@ - (id) initWithEventToken:(NSString *)eventToken { } - (void) addCallbackParameter:(NSString *)key - andValue:(NSString *)value { + value:(NSString *)value { if (self.callbackParameters == nil) { self.callbackParameters = [[NSMutableDictionary alloc] init]; } @@ -44,7 +44,7 @@ - (void) addCallbackParameter:(NSString *)key } - (void) addPartnerParameter:(NSString *)key - andValue:(NSString *)value { + value:(NSString *)value { if (self.partnerParameters == nil) { self.partnerParameters = [[NSMutableDictionary alloc] init]; } From daf215358b3c5bf9116d49cf38adc6420ae9f1ec Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 16:28:01 +0100 Subject: [PATCH 58/86] Reword public api comments --- Adjust/ADJConfig.h | 46 ++++++++++++++++++++++++++++++--- Adjust/ADJEvent.h | 64 ++++++++++++++++++++++++++++++++++++++++++++-- Adjust/Adjust.h | 28 +++++++++++++++----- 3 files changed, 127 insertions(+), 11 deletions(-) diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index e2049e512..9d77f2bc7 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -16,6 +16,11 @@ @protocol AdjustDelegate @optional +/** + * Optional delegate method that will get called when a tracking attempt finished + * + * @param attribution The attribution information. See ADJAttribution for details. + */ - (void)adjustAttributionChanged:(ADJAttribution *)attribution; @end @@ -26,11 +31,46 @@ @property (nonatomic, assign) ADJLogLevel logLevel; @property (nonatomic, copy) NSString *environment; @property (nonatomic, copy) NSString *sdkPrefix; + +/** + * Configuration object for the initialization of the Adjust SDK. + * + * @param appToken The App Token of your app. This unique identifier can + * be found it in your dashboard at http://adjust.com and should always + * be 12 characters long. + * @param environment The current environment your app. We use this environment to + * distinguish between real traffic and artificial traffic from test devices. + * It is very important that you keep this value meaningful at all times! + * Especially if you are tracking revenue. + */ ++ (ADJConfig*)configWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; +- (id)initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; + +/** + * Enable event buffering if your app triggers a lot of events. + * When enabled, events get buffered and only get tracked each + * minute. Buffered events are still persisted, of course. + * + * @param eventBufferingEnabled Enable or disable event buffering + */ @property (nonatomic, assign) BOOL eventBufferingEnabled; + +/** + * Disable macMd5 tracking if your privacy constraints require it. + * + * @param macMd5TrackingEnabled Enable or disable tracking of + * the MD5 hash of the MAC address + */ @property (nonatomic, assign) BOOL macMd5TrackingEnabled; -@property (nonatomic, retain) NSObject *delegate; -- (id)initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; -+ (ADJConfig*)configWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; +/** + * Set the optional delegate that will inform you about attribution + * + * See the AdjustDelegate declaration above for details + * + * @param delegate The delegate that might implement the optional delegate + * methods like adjustAttributionChanged: + */ +@property (nonatomic, retain) NSObject *delegate; @end diff --git a/Adjust/ADJEvent.h b/Adjust/ADJEvent.h index 2dde2ef36..f297dfbdb 100644 --- a/Adjust/ADJEvent.h +++ b/Adjust/ADJEvent.h @@ -17,17 +17,77 @@ @property (nonatomic, copy) NSString* transactionId; @property (nonatomic, copy) NSString* currency; -- (id) initWithEventToken:(NSString *)eventToken; +/** + * Create Event object with Event Token. + * + * In your dashboard at http://adjust.com you can assign a callback URL to each + * event type. That URL will get called every time the event is triggered. On + * top of that you can pass a set of parameters to the following method that + * will be forwarded to these callbacks. + * + * TODO: Parameter parameter + * + * The event can contain some revenue. The amount is measured in units and + * rounded to the decimal cent point. It must include a currency in the + * ISO 4217 format + * + * A transaction ID can be used to avoid duplicate revenue events. The last ten + * transaction identifiers are remembered. + * + * @param event Event token that is created in the dashboard + * at http://adjust.com and should be six characters long. + */ + (ADJEvent *)eventWithEventToken:(NSString *)eventToken; +- (id) initWithEventToken:(NSString *)eventToken; +/** + * Add a key-pair to a callback URL. You must add as many as you want before + * using tracking the ADJEvent object + * + * In your dashboard at http://adjust.com you can assign a callback URL to each + * event type. That URL will get called every time the event is triggered. On + * top of that you can pass a set of parameters to the following method that + * will be forwarded to these callbacks. + * + * @param key String key in the callback URL. + * @param value String value of the key in the Callback URL. + * + */ - (void) addCallbackParameter:(NSString *)key value:(NSString *)value; +/** + * Add a key-pair to ... + * + * ... + * + * @param key ... + * @param value ... + * + */ - (void) addPartnerParameter:(NSString *)key value:(NSString *)value; +/** + * Set the revenue and associated currency of the event. + * + * The event can contain some revenue. The amount revenue is measured in units. + * It must include a currency in the ISO 4217 format. + * + * @param amount The amount in units (example: 1€50 is 1.5) + * @param currency String of the currency with ISO 4217 format. + * It should be 3 characters long (example: 1€50 is @"EUR") + */ - (void) setRevenue:(double)amount currency:(NSString *)currency; -// check currency correctness, warn if weird + +/** + * Set the transaction ID of a In-App Purchases to avoid revenue duplications. + * + * A transaction ID can be used to avoid duplicate revenue events. The last ten + * transaction identifiers are remembered. + * + * @param The identifier used to avoid duplicate revenue events + */ - (void) setTransactionId:(NSString *)transactionId; - (BOOL) isValid; diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index db1a503d4..5bf9ae883 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -31,7 +31,14 @@ static NSString * const ADJEnvironmentProduction = @"production"; * This is required to initialize Adjust. Call this in the didFinishLaunching * method of your AppDelegate. * - * @param appToken The App Token of your app. This unique identifier can + * Enable event buffering if your app triggers a lot of events. + * When enabled, events get buffered and only get tracked each + * minute. Buffered events are still persisted, of course. + * + * Disable macMd5 tracking if your privacy constraints require it. + * + * @param adjustConfig The configuration object that includes the environment + * and the App Token of your app. This unique identifier can * be found it in your dashboard at http://adjust.com and should always * be 12 characters long. */ @@ -45,8 +52,10 @@ static NSString * const ADJEnvironmentProduction = @"production"; * top of that you can pass a set of parameters to the following method that * will be forwarded to these callbacks. * - * The event can contain some revenue. The amount is measured in units and - * rounded to the decimal cent point. + * TODO: Partner parameter ... + * + * The event can contain some revenue. The amount revenue is measured in units. + * It must include a currency in the ISO 4217 format. * * A transaction ID can be used to avoid duplicate revenue events. The last ten * transaction identifiers are remembered. @@ -72,7 +81,8 @@ static NSString * const ADJEnvironmentProduction = @"production"; + (void)trackSubsessionEnd; /** - * Enable or disable the adjust SDK + * Enable or disable the adjust SDK. This setting is saved + * for future sessions * * @param enabled The flag to enable or disable the adjust SDK */ @@ -94,13 +104,19 @@ static NSString * const ADJEnvironmentProduction = @"production"; */ + (void)setDeviceToken:(NSData *)deviceToken; - +/** + * Enable or disable offline mode. Activities won't be sent + * but they are saved when offline mode is disabled. This + * feature is not saved for future sessions + */ + (void)setOfflineMode:(BOOL)enabled; +/** + * Obtain singleton Adjust object + */ + (id)getInstance; - (void)appDidLaunch:(ADJConfig *)adjustConfig; - - (void)trackEvent:(ADJEvent *)event; - (void)trackSubsessionStart; - (void)trackSubsessionEnd; From 7fe5eeb2028854e48fdc3587159ea815b2eccc35 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 16:28:28 +0100 Subject: [PATCH 59/86] Rename andValue --- example/example/ViewController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/example/ViewController.m b/example/example/ViewController.m index 18e2f4a3c..4483075e4 100644 --- a/example/example/ViewController.m +++ b/example/example/ViewController.m @@ -51,7 +51,7 @@ - (IBAction)clickEventWithCallback:(UIButton *)sender { ADJEvent *event = [ADJEvent eventWithEventToken:@"{YourEventToken}"]; // add callback parameters to this parameter - [event addCallbackParameter:@"key" andValue:@"value"]; + [event addCallbackParameter:@"key" value:@"value"]; [Adjust trackEvent:event]; } @@ -59,7 +59,7 @@ - (IBAction)clickEventWithPartner:(UIButton *)sender { ADJEvent *event = [ADJEvent eventWithEventToken:@"{YourEventToken}"]; // add partner parameteres to all events and sessions - [event addPartnerParameter:@"foo" andValue:@"bar"]; + [event addPartnerParameter:@"foo" value:@"bar"]; [Adjust trackEvent:event]; } From 3ce3d6425249948c31eb816b542f90855c760f2a Mon Sep 17 00:00:00 2001 From: Pedro Filipe Date: Fri, 5 Dec 2014 16:40:43 +0100 Subject: [PATCH 60/86] Update Mixpanel doc --- doc/mixpanel.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/mixpanel.md b/doc/mixpanel.md index 4708d266a..d780608f6 100644 --- a/doc/mixpanel.md +++ b/doc/mixpanel.md @@ -1,22 +1,22 @@ ##Integrate adjust with Mixpanel SDK -The Mixpanel API allows to register common properties to be sent in all activities as `super properties`, as it is explained in the [Mixpanel page][mixpanel_ios]. To integrate adjust with all tracked events of Mixpanel, you must set the `super properties` after receiving the response data of each activity. Follow the steps of the [delegate callbacks][response_callbacks] chapter in our iOS SDK guide to implement it. +The Mixpanel API allows to register common properties to be sent in all activities as `super properties`, as it is explained in the [Mixpanel page][mixpanel_ios]. To integrate adjust with all tracked events of Mixpanel, you must set the `super properties` after receiving the attribution data. Follow the steps of the [delegate callbacks][response_callbacks] chapter in our iOS SDK guide to implement it. The delegate function can be set as the following, to use the Mixpanel API: ```objc -- (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData { +- (void)adjustAttributionChanged:(ADJAttribution *)attribution { Mixpanel *mixpanel = [Mixpanel sharedInstance]; // The adjust properties will be sent // with all future track calls. - if (responseData.network != nil) - [mixpanel registerSuperProperties:@{@"[Adjust]Network": responseData.network}]; - if (responseData.campaign != nil) - [mixpanel registerSuperProperties:@{@"[Adjust]Campaign": responseData.campaign}]; - if (responseData.adgroup != nil) - [mixpanel registerSuperProperties:@{@"[Adjust]Adgroup": responseData.adgroup}]; - if (responseData.creative != nil) - [mixpanel registerSuperProperties:@{@"[Adjust]Creative": responseData.creative}]; + if (attribution.network != nil) + [mixpanel registerSuperProperties:@{@"[Adjust]Network": attribution.network}]; + if (attribution.campaign != nil) + [mixpanel registerSuperProperties:@{@"[Adjust]Campaign": attribution.campaign}]; + if (attribution.adgroup != nil) + [mixpanel registerSuperProperties:@{@"[Adjust]Adgroup": attribution.adgroup}]; + if (attribution.creative != nil) + [mixpanel registerSuperProperties:@{@"[Adjust]Creative": attribution.creative}]; } ``` From de46e98507d880eaed9d78ff93f4675659d65430 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 17:08:56 +0100 Subject: [PATCH 61/86] Fix attribution handler status code --- Adjust/ADJAttributionHandler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 826ffa4c2..c8aee6f90 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -142,7 +142,7 @@ -(void) getAttributionInternal { NSString* messageResponse = [jsonDict objectForKey:@"message"]; - if (statusCode != 200) { + if (statusCode == 200) { [self.logger debug:@"%@", messageResponse]; } else { [self.logger error:@"%@", messageResponse]; From 443548786c1a15194ed5ffb53eda7036eb54ece8 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 17:40:15 +0100 Subject: [PATCH 62/86] Rename tests to ADJ --- Adjust.xcodeproj/project.pbxproj | 76 +++++++++---------- ...HandlerMock.h => ADJActivityHandlerMock.h} | 4 +- ...HandlerMock.m => ADJActivityHandlerMock.m} | 16 ++-- ...ndlerTests.m => ADJActivityHandlerTests.m} | 60 +++++++-------- .../{AILoggerMock.h => ADJLoggerMock.h} | 2 +- .../{AILoggerMock.m => ADJLoggerMock.m} | 6 +- ...eHandlerMock.h => ADJPackageHandlerMock.h} | 4 +- ...eHandlerMock.m => ADJPackageHandlerMock.m} | 14 ++-- ...andlerTests.m => ADJPackageHandlerTests.m} | 54 ++++++------- ...tHandlerMock.h => ADJRequestHandlerMock.h} | 4 +- ...tHandlerMock.m => ADJRequestHandlerMock.m} | 16 ++-- AdjustTests/{AITestsUtil.h => ADJTestsUtil.h} | 8 +- AdjustTests/{AITestsUtil.m => ADJTestsUtil.m} | 12 +-- AdjustTests/AIRequestHandlerTests.m | 40 +++++----- ...NSURLConnectionSynchronousLoadingMocking.m | 4 +- 15 files changed, 160 insertions(+), 160 deletions(-) rename AdjustTests/{AIActivityHandlerMock.h => ADJActivityHandlerMock.h} (62%) rename AdjustTests/{AIActivityHandlerMock.m => ADJActivityHandlerMock.m} (87%) rename AdjustTests/{AIActivityHandlerTests.m => ADJActivityHandlerTests.m} (93%) rename AdjustTests/{AILoggerMock.h => ADJLoggerMock.h} (88%) rename AdjustTests/{AILoggerMock.m => ADJLoggerMock.m} (97%) rename AdjustTests/{AIPackageHandlerMock.h => ADJPackageHandlerMock.h} (78%) rename AdjustTests/{AIPackageHandlerMock.m => ADJPackageHandlerMock.m} (86%) rename AdjustTests/{AIPackageHandlerTests.m => ADJPackageHandlerTests.m} (75%) rename AdjustTests/{AIRequestHandlerMock.h => ADJRequestHandlerMock.h} (72%) rename AdjustTests/{AIRequestHandlerMock.m => ADJRequestHandlerMock.m} (78%) rename AdjustTests/{AITestsUtil.h => ADJTestsUtil.h} (63%) rename AdjustTests/{AITestsUtil.m => ADJTestsUtil.m} (84%) diff --git a/Adjust.xcodeproj/project.pbxproj b/Adjust.xcodeproj/project.pbxproj index eda2046a7..6a121d7cb 100644 --- a/Adjust.xcodeproj/project.pbxproj +++ b/Adjust.xcodeproj/project.pbxproj @@ -39,14 +39,14 @@ 96E5E39618BBB48A008E7B30 /* ADJRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37A18BBB48A008E7B30 /* ADJRequestHandler.m */; }; 96E5E39818BBB48A008E7B30 /* ADJTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E37E18BBB48A008E7B30 /* ADJTimer.m */; }; 96E5E39918BBB48A008E7B30 /* ADJUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E38018BBB48A008E7B30 /* ADJUtil.m */; }; - 96E5E3AF18BBB49E008E7B30 /* AIActivityHandlerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E39E18BBB49E008E7B30 /* AIActivityHandlerMock.m */; }; - 96E5E3B018BBB49E008E7B30 /* AIActivityHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E39F18BBB49E008E7B30 /* AIActivityHandlerTests.m */; }; - 96E5E3B118BBB49E008E7B30 /* AILoggerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A118BBB49E008E7B30 /* AILoggerMock.m */; }; - 96E5E3B218BBB49E008E7B30 /* AIPackageHandlerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A318BBB49E008E7B30 /* AIPackageHandlerMock.m */; }; - 96E5E3B318BBB49E008E7B30 /* AIPackageHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A418BBB49E008E7B30 /* AIPackageHandlerTests.m */; }; - 96E5E3B418BBB49E008E7B30 /* AIRequestHandlerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A618BBB49E008E7B30 /* AIRequestHandlerMock.m */; }; + 96E5E3AF18BBB49E008E7B30 /* ADJActivityHandlerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E39E18BBB49E008E7B30 /* ADJActivityHandlerMock.m */; }; + 96E5E3B018BBB49E008E7B30 /* ADJActivityHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E39F18BBB49E008E7B30 /* ADJActivityHandlerTests.m */; }; + 96E5E3B118BBB49E008E7B30 /* ADJLoggerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A118BBB49E008E7B30 /* ADJLoggerMock.m */; }; + 96E5E3B218BBB49E008E7B30 /* ADJPackageHandlerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A318BBB49E008E7B30 /* ADJPackageHandlerMock.m */; }; + 96E5E3B318BBB49E008E7B30 /* ADJPackageHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A418BBB49E008E7B30 /* ADJPackageHandlerTests.m */; }; + 96E5E3B418BBB49E008E7B30 /* ADJRequestHandlerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A618BBB49E008E7B30 /* ADJRequestHandlerMock.m */; }; 96E5E3B518BBB49E008E7B30 /* AIRequestHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A718BBB49E008E7B30 /* AIRequestHandlerTests.m */; }; - 96E5E3B618BBB49E008E7B30 /* AITestsUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A918BBB49E008E7B30 /* AITestsUtil.m */; }; + 96E5E3B618BBB49E008E7B30 /* ADJTestsUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3A918BBB49E008E7B30 /* ADJTestsUtil.m */; }; 96E5E3B718BBB49E008E7B30 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E5E3AA18BBB49E008E7B30 /* InfoPlist.strings */; }; 96E5E3B818BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E3AD18BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m */; }; 96E5E3B918BBB75F008E7B30 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9679921E18BBAE2800394606 /* XCTest.framework */; }; @@ -139,19 +139,19 @@ 96E5E38018BBB48A008E7B30 /* ADJUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJUtil.m; sourceTree = ""; }; 96E5E39B18BBB49E008E7B30 /* Adjust-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Adjust-Prefix.pch"; sourceTree = ""; }; 96E5E39C18BBB49E008E7B30 /* AdjustTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "AdjustTests-Info.plist"; sourceTree = ""; }; - 96E5E39D18BBB49E008E7B30 /* AIActivityHandlerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIActivityHandlerMock.h; sourceTree = ""; }; - 96E5E39E18BBB49E008E7B30 /* AIActivityHandlerMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIActivityHandlerMock.m; sourceTree = ""; }; - 96E5E39F18BBB49E008E7B30 /* AIActivityHandlerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIActivityHandlerTests.m; sourceTree = ""; }; - 96E5E3A018BBB49E008E7B30 /* AILoggerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AILoggerMock.h; sourceTree = ""; }; - 96E5E3A118BBB49E008E7B30 /* AILoggerMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AILoggerMock.m; sourceTree = ""; }; - 96E5E3A218BBB49E008E7B30 /* AIPackageHandlerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIPackageHandlerMock.h; sourceTree = ""; }; - 96E5E3A318BBB49E008E7B30 /* AIPackageHandlerMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIPackageHandlerMock.m; sourceTree = ""; }; - 96E5E3A418BBB49E008E7B30 /* AIPackageHandlerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIPackageHandlerTests.m; sourceTree = ""; }; - 96E5E3A518BBB49E008E7B30 /* AIRequestHandlerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIRequestHandlerMock.h; sourceTree = ""; }; - 96E5E3A618BBB49E008E7B30 /* AIRequestHandlerMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIRequestHandlerMock.m; sourceTree = ""; }; + 96E5E39D18BBB49E008E7B30 /* ADJActivityHandlerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJActivityHandlerMock.h; sourceTree = ""; }; + 96E5E39E18BBB49E008E7B30 /* ADJActivityHandlerMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityHandlerMock.m; sourceTree = ""; }; + 96E5E39F18BBB49E008E7B30 /* ADJActivityHandlerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJActivityHandlerTests.m; sourceTree = ""; }; + 96E5E3A018BBB49E008E7B30 /* ADJLoggerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJLoggerMock.h; sourceTree = ""; }; + 96E5E3A118BBB49E008E7B30 /* ADJLoggerMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJLoggerMock.m; sourceTree = ""; }; + 96E5E3A218BBB49E008E7B30 /* ADJPackageHandlerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJPackageHandlerMock.h; sourceTree = ""; }; + 96E5E3A318BBB49E008E7B30 /* ADJPackageHandlerMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJPackageHandlerMock.m; sourceTree = ""; }; + 96E5E3A418BBB49E008E7B30 /* ADJPackageHandlerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJPackageHandlerTests.m; sourceTree = ""; }; + 96E5E3A518BBB49E008E7B30 /* ADJRequestHandlerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJRequestHandlerMock.h; sourceTree = ""; }; + 96E5E3A618BBB49E008E7B30 /* ADJRequestHandlerMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJRequestHandlerMock.m; sourceTree = ""; }; 96E5E3A718BBB49E008E7B30 /* AIRequestHandlerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIRequestHandlerTests.m; sourceTree = ""; }; - 96E5E3A818BBB49E008E7B30 /* AITestsUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AITestsUtil.h; sourceTree = ""; }; - 96E5E3A918BBB49E008E7B30 /* AITestsUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AITestsUtil.m; sourceTree = ""; }; + 96E5E3A818BBB49E008E7B30 /* ADJTestsUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADJTestsUtil.h; sourceTree = ""; }; + 96E5E3A918BBB49E008E7B30 /* ADJTestsUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADJTestsUtil.m; sourceTree = ""; }; 96E5E3AB18BBB49E008E7B30 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 96E5E3AC18BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLConnection+NSURLConnectionSynchronousLoadingMocking.h"; sourceTree = ""; }; 96E5E3AD18BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m"; sourceTree = ""; }; @@ -290,19 +290,19 @@ children = ( 96E5E39B18BBB49E008E7B30 /* Adjust-Prefix.pch */, 96E5E39C18BBB49E008E7B30 /* AdjustTests-Info.plist */, - 96E5E39D18BBB49E008E7B30 /* AIActivityHandlerMock.h */, - 96E5E39E18BBB49E008E7B30 /* AIActivityHandlerMock.m */, - 96E5E39F18BBB49E008E7B30 /* AIActivityHandlerTests.m */, - 96E5E3A018BBB49E008E7B30 /* AILoggerMock.h */, - 96E5E3A118BBB49E008E7B30 /* AILoggerMock.m */, - 96E5E3A218BBB49E008E7B30 /* AIPackageHandlerMock.h */, - 96E5E3A318BBB49E008E7B30 /* AIPackageHandlerMock.m */, - 96E5E3A418BBB49E008E7B30 /* AIPackageHandlerTests.m */, - 96E5E3A518BBB49E008E7B30 /* AIRequestHandlerMock.h */, - 96E5E3A618BBB49E008E7B30 /* AIRequestHandlerMock.m */, + 96E5E39D18BBB49E008E7B30 /* ADJActivityHandlerMock.h */, + 96E5E39E18BBB49E008E7B30 /* ADJActivityHandlerMock.m */, + 96E5E39F18BBB49E008E7B30 /* ADJActivityHandlerTests.m */, + 96E5E3A018BBB49E008E7B30 /* ADJLoggerMock.h */, + 96E5E3A118BBB49E008E7B30 /* ADJLoggerMock.m */, + 96E5E3A218BBB49E008E7B30 /* ADJPackageHandlerMock.h */, + 96E5E3A318BBB49E008E7B30 /* ADJPackageHandlerMock.m */, + 96E5E3A418BBB49E008E7B30 /* ADJPackageHandlerTests.m */, + 96E5E3A518BBB49E008E7B30 /* ADJRequestHandlerMock.h */, + 96E5E3A618BBB49E008E7B30 /* ADJRequestHandlerMock.m */, 96E5E3A718BBB49E008E7B30 /* AIRequestHandlerTests.m */, - 96E5E3A818BBB49E008E7B30 /* AITestsUtil.h */, - 96E5E3A918BBB49E008E7B30 /* AITestsUtil.m */, + 96E5E3A818BBB49E008E7B30 /* ADJTestsUtil.h */, + 96E5E3A918BBB49E008E7B30 /* ADJTestsUtil.m */, 96E5E3AA18BBB49E008E7B30 /* InfoPlist.strings */, 96E5E3AC18BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.h */, 96E5E3AD18BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m */, @@ -438,17 +438,17 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 96E5E3B118BBB49E008E7B30 /* AILoggerMock.m in Sources */, - 96E5E3AF18BBB49E008E7B30 /* AIActivityHandlerMock.m in Sources */, - 96E5E3B318BBB49E008E7B30 /* AIPackageHandlerTests.m in Sources */, - 96E5E3B618BBB49E008E7B30 /* AITestsUtil.m in Sources */, + 96E5E3B118BBB49E008E7B30 /* ADJLoggerMock.m in Sources */, + 96E5E3AF18BBB49E008E7B30 /* ADJActivityHandlerMock.m in Sources */, + 96E5E3B318BBB49E008E7B30 /* ADJPackageHandlerTests.m in Sources */, + 96E5E3B618BBB49E008E7B30 /* ADJTestsUtil.m in Sources */, 96CD2BE11A13BFC600A40AFB /* UIDevice+ADJAdditions.m in Sources */, - 96E5E3B018BBB49E008E7B30 /* AIActivityHandlerTests.m in Sources */, + 96E5E3B018BBB49E008E7B30 /* ADJActivityHandlerTests.m in Sources */, 96CD2BE01A13BFC600A40AFB /* NSString+ADJAdditions.m in Sources */, 96E5E3B818BBB49E008E7B30 /* NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m in Sources */, - 96E5E3B418BBB49E008E7B30 /* AIRequestHandlerMock.m in Sources */, + 96E5E3B418BBB49E008E7B30 /* ADJRequestHandlerMock.m in Sources */, 96E5E3B518BBB49E008E7B30 /* AIRequestHandlerTests.m in Sources */, - 96E5E3B218BBB49E008E7B30 /* AIPackageHandlerMock.m in Sources */, + 96E5E3B218BBB49E008E7B30 /* ADJPackageHandlerMock.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/AdjustTests/AIActivityHandlerMock.h b/AdjustTests/ADJActivityHandlerMock.h similarity index 62% rename from AdjustTests/AIActivityHandlerMock.h rename to AdjustTests/ADJActivityHandlerMock.h index 69bdac334..883ef795c 100644 --- a/AdjustTests/AIActivityHandlerMock.h +++ b/AdjustTests/ADJActivityHandlerMock.h @@ -1,5 +1,5 @@ // -// AIActivityHandlerMock.h +// ADJActivityHandlerMock.h // Adjust // // Created by Pedro Filipe on 11/02/14. @@ -8,6 +8,6 @@ #import "ADJActivityHandler.h" -@interface AIActivityHandlerMock : NSObject +@interface ADJActivityHandlerMock : NSObject @end diff --git a/AdjustTests/AIActivityHandlerMock.m b/AdjustTests/ADJActivityHandlerMock.m similarity index 87% rename from AdjustTests/AIActivityHandlerMock.m rename to AdjustTests/ADJActivityHandlerMock.m index 7e2237a6e..b6aeb7599 100644 --- a/AdjustTests/AIActivityHandlerMock.m +++ b/AdjustTests/ADJActivityHandlerMock.m @@ -1,30 +1,30 @@ // -// AIActivityHandlerMock.m +// ADJActivityHandlerMock.m // Adjust // // Created by Pedro Filipe on 11/02/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIActivityHandlerMock.h" -#import "AILoggerMock.h" +#import "ADJActivityHandlerMock.h" +#import "ADJLoggerMock.h" #import "ADJAdjustFactory.h" -static NSString * const prefix = @"AIActivityHandler "; +static NSString * const prefix = @"ADJActivityHandler "; -@interface AIActivityHandlerMock() +@interface ADJActivityHandlerMock() -@property (nonatomic, strong) AILoggerMock *loggerMock; +@property (nonatomic, strong) ADJLoggerMock *loggerMock; @end -@implementation AIActivityHandlerMock +@implementation ADJActivityHandlerMock - (id)initWithConfig:(ADJConfig *)adjustConfig { self = [super init]; if (self == nil) return nil; - self.loggerMock = (AILoggerMock *) [ADJAdjustFactory logger]; + self.loggerMock = (ADJLoggerMock *) [ADJAdjustFactory logger]; [self.loggerMock test:[prefix stringByAppendingFormat:@"initWithConfig"]]; diff --git a/AdjustTests/AIActivityHandlerTests.m b/AdjustTests/ADJActivityHandlerTests.m similarity index 93% rename from AdjustTests/AIActivityHandlerTests.m rename to AdjustTests/ADJActivityHandlerTests.m index 083467577..197cd1b49 100644 --- a/AdjustTests/AIActivityHandlerTests.m +++ b/AdjustTests/ADJActivityHandlerTests.m @@ -1,5 +1,5 @@ // -// AIActivityHandlerTests.m +// ADJActivityHandlerTests.m // Adjust // // Created by Pedro Filipe on 07/02/14. @@ -7,23 +7,23 @@ // #import -#import "AILoggerMock.h" -#import "AIPackageHandlerMock.h" +#import "ADJLoggerMock.h" +#import "ADJPackageHandlerMock.h" #import "ADJAdjustFactory.h" #import "ADJActivityHandler.h" #import "ADJActivityPackage.h" -#import "AITestsUtil.h" +#import "ADJTestsUtil.h" #import "ADJUtil.h" #import "ADJLogger.h" -@interface AIActivityHandlerTests : XCTestCase +@interface ADJActivityHandlerTests : XCTestCase -@property (atomic,strong) AILoggerMock *loggerMock; -@property (atomic,strong) AIPackageHandlerMock *packageHandlerMock; +@property (atomic,strong) ADJLoggerMock *loggerMock; +@property (atomic,strong) ADJPackageHandlerMock *packageHandlerMock; @end -@implementation AIActivityHandlerTests +@implementation ADJActivityHandlerTests - (void)setUp { @@ -43,10 +43,10 @@ - (void)tearDown } - (void)reset { - self.loggerMock = [[AILoggerMock alloc] init]; + self.loggerMock = [[ADJLoggerMock alloc] init]; [ADJAdjustFactory setLogger:self.loggerMock]; - self.packageHandlerMock = [AIPackageHandlerMock alloc]; + self.packageHandlerMock = [ADJPackageHandlerMock alloc]; [ADJAdjustFactory setPackageHandler:self.packageHandlerMock]; [ADJAdjustFactory setSessionInterval:-1]; @@ -60,13 +60,13 @@ - (void)testFirstRun [self reset]; // deleting the activity state file to simulate a first session - XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); + XCTAssert([ADJTestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler and start the first session id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; // set the delegate to be called at after sending the package - AITestsUtil * testsUtil = [[AITestsUtil alloc] init]; + ADJTestsUtil * testsUtil = [[ADJTestsUtil alloc] init]; [activityHandler setDelegate:testsUtil]; // it's necessary to sleep the activity for a while after each handler call @@ -78,11 +78,11 @@ - (void)testFirstRun @"%@", self.loggerMock); // when a session package is being sent the package handler should resume sending - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler resumeSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler resumeSending"], @"%@", self.loggerMock); // if the package was build, it was sent to the Package Handler - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler addPackage"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler addPackage"], @"%@", self.loggerMock); // checking the default values of the first session package // should only have one package @@ -125,7 +125,7 @@ - (void)testFirstRun XCTAssertNotNil((NSString *)parameters[@"idfv"], @"%@", activityPackage.extendedString); // after adding, the activity handler ping the Package handler to send the package - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // check that the package handler calls back with the delegate @@ -146,7 +146,7 @@ - (void)testSessions { [self reset]; // starting from a clean slate - XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); + XCTAssert([ADJTestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // adjust the intervals for testing [ADJAdjustFactory setSessionInterval:(2)]; // 2 seconds @@ -189,7 +189,7 @@ - (void)testSessions { XCTAssertEqual(2, [(NSString *)parameters[@"subsession_count"] intValue], @"%@", activityPackage.extendedString); // check that the package handler was paused - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler pauseSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler pauseSending"], @"%@", self.loggerMock); */ } @@ -200,7 +200,7 @@ - (void)testEventsBuffered { [self reset]; // starting from a clean slate - XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); + XCTAssert([ADJTestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; @@ -302,7 +302,7 @@ - (void)testEventsNotBuffered { [self reset]; // starting from a clean slate - XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); + XCTAssert([ADJTestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; @@ -345,7 +345,7 @@ - (void)testEventsNotBuffered { XCTAssert([@"fc0721b6dfad5ee110975bb2a263de0061cc705b4a85a8ae3ccfbe7a662fb1ab" isEqualToString:eventPackageParameters[@"push_token"]], @"%@", eventPackage.extendedString); // check that the package handler was called - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // check the event count in the written activity state @@ -381,7 +381,7 @@ - (void)testEventsNotBuffered { XCTAssertNil(eventPackageParameters[@"params"], @"%@", eventPackage.extendedString); // check that the package handler was called - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // check the event count in the written activity state @@ -470,7 +470,7 @@ - (void)testDisable { [self reset]; // starting from a clean slate - XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); + XCTAssert([ADJTestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; @@ -497,11 +497,11 @@ - (void)testDisable { XCTAssert([self.loggerMock containsMessage:ADJLogLevelInfo beginsWith:@"First session"], @"%@", self.loggerMock); // delete the first session package from the log - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // making sure the timer fired did not call the package handler - XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"], + XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler sendFirstPackage"], @"%@", self.loggerMock); // test if the event was not triggered @@ -511,11 +511,11 @@ - (void)testDisable { XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 1 (revenue)"], @"%@", self.loggerMock); // verify that the application was paused - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler pauseSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler pauseSending"], @"%@", self.loggerMock); // verify that it was not resumed - XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler resumeSending"], + XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler resumeSending"], @"%@", self.loggerMock); // enable again @@ -538,11 +538,11 @@ - (void)testDisable { XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Event 2 (revenue)"], @"%@", self.loggerMock); // verify that the application was paused - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler pauseSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler pauseSending"], @"%@", self.loggerMock); // verify that it was also resumed - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler resumeSending"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler resumeSending"], @"%@", self.loggerMock); */ } @@ -553,7 +553,7 @@ - (void)testOpenUrl { [self reset]; // starting from a clean slate - XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); + XCTAssert([ADJTestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; @@ -626,7 +626,7 @@ - (void)testfinishedTrackingWithResponse { [self reset]; // starting from a clean slate - XCTAssert([AITestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); + XCTAssert([ADJTestsUtil deleteFile:@"AdjustIoActivityState" logger:self.loggerMock], @"%@", self.loggerMock); // create handler to start the session id activityHandler = [ADJAdjustFactory activityHandlerWithAppToken:@"123456789012"]; diff --git a/AdjustTests/AILoggerMock.h b/AdjustTests/ADJLoggerMock.h similarity index 88% rename from AdjustTests/AILoggerMock.h rename to AdjustTests/ADJLoggerMock.h index a60015e16..3a403c1e1 100644 --- a/AdjustTests/AILoggerMock.h +++ b/AdjustTests/ADJLoggerMock.h @@ -11,7 +11,7 @@ static const int ADJLogLevelTest = 0; -@interface AILoggerMock : NSObject +@interface ADJLoggerMock : NSObject - (void)test:(NSString *)message, ...; - (BOOL) containsMessage:(NSInteger)logLevel beginsWith:(NSString *)beginsWith; @end diff --git a/AdjustTests/AILoggerMock.m b/AdjustTests/ADJLoggerMock.m similarity index 97% rename from AdjustTests/AILoggerMock.m rename to AdjustTests/ADJLoggerMock.m index b34495401..004443e14 100644 --- a/AdjustTests/AILoggerMock.m +++ b/AdjustTests/ADJLoggerMock.m @@ -6,18 +6,18 @@ // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AILoggerMock.h" +#import "ADJLoggerMock.h" static NSString * const kLogTag = @"AdjustTests"; -@interface AILoggerMock() +@interface ADJLoggerMock() @property (nonatomic, strong) NSMutableString *logBuffer; @property (nonatomic, strong) NSDictionary *logMap; @end -@implementation AILoggerMock +@implementation ADJLoggerMock - (id)init { self = [super init]; diff --git a/AdjustTests/AIPackageHandlerMock.h b/AdjustTests/ADJPackageHandlerMock.h similarity index 78% rename from AdjustTests/AIPackageHandlerMock.h rename to AdjustTests/ADJPackageHandlerMock.h index a847f0cfb..fc6410e0a 100644 --- a/AdjustTests/AIPackageHandlerMock.h +++ b/AdjustTests/ADJPackageHandlerMock.h @@ -1,5 +1,5 @@ // -// AIPackageHandlerMock.h +// ADJPackageHandlerMock.h // Adjust // // Created by Pedro Filipe on 10/02/14. @@ -8,7 +8,7 @@ #import "ADJPackageHandler.h" -@interface AIPackageHandlerMock : NSObject +@interface ADJPackageHandlerMock : NSObject @property (nonatomic, strong) NSMutableArray *packageQueue; diff --git a/AdjustTests/AIPackageHandlerMock.m b/AdjustTests/ADJPackageHandlerMock.m similarity index 86% rename from AdjustTests/AIPackageHandlerMock.m rename to AdjustTests/ADJPackageHandlerMock.m index 15dd297cf..8e26b052b 100644 --- a/AdjustTests/AIPackageHandlerMock.m +++ b/AdjustTests/ADJPackageHandlerMock.m @@ -1,26 +1,26 @@ // -// AIPackageHandlerMock.m +// ADJPackageHandlerMock.m // Adjust // // Created by Pedro Filipe on 10/02/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIPackageHandlerMock.h" -#import "AILoggerMock.h" +#import "ADJPackageHandlerMock.h" +#import "ADJLoggerMock.h" #import "ADJAdjustFactory.h" #import "ADJActivityHandler.h" -static NSString * const prefix = @"AIPackageHandler "; +static NSString * const prefix = @"ADJPackageHandler "; -@interface AIPackageHandlerMock() +@interface ADJPackageHandlerMock() -@property (nonatomic, strong) AILoggerMock *loggerMock; +@property (nonatomic, strong) ADJLoggerMock *loggerMock; @property (nonatomic, assign) id activityHandler; @end -@implementation AIPackageHandlerMock +@implementation ADJPackageHandlerMock - (id)initWithActivityHandler:(id)activityHandler { self = [super init]; diff --git a/AdjustTests/AIPackageHandlerTests.m b/AdjustTests/ADJPackageHandlerTests.m similarity index 75% rename from AdjustTests/AIPackageHandlerTests.m rename to AdjustTests/ADJPackageHandlerTests.m index 8edd2e75f..b23411b15 100644 --- a/AdjustTests/AIPackageHandlerTests.m +++ b/AdjustTests/ADJPackageHandlerTests.m @@ -1,5 +1,5 @@ // -// AIPackageHandlerTests.m +// ADJPackageHandlerTests.m // Adjust // // Created by Pedro Filipe on 07/02/14. @@ -8,19 +8,19 @@ #import #import "ADJAdjustFactory.h" -#import "AILoggerMock.h" -#import "AIActivityHandlerMock.h" -#import "AIRequestHandlerMock.h" -#import "AITestsUtil.h" +#import "ADJLoggerMock.h" +#import "ADJActivityHandlerMock.h" +#import "ADJRequestHandlerMock.h" +#import "ADJTestsUtil.h" -@interface AIPackageHandlerTests : XCTestCase +@interface ADJPackageHandlerTests : XCTestCase -@property (atomic,strong) AILoggerMock *loggerMock; -@property (atomic,strong) AIRequestHandlerMock *requestHandlerMock; +@property (atomic,strong) ADJLoggerMock *loggerMock; +@property (atomic,strong) ADJRequestHandlerMock *requestHandlerMock; @end -@implementation AIPackageHandlerTests +@implementation ADJPackageHandlerTests - (void)setUp { @@ -38,10 +38,10 @@ - (void)tearDown } - (void)reset { - self.loggerMock = [[AILoggerMock alloc] init]; + self.loggerMock = [[ADJLoggerMock alloc] init]; [ADJAdjustFactory setLogger:self.loggerMock]; - self.requestHandlerMock = [AIRequestHandlerMock alloc]; + self.requestHandlerMock = [ADJRequestHandlerMock alloc]; [ADJAdjustFactory setRequestHandler:self.requestHandlerMock]; } @@ -53,17 +53,17 @@ - (void)testFirstPackage [self reset]; // delete previously created Package queue file to make a new queue - XCTAssert([AITestsUtil deleteFile:@"AdjustIoPackageQueue" logger:self.loggerMock], @"%@", self.loggerMock); + XCTAssert([ADJTestsUtil deleteFile:@"AdjustIoPackageQueue" logger:self.loggerMock], @"%@", self.loggerMock); // initialize Package Handler - AIActivityHandlerMock *activityHandler = [[AIActivityHandlerMock alloc] initWithAppToken:@"123456789012"]; + ADJActivityHandlerMock *activityHandler = [[ADJActivityHandlerMock alloc] initWithAppToken:@"123456789012"]; id packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:activityHandler]; // enable sending packages to Request Handler [packageHandler resumeSending]; // build and add the first package to the queue - [packageHandler addPackage:[AITestsUtil buildEmptyPackage]]; + [packageHandler addPackage:[ADJTestsUtil buildEmptyPackage]]; // send the first package in the queue to the mock request handler [packageHandler sendFirstPackage]; @@ -73,7 +73,7 @@ - (void)testFirstPackage [NSThread sleepForTimeInterval:1.0]; // check that the request handler mock was created - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); // test that the file did not exist in the first run of the application XCTAssert([self.loggerMock containsMessage:ADJLogLevelVerbose beginsWith:@"Package queue file not found"], @"%@", self.loggerMock); @@ -87,10 +87,10 @@ - (void)testFirstPackage XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Package handler wrote 1 packages"], @"%@", self.loggerMock); // check that the Request Handler was called to send the package - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler sendPackage"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJRequestHandler sendPackage"], @"%@", self.loggerMock); // check that the the request handler called the package callback, that foward it to the activity handler - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIActivityHandler finishedTrackingWithResponse"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJActivityHandler finishedTrackingWithResponse"], @"%@", self.loggerMock); // check that the package was removed from the queue and 0 packages were written @@ -104,14 +104,14 @@ - (void) testPaused { [self reset]; // initialize Package Handler - AIActivityHandlerMock *activityHandler = [[AIActivityHandlerMock alloc] initWithAppToken:@"123456789012"]; + ADJActivityHandlerMock *activityHandler = [[ADJActivityHandlerMock alloc] initWithAppToken:@"123456789012"]; id packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:activityHandler]; // disable sending packages to Request Handler [packageHandler pauseSending]; // build and add a package the queue - [packageHandler addPackage:[AITestsUtil buildEmptyPackage]]; + [packageHandler addPackage:[ADJTestsUtil buildEmptyPackage]]; // try to send the first package in the queue to the mock request handler [packageHandler sendFirstPackage]; @@ -119,13 +119,13 @@ - (void) testPaused { [NSThread sleepForTimeInterval:1.0]; // check that the request handler mock was created - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); // check that a package was added XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Added package"], @"%@", self.loggerMock); // check that the mock request handler was NOT called to send the package - XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler sendPackage"], @"%@", self.loggerMock); + XCTAssertFalse([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJRequestHandler sendPackage"], @"%@", self.loggerMock); // check that the package handler is paused XCTAssert([self.loggerMock containsMessage:ADJLogLevelDebug beginsWith:@"Package handler is paused"], @"%@", self.loggerMock); @@ -138,19 +138,19 @@ - (void) testMultiplePackages { [self reset]; // delete previously created Package queue file to make a new queue - XCTAssert([AITestsUtil deleteFile:@"AdjustIoPackageQueue" logger:self.loggerMock], @"%@", self.loggerMock); + XCTAssert([ADJTestsUtil deleteFile:@"AdjustIoPackageQueue" logger:self.loggerMock], @"%@", self.loggerMock); // initialize Package Handler - AIActivityHandlerMock *activityHandler = [[AIActivityHandlerMock alloc] initWithAppToken:@"123456789012"]; + ADJActivityHandlerMock *activityHandler = [[ADJActivityHandlerMock alloc] initWithAppToken:@"123456789012"]; id packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:activityHandler]; // enable sending packages to Request Handler [packageHandler resumeSending]; // build and add the 3 packages to the queue - [packageHandler addPackage:[AITestsUtil buildEmptyPackage]]; - [packageHandler addPackage:[AITestsUtil buildEmptyPackage]]; - [packageHandler addPackage:[AITestsUtil buildEmptyPackage]]; + [packageHandler addPackage:[ADJTestsUtil buildEmptyPackage]]; + [packageHandler addPackage:[ADJTestsUtil buildEmptyPackage]]; + [packageHandler addPackage:[ADJTestsUtil buildEmptyPackage]]; // create a new package handler to simulate a new launch [NSThread sleepForTimeInterval:1.0]; @@ -163,7 +163,7 @@ - (void) testMultiplePackages { [NSThread sleepForTimeInterval:1.0]; // check that the request handler mock was created - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJRequestHandler initWithPackageHandler"], @"%@", self.loggerMock); // test that the file did not exist in the first run of the application XCTAssert([self.loggerMock containsMessage:ADJLogLevelVerbose beginsWith:@"Package queue file not found"], @"%@", self.loggerMock); diff --git a/AdjustTests/AIRequestHandlerMock.h b/AdjustTests/ADJRequestHandlerMock.h similarity index 72% rename from AdjustTests/AIRequestHandlerMock.h rename to AdjustTests/ADJRequestHandlerMock.h index 56b5c7415..9dd182acc 100644 --- a/AdjustTests/AIRequestHandlerMock.h +++ b/AdjustTests/ADJRequestHandlerMock.h @@ -1,5 +1,5 @@ // -// AIRequestHandlerMock.h +// ADJRequestHandlerMock.h // Adjust // // Created by Pedro Filipe on 10/02/14. @@ -9,7 +9,7 @@ #import #import "ADJRequestHandler.h" -@interface AIRequestHandlerMock : NSObject +@interface ADJRequestHandlerMock : NSObject @property (nonatomic, assign) BOOL connectionError; diff --git a/AdjustTests/AIRequestHandlerMock.m b/AdjustTests/ADJRequestHandlerMock.m similarity index 78% rename from AdjustTests/AIRequestHandlerMock.m rename to AdjustTests/ADJRequestHandlerMock.m index 1c106bf43..de3bbfbfb 100644 --- a/AdjustTests/AIRequestHandlerMock.m +++ b/AdjustTests/ADJRequestHandlerMock.m @@ -1,32 +1,32 @@ // -// AIRequestHandlerMock.m +// ADJRequestHandlerMock.m // Adjust // // Created by Pedro Filipe on 10/02/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AIRequestHandlerMock.h" -#import "AILoggerMock.h" +#import "ADJRequestHandlerMock.h" +#import "ADJLoggerMock.h" #import "ADJAdjustFactory.h" -static NSString * const prefix = @"AIRequestHandler "; +static NSString * const prefix = @"ADJRequestHandler "; -@interface AIRequestHandlerMock() +@interface ADJRequestHandlerMock() @property (nonatomic, assign) id packageHandler; -@property (nonatomic, assign) AILoggerMock *loggerMock; +@property (nonatomic, assign) ADJLoggerMock *loggerMock; @end -@implementation AIRequestHandlerMock +@implementation ADJRequestHandlerMock - (id)initWithPackageHandler:(id) packageHandler { self = [super init]; if (self == nil) return nil; self.packageHandler = packageHandler; - self.loggerMock = (AILoggerMock *) [ADJAdjustFactory logger]; + self.loggerMock = (ADJLoggerMock *) [ADJAdjustFactory logger]; [self.loggerMock test:[prefix stringByAppendingString:@"initWithPackageHandler"]]; diff --git a/AdjustTests/AITestsUtil.h b/AdjustTests/ADJTestsUtil.h similarity index 63% rename from AdjustTests/AITestsUtil.h rename to AdjustTests/ADJTestsUtil.h index 106e497bc..86f2ca5dd 100644 --- a/AdjustTests/AITestsUtil.h +++ b/AdjustTests/ADJTestsUtil.h @@ -1,5 +1,5 @@ // -// AITestsUtil.h +// ADJTestsUtil.h // Adjust // // Created by Pedro Filipe on 12/02/14. @@ -7,14 +7,14 @@ // #import -#import "AILoggerMock.h" +#import "ADJLoggerMock.h" #import "ADJActivityPackage.h" #import "Adjust.h" -@interface AITestsUtil : NSObject +@interface ADJTestsUtil : NSObject + (NSString *)getFilename:(NSString *)filename; -+ (BOOL)deleteFile:(NSString *)filename logger:(AILoggerMock *)loggerMock; ++ (BOOL)deleteFile:(NSString *)filename logger:(ADJLoggerMock *)loggerMock; + (ADJActivityPackage *)buildEmptyPackage; @end diff --git a/AdjustTests/AITestsUtil.m b/AdjustTests/ADJTestsUtil.m similarity index 84% rename from AdjustTests/AITestsUtil.m rename to AdjustTests/ADJTestsUtil.m index 70e54eca6..1d6461307 100644 --- a/AdjustTests/AITestsUtil.m +++ b/AdjustTests/ADJTestsUtil.m @@ -1,17 +1,17 @@ // -// AITestsUtil.m +// ADJTestsUtil.m // Adjust // // Created by Pedro Filipe on 12/02/14. // Copyright (c) 2014 adjust GmbH. All rights reserved. // -#import "AITestsUtil.h" +#import "ADJTestsUtil.h" #import "ADJPackageBuilder.h" -#import "AILoggerMock.h" +#import "ADJLoggerMock.h" #import "ADJAdjustFactory.h" -@implementation AITestsUtil +@implementation ADJTestsUtil + (NSString *)getFilename:(NSString *)filename { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); @@ -20,8 +20,8 @@ + (NSString *)getFilename:(NSString *)filename { return filepath; } -+ (BOOL)deleteFile:(NSString *)filename logger:(AILoggerMock *)loggerMock { - NSString *filepath = [AITestsUtil getFilename:filename]; ++ (BOOL)deleteFile:(NSString *)filename logger:(ADJLoggerMock *)loggerMock { + NSString *filepath = [ADJTestsUtil getFilename:filename]; NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error = nil; BOOL exists = [fileManager fileExistsAtPath:filepath]; diff --git a/AdjustTests/AIRequestHandlerTests.m b/AdjustTests/AIRequestHandlerTests.m index b7f8d8427..1ba3541c3 100644 --- a/AdjustTests/AIRequestHandlerTests.m +++ b/AdjustTests/AIRequestHandlerTests.m @@ -1,5 +1,5 @@ // -// AIRequestHandlerTests.m +// ADJRequestHandlerTests.m // Adjust // // Created by Pedro Filipe on 07/02/14. @@ -8,22 +8,22 @@ #import #import "ADJAdjustFactory.h" -#import "AILoggerMock.h" +#import "ADJLoggerMock.h" #import "NSURLConnection+NSURLConnectionSynchronousLoadingMocking.h" -#import "AIPackageHandlerMock.h" -#import "AIRequestHandlerMock.h" -#import "AITestsUtil.h" +#import "ADJPackageHandlerMock.h" +#import "ADJRequestHandlerMock.h" +#import "ADJTestsUtil.h" -@interface AIRequestHandlerTests : XCTestCase +@interface ADJRequestHandlerTests : XCTestCase -@property (atomic,strong) AILoggerMock *loggerMock; -@property (atomic,strong) AIPackageHandlerMock *packageHandlerMock; +@property (atomic,strong) ADJLoggerMock *loggerMock; +@property (atomic,strong) ADJPackageHandlerMock *packageHandlerMock; @property (atomic,strong) id requestHandler; @end -@implementation AIRequestHandlerTests +@implementation ADJRequestHandlerTests - (void)setUp { @@ -43,10 +43,10 @@ - (void)tearDown } - (void)reset { - self.loggerMock = [[AILoggerMock alloc] init]; + self.loggerMock = [[ADJLoggerMock alloc] init]; [ADJAdjustFactory setLogger:self.loggerMock]; - self.packageHandlerMock = [[AIPackageHandlerMock alloc] init]; + self.packageHandlerMock = [[ADJPackageHandlerMock alloc] init]; self.requestHandler =[ADJAdjustFactory requestHandlerForPackageHandler:self.packageHandlerMock]; } @@ -60,7 +60,7 @@ - (void)testSendPackage [NSURLConnection setConnectionError:NO]; [NSURLConnection setResponseError:NO]; - [self.requestHandler sendPackage:[AITestsUtil buildEmptyPackage]]; + [self.requestHandler sendPackage:[ADJTestsUtil buildEmptyPackage]]; [NSThread sleepForTimeInterval:1.0]; @@ -71,7 +71,7 @@ - (void)testSendPackage @"%@", self.loggerMock); // check that the package handler was pinged after sending - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler finishedTrackingActivity"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler finishedTrackingActivity"], @"%@", self.loggerMock); // check the response data, the kind is unknown because is set by the package handler @@ -85,7 +85,7 @@ - (void)testSendPackage @"%@", self.loggerMock); // check that the package handler was called to send the next package - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendNextPackage"], @"%@", self.loggerMock); + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler sendNextPackage"], @"%@", self.loggerMock); */ } @@ -98,7 +98,7 @@ - (void)testConnectionError { [NSURLConnection setConnectionError:YES]; [NSURLConnection setResponseError:NO]; - [self.requestHandler sendPackage:[AITestsUtil buildEmptyPackage]]; + [self.requestHandler sendPackage:[ADJTestsUtil buildEmptyPackage]]; [NSThread sleepForTimeInterval:1.0]; // check the URL Connection was called @@ -106,7 +106,7 @@ - (void)testConnectionError { @"%@", self.loggerMock); // check that the package handler was pinged after sending - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler finishedTrackingActivity"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler finishedTrackingActivity"], @"%@", self.loggerMock); // check the response data, @@ -119,7 +119,7 @@ - (void)testConnectionError { @"%@", self.loggerMock); // check that the package handler was called to close the package to retry later - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler closeFirstPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler closeFirstPackage"], @"%@", self.loggerMock); */ @@ -134,14 +134,14 @@ - (void)testResponseError { [NSURLConnection setConnectionError:NO]; [NSURLConnection setResponseError:YES]; - [self.requestHandler sendPackage:[AITestsUtil buildEmptyPackage]]; + [self.requestHandler sendPackage:[ADJTestsUtil buildEmptyPackage]]; [NSThread sleepForTimeInterval:1.0]; // check the URL Connection was called XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"NSURLConnection sendSynchronousRequest"], @"%@", self.loggerMock); // check that the package handler was pinged after sending - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler finishedTrackingActivity"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler finishedTrackingActivity"], @"%@", self.loggerMock); // check the response data, @@ -155,7 +155,7 @@ - (void)testResponseError { @"%@", sresponseData); // check that the package handler was called to send the next package - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"AIPackageHandler sendNextPackage"], + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler sendNextPackage"], @"%@", self.loggerMock); */ } diff --git a/AdjustTests/NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m b/AdjustTests/NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m index 69ddb1fe2..58d1e1835 100644 --- a/AdjustTests/NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m +++ b/AdjustTests/NSURLConnection+NSURLConnectionSynchronousLoadingMocking.m @@ -7,7 +7,7 @@ // #import "NSURLConnection+NSURLConnectionSynchronousLoadingMocking.h" #import "ADJAdjustFactory.h" -#import "AILoggerMock.h" +#import "ADJLoggerMock.h" static BOOL triggerConnectionError = NO; static BOOL triggerResponseError = NO; @@ -15,7 +15,7 @@ @implementation NSURLConnection(NSURLConnectionSynchronousLoadingMock) + (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error { - AILoggerMock *loggerMock =(AILoggerMock *)ADJAdjustFactory.logger; + ADJLoggerMock *loggerMock =(ADJLoggerMock *)ADJAdjustFactory.logger; [loggerMock test:@"NSURLConnection sendSynchronousRequest"]; if (triggerConnectionError) { From 23081b247feb16de2a092fec11643d49c43aa293 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 17:49:41 +0100 Subject: [PATCH 63/86] Suppress Xcode warning --- Adjust/ADJUtil.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index a301e6f57..90517e06c 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -38,6 +38,9 @@ + (void)excludeFromBackup:(NSString *)path { const char* attrName = "com.apple.MobileBackup"; id logger = ADJAdjustFactory.logger; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" + if (&NSURLIsExcludedFromBackupKey == nil) { // iOS 5.0.1 and lower u_int8_t attrValue = 1; int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0); @@ -64,6 +67,8 @@ + (void)excludeFromBackup:(NSString *)path { [logger debug:@"Failed to exclude '%@' from backup (%@)", url.lastPathComponent, error.localizedDescription]; } } +#pragma clang diagnostic pop + } + (NSString *)formatSeconds1970:(double) value { From 8715efa2b60a42b2279bac5d1bb2b63a72a76121 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Fri, 5 Dec 2014 16:24:20 +0100 Subject: [PATCH 64/86] Wrap lines in Readme --- README.md | 105 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 289cd0579..af900b5a6 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,8 @@ This is the iOS SDK of adjust™. You can read more about adjust™ at ## Basic Installation -These are the minimal steps required to integrate the adjust SDK into your -iOS project. We are going to assume that you use Xcode for your iOS -development. +These are the minimal steps required to integrate the adjust SDK into your iOS +project. We are going to assume that you use Xcode for your iOS development. If you're using [CocoaPods][cocoapods], you can add the following line to your `Podfile` and continue with [step 3](#step3): @@ -18,7 +17,9 @@ pod 'Adjust', :git => 'git://github.com/adjust/ios_sdk.git', :tag => 'v4.0.0' ## Example app -There is an example app located inside the extracted folder named `example`. In it, you can open the Xcode project and see how the adjust SDK can be integrated. +There is an example app located inside the extracted folder named `example`. In +it, you can open the Xcode project and see how the adjust SDK can be +integrated. ### 1. Get the SDK @@ -28,8 +29,8 @@ archive in a folder of your choice. ### 2. Add it to your project 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. +group of your choice). From Finder drag the `Adjust` subdirectory into Xcode's +`Supporting Files` group. ![][drag] @@ -44,17 +45,21 @@ radio button to `Create groups for any added folders`. In the Project Navigator select your project. 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 group click on the `+` button. -Select the `AdSupport.framework` and click the `Add` button. Repeat the same step to -add the `iAd.framework`. In the list of frameworks select the newly added `AdSupport.framework` -and `iAd.framework`. Change the attribute `Required` to `Optional`. +Select the `AdSupport.framework` and click the `Add` button. Repeat the same +step to add the `iAd.framework`. In the list of frameworks select the newly +added `AdSupport.framework` and `iAd.framework`. Change the attribute +`Required` to `Optional`. ![][framework] ### 4. Integrate Adjust into your app -Inside the example app, you can find the class `ExampleAdjustHelper` with the static method `initAdjust` that contains the minimum configuration and the optional ones commented. +Inside the example app, you can find the class `ExampleAdjustHelper` with the +static method `initAdjust` that contains the minimum configuration and the +optional ones commented. -The `ADJConfig` object is where all optional configurations can be set before calling `appDidLaunch` method in the `Adjust` class. +The `ADJConfig` object is where all optional configurations can be set before +calling `appDidLaunch` method in the `Adjust` class. #### Minimum configuration @@ -109,14 +114,16 @@ You can increase or decrease the amount of logs you see in tests by calling #### Attribution callback -At install time, you can be notified of tracker attribution information. Due to the nature -of this information, it is not synchronous and can take some time before is available. -Follow these steps to implement the optional delegate protocol in your app delegate. +At install time, you can be notified of tracker attribution information. Due to +the nature of this information, it is not synchronous and can take some time +before is available. Follow these steps to implement the optional delegate +protocol in your app delegate. -Please make sure to consider [applicable attribution data policies.][attribution-data] +Please make sure to consider [applicable attribution data +policies.][attribution-data] -1. Open `AppDelegate.h` and add the `ADJConfig.h` import and the `AdjustDelegate` - declaration. +1. Open `AppDelegate.h` and add the `ADJConfig.h` import and the + `AdjustDelegate` declaration. ```objc #import "Adjust.h" @@ -131,22 +138,25 @@ Please make sure to consider [applicable attribution data policies.][attribution - (void)adjustAttributionCallback:(ADJAttribution *)attribution { } ``` - -3. When you are configuring the `ADJConfig` object, set the adjust delegate by calling `setDelegate` with the `AdjustDelegate` instace. + +3. When you are configuring the `ADJConfig` object, set the adjust delegate by + calling `setDelegate` with the `AdjustDelegate` instace. ```objc [adjustConfig setDelegate:self]; // if configuration is in the `AppDelegate.m` [adjustConfig setDelegate:adjustDelegate]; // if configuration is set in another class, see example app ``` -The delegate function will get called once somewhere after the install. Within the delegate function you have access to the `attribution` parameter. Here is a quick summary of its properties: +The delegate function will get called once somewhere after the install. 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 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. #### Enable event buffering @@ -168,26 +178,25 @@ adjust into your app. After the app launched, you should see the debug log #### Troubleshooting -- 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 to use ARC][transition]. 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: +- 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 to use ARC][transition]. 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 (AjustIo, AI..., ...+AIAdditions, AF..., ...+AFNetworking) and change the `Compiler - Flags` to `-fobjc-arc` (Select all and press the `Return` key to change - all at once). + Flags` to `-fobjc-arc` (Select all and press the `Return` key to change all + at once). ## Additional features -Once you integrated the adjust SDK into your project, you can take advantage -of the following features. +Once you integrated the adjust SDK into your project, you can take advantage of +the following features. ### 6. Add tracking of custom events. -You can tell adjust about every event you want. Suppose you want to track -every tap on a button. You would have to create a new Event Token in your +You can tell adjust about every event you want. Suppose you want to track every +tap on a button. You would have to create a new Event Token in your [dashboard]. Let's say that Event Token is `abc123`. In your button's `buttonDown` method you could then add the following line to track the click: @@ -196,21 +205,24 @@ ADJEvent * event = [ADJEvent eventWithEventToken:@"abc123"]; [Adjust trackEvent:event]; ``` -Before calling the `trackEvent` method, you can configure the `ADJEvent` object +Before calling the `trackEvent` method, you can configure the `ADJEvent` object -Inside the example app, you can find the class `ExampleAdjustHelper` with the static method `triggerEvent` that contains an example how to trigger an event. +Inside the example app, you can find the class `ExampleAdjustHelper` with the +static method `triggerEvent` that contains an example how to trigger an event. -The `ADJEvent` object is where all optional configurations can be set before calling the `trackEvent` method in the `Adjust` class. +The `ADJEvent` object is where all optional configurations can be set before +calling the `trackEvent` method in the `Adjust` class. #### Callback URK You can also register a callback URL for that event in your [dashboard] and we will send a GET request to that URL whenever the event gets tracked. In that -case you can add a key-value-pair to `addCallbackParameter` method of `ADJEvent`. -We will then append these named parameters to your callback URL. +case you can add a key-value-pair to `addCallbackParameter` method of +`ADJEvent`. We will then append these named parameters to your callback URL. For example, suppose you have registered the URL -`http://www.adjust.com/callback` then add following lines to the `ADJEvent` object: +`http://www.adjust.com/callback` then add following lines to the `ADJEvent` +object: ```objc [event addCallbackParameter:@"key" andValue:@"value"]; @@ -232,8 +244,8 @@ event, these parameters won't even be read. If your users can generate revenue by clicking on advertisements or making in-app purchases you can track those revenues. If, for example, a click is -worth one cent of an Euro, you can add the following calll to the `ADJEvent` object to track -that revenue: +worth one cent of an Euro, you can add the following calll to the `ADJEvent` +object to track that revenue: ```objc [event setRevenue:0.01 currency:@"EUR"]; @@ -304,7 +316,7 @@ You can verify if the adjust SDK is currently active with the method #### 9. Offline mode -You can put the adjust SDK in offline mode, preventing from tracking while in +You can put the adjust SDK in offline mode, preventing from tracking while in offline mode. When disabled, the tracking done in offline mode will be sent. Call the method `setOfflineMode` with the enabled parameter as `YES` to put it on offline mode, and `NO` to disable it. @@ -313,7 +325,6 @@ on offline mode, and `NO` to disable it. [Adjust setOfflineMode:YES]; ``` - [adjust.com]: http://adjust.com [cocoapods]: http://cocoapods.org [dashboard]: http://adjust.com From 5d556c1c40c0499ac717683050a94534e4d40b2b Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Fri, 5 Dec 2014 16:29:06 +0100 Subject: [PATCH 65/86] Update images in Readme --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index af900b5a6..5c5fc18c0 100644 --- a/README.md +++ b/README.md @@ -331,11 +331,11 @@ on offline mode, and `NO` to disable it. [releases]: https://github.com/adjust/ios_sdk/releases [arc]: http://en.wikipedia.org/wiki/Automatic_Reference_Counting [transition]: http://developer.apple.com/library/mac/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html -[drag]: https://raw.github.com/adjust/sdks/master/Resources/ios/drag3.png -[add]: https://raw.github.com/adjust/sdks/master/Resources/ios/add2.png -[framework]: https://raw.github.com/adjust/sdks/master/Resources/ios/framework3.png -[delegate]: https://raw.github.com/adjust/sdks/master/Resources/ios/delegate3.png -[run]: https://raw.github.com/adjust/sdks/master/Resources/ios/run3.png +[drag]: https://raw.github.com/adjust/sdks/master/Resources/ios/drag4.png +[add]: https://raw.github.com/adjust/sdks/master/Resources/ios/add3.png +[framework]: https://raw.github.com/adjust/sdks/master/Resources/ios/framework4.png +[delegate]: https://raw.github.com/adjust/sdks/master/Resources/ios/delegate4.png +[run]: https://raw.github.com/adjust/sdks/master/Resources/ios/run4.png [AEPriceMatrix]: https://github.com/adjust/AEPriceMatrix [attribution-data]: https://github.com/adjust/sdks/blob/master/doc/attribution-data.md From acf7b456996dbad8d00fd34a794a77683b6ef092 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Fri, 5 Dec 2014 17:36:51 +0100 Subject: [PATCH 66/86] Restructure Readme --- README.md | 307 ++++++++++++++++++++++++++---------------------------- 1 file changed, 145 insertions(+), 162 deletions(-) diff --git a/README.md b/README.md index 5c5fc18c0..f8fec372e 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,15 @@ This is the iOS SDK of adjust™. You can read more about adjust™ at [adjust.com]. -## Basic Installation +## Example app + +There is an example app inside the [`example` directory][example]. You can open +the Xcode project to see an example on how the adjust SDK can be integrated. + +## Basic integration -These are the minimal steps required to integrate the adjust SDK into your iOS -project. We are going to assume that you use Xcode for your iOS development. +We will describe the steps to integrate the adjust SDK into your iOS project. +We are going to assume that you use Xcode for your iOS development. If you're using [CocoaPods][cocoapods], you can add the following line to your `Podfile` and continue with [step 3](#step3): @@ -15,16 +20,10 @@ If you're using [CocoaPods][cocoapods], you can add the following line to your pod 'Adjust', :git => 'git://github.com/adjust/ios_sdk.git', :tag => 'v4.0.0' ``` -## Example app - -There is an example app located inside the extracted folder named `example`. In -it, you can open the Xcode project and see how the adjust SDK can be -integrated. - ### 1. Get the SDK Download the latest version from our [releases page][releases]. Extract the -archive in a folder of your choice. +archive into a directory of your choice. ### 2. Add it to your project @@ -35,8 +34,8 @@ group of your choice). From Finder drag the `Adjust` subdirectory into Xcode's ![][drag] In the dialog `Choose options for adding these files` make sure to check the -checkbox to `Copy items into destination group's folder` and select the upper -radio button to `Create groups for any added folders`. +checkbox to `Copy items if needed` and select the radio button to `Create +groups`. ![][add] @@ -44,189 +43,126 @@ radio button to `Create groups for any added folders`. In the Project Navigator select your project. 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 group click on the `+` button. +Binary with Libraries`. On the bottom of that section click on the `+` button. Select the `AdSupport.framework` and click the `Add` button. Repeat the same -step to add the `iAd.framework`. In the list of frameworks select the newly -added `AdSupport.framework` and `iAd.framework`. Change the attribute -`Required` to `Optional`. +steps to add the `iAd.framework`. Change the `Status` of both frameworks to +`Optional`. ![][framework] ### 4. Integrate Adjust into your app -Inside the example app, you can find the class `ExampleAdjustHelper` with the -static method `initAdjust` that contains the minimum configuration and the -optional ones commented. +At first we set up basic session tracking. -The `ADJConfig` object is where all optional configurations can be set before -calling `appDidLaunch` method in the `Adjust` class. +#### Basic Setup -#### Minimum configuration - -In the Project Navigator open the source file your Application Delegate. Add +In the Project Navigator open the source file your application delegate. Add the `import` statement at the top of the file. In the `didFinishLaunching` or -`didFinishLaunchingWithOptions` method of your App Delegate add the following -calls to `Adjust`: +`didFinishLaunchingWithOptions` method of your app delegate add the following +call to `Adjust`: ```objc -#import "ADJConfig.h" #import "Adjust.h" // ... -NSString * yourAppToken = @"{YourAppToken}"; -NSString * enviroment = AIEnvironmentSandbox; -ADJConfig * adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; +NSString *yourAppToken = @"{YourAppToken}"; +NSString *enviroment = ADJEnvironmentSandbox; +ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken + andEnvironment:enviroment]; [Adjust appDidLaunch:adjustConfig]; ``` ![][delegate] -Replace `{YourAppToken}` with your App Token. You can find in your [dashboard]. +Replace `{YourAppToken}` with your app token. You can find in your [dashboard]. -Depending on whether or not you build your app for testing or for production -you must set `enviroment` with one of these values: +Depending on whether you build your app for testing or for production you must +set `enviroment` with one of these values: ```objc -NSString * enviroment = AIEnvironmentSandbox; -NSString * enviroment = AIEnvironmentProduction; +NSString *enviroment = ADJEnvironmentSandbox; +NSString *enviroment = ADJEnvironmentProduction; ``` -**Important:** This value should be set to `AIEnvironmentSandbox` if and only +**Important:** This value should be set to `ADJEnvironmentSandbox` if and only if you or someone else is testing your app. Make sure to set the environment to -`AIEnvironmentProduction` just before you publish the app. Set it back to -`AIEnvironmentSandbox` when you start testing it again. +`ADJEnvironmentProduction` just before you publish the app. Set it back to +`ADJEnvironmentSandbox` when you start developing and testing it again. -We use this environment to distinguish between real traffic and artificial -traffic from test devices. It is very important that you keep this value -meaningful at all times! Especially if you are tracking revenue. +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! Especially if you are tracking revenue. -#### Logging +#### Adjust Logging You can increase or decrease the amount of logs you see in tests by calling -`setLogLevel:` on the `ADJConfig` object with one of the following parameters: +`setLogLevel:` on your `ADJConfig` instance with one of the following +parameters: ```objc [adjustConfig setLogLevel:ADJLogLevelVerbose]; // enable all logging -[adjustConfig setLogLevel:AILogLevelDebug]; // enable more logging -[adjustConfig setLogLevel:AILogLevelInfo]; // the default -[adjustConfig setLogLevel:AILogLevelWarn]; // disable info logging -[adjustConfig setLogLevel:AILogLevelError]; // disable warnings as well -[adjustConfig setLogLevel:AILogLevelAssert]; // disable errors as well -``` - -#### Attribution callback - -At install time, you can be notified of tracker attribution information. Due to -the nature of this information, it is not synchronous and can take some time -before is available. Follow these steps to implement the optional delegate -protocol in your app delegate. - -Please make sure to consider [applicable attribution data -policies.][attribution-data] - -1. Open `AppDelegate.h` and add the `ADJConfig.h` import and the - `AdjustDelegate` declaration. - - ```objc - #import "Adjust.h" - - @interface AppDelegate : UIResponder - ``` - -2. Open `AppDelegate.m` and add the following delegate callback function to - your app delegate implementation. - - ```objc - - (void)adjustAttributionCallback:(ADJAttribution *)attribution { - } - ``` - -3. When you are configuring the `ADJConfig` object, set the adjust delegate by - calling `setDelegate` with the `AdjustDelegate` instace. - - ```objc - [adjustConfig setDelegate:self]; // if configuration is in the `AppDelegate.m` - [adjustConfig setDelegate:adjustDelegate]; // if configuration is set in another class, see example app - ``` - -The delegate function will get called once somewhere after the install. 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. - -#### Enable 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 by adding the following line to the `ADJConfig` object: - -```objc -[adjustConfig setEventBufferingEnabled:YES]; +[adjustConfig setLogLevel:ADJLogLevelDebug]; // enable more logging +[adjustConfig setLogLevel:ADJLogLevelInfo]; // the default +[adjustConfig setLogLevel:ADJLogLevelWarn]; // disable info logging +[adjustConfig setLogLevel:ADJLogLevelError]; // disable warnings as well +[adjustConfig setLogLevel:ADJLogLevelAssert]; // disable errors as well ``` ### 5. Build your app -Build and run your app. If the build succeeds, you successfully integrated -adjust into your app. After the app launched, you should see the debug log -`Tracked session start`. +Build and run your app. If the build succeeds, you should carefully read the +SDK logs in the console. After the app launched for the first time, you should +see the info log `Install tracked`. ![][run] #### Troubleshooting -- 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 to use ARC][transition]. 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: +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 to use ARC][transition]. 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 (AjustIo, - AI..., ...+AIAdditions, AF..., ...+AFNetworking) and change the `Compiler - Flags` to `-fobjc-arc` (Select all and press the `Return` key to change all - at once). +Expand the `Compile Sources` group, select all adjust files (Adjust, ADJ..., +...+ADJAdditions) and change the `Compiler Flags` to `-fobjc-arc` (Select all +and press the `Return` key to change all at once). ## Additional features Once you integrated the adjust SDK into your project, you can take advantage of the following features. -### 6. Add tracking of custom events. +### 6. Set up event tracking -You can tell adjust about every event you want. Suppose you want to track every -tap on a button. You would have to create a new Event Token in your -[dashboard]. Let's say that Event Token is `abc123`. In your button's -`buttonDown` method you could then add the following line to track the click: +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]. It +might look like this: `abc123`. In your button's `buttonDown` method you would +then add the following lines to track the tap: ```objc -ADJEvent * event = [ADJEvent eventWithEventToken:@"abc123"]; +ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"]; [Adjust trackEvent:event]; ``` -Before calling the `trackEvent` method, you can configure the `ADJEvent` object - -Inside the example app, you can find the class `ExampleAdjustHelper` with the -static method `triggerEvent` that contains an example how to trigger an event. +When tapping the button you should now see `Event tracked` in the logs. -The `ADJEvent` object is where all optional configurations can be set before -calling the `trackEvent` method in the `Adjust` class. +The event instance can be used to configure the event even more before tracking +it. -#### Callback URK +#### Add callback parameters -You can also register a callback URL for that event in your [dashboard] and we -will send a GET request to that URL whenever the event gets tracked. In that -case you can add a key-value-pair to `addCallbackParameter` method of -`ADJEvent`. We will then append these named parameters to your callback URL. +You can register a callback URL for your events in your [dashboard]. We will +send a GET request to that URL whenever the event gets tracked. You can add +callback parameters to that event by calling `addCallbackParameter` on the +event before tracking it. We will then append these parameters to your callback +URL. For example, suppose you have registered the URL -`http://www.adjust.com/callback` then add following lines to the `ADJEvent` -object: +`http://www.adjust.com/callback` then track an event like this: ```objc +ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"]; [event addCallbackParameter:@"key" andValue:@"value"]; [event addCallbackParameter:@"foo" andValue:@"bar"]; +[Adjust trackEvent:event]; ``` In that case we would track the event and send a request to: @@ -242,15 +178,20 @@ event, these parameters won't even be read. #### Track revenue -If your users can generate revenue by clicking on advertisements or making -in-app purchases you can track those revenues. If, for example, a click is -worth one cent of an Euro, you can add the following calll to the `ADJEvent` -object to track that revenue: +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: ```objc +ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"]; [event setRevenue:0.01 currency:@"EUR"]; +[Adjust trackEvent:event]; ``` +This can be combined with callback parameters of course. + +#### Revenue deduplication + You can also pass in an optional transaction ID to avoid tracking duplicate revenues. The last ten transaction IDs are remembered and revenue events with duplicate transaction IDs are skipped. This is especially useful for In-App @@ -258,7 +199,8 @@ Purchase tracking. See an example below. If you want to track In-App Purchases, please make sure to call `trackEvent` after `finishTransaction` in `paymentQueue:updatedTransaction` only if the -state changed to `SKPaymentTransactionStatePurchased`: +state changed to `SKPaymentTransactionStatePurchased`. That way you can avoid +tracking revenue that is not actually being generated. ```objc - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { @@ -267,7 +209,7 @@ state changed to `SKPaymentTransactionStatePurchased`: case SKPaymentTransactionStatePurchased: [self finishTransaction:transaction]; - ADJEvent * event = [ADJEvent eventWithEventToken:...]; + ADJEvent *event = [ADJEvent eventWithEventToken:...]; [event setRevenue:... currency:...]; [event setTransactionId:transaction.transactionIdentifier]; // avoid duplicates [Adjust trackEvent:event]; @@ -279,15 +221,12 @@ state changed to `SKPaymentTransactionStatePurchased`: } ``` -If you want to track all revenues in the same currency you might want to use -[AEPriceMatrix][AEPriceMatrix] to do simple tier based currency conversion. - -### 7. Handle reattributions with deep linking +### 7. Set up deep link reattributions -You can also set up the adjust SDK to read deep links that come to your app, -also known as custom URL schemes in iOS. We will only read the data that is -injected by adjust tracker URLs. This is essential if you are planning to run -retargeting or re-engagement campaigns with deep links. +You can set up the adjust SDK to handle deep links that are used to open your +app via a custom URL scheme. We will only read certain adjust specific +parameters. This is essential if you are planning to run retargeting or +re-engagement campaigns with deep links. In the Project Navigator open the source file your Application Delegate. Find or add the method `openURL` and add the following call to adjust: @@ -300,34 +239,78 @@ or add the method `openURL` and add the following call to adjust: } ``` -#### 8. Disable tracking +### 8. Enable event buffering -You can disable the adjust SDK from tracking by invoking the method -`setEnabled` with the enabled parameter as `NO`. This setting is remembered -between sessions, but it can only be activated after the first session. +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: ```objc -[Adjust setEnabled:NO]; +[adjustConfig setEventBufferingEnabled:YES]; ``` -You can verify if the adjust SDK is currently active with the method -`isEnabled`. It is always possible to activate the adjust SDK by invoking -`setEnabled` with the enabled parameter as `YES`. +### 9. Implement the attribution callback -#### 9. Offline mode +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 by provided synchronously. Follow these steps to implement +the optional delegate protocol in your app delegate: -You can put the adjust SDK in offline mode, preventing from tracking while in -offline mode. When disabled, the tracking done in offline mode will be sent. -Call the method `setOfflineMode` with the enabled parameter as `YES` to put it -on offline mode, and `NO` to disable it. +Please make sure to consider our [applicable attribution data +policies.][attribution-data] + +1. Open `AppDelegate.h` and add the import and the `AdjustDelegate` + declaration. + + ```objc + #import "Adjust.h" + + @interface AppDelegate : UIResponder + ``` + +2. Open `AppDelegate.m` and add the following delegate callback function to + your app delegate implementation. + + ```objc + - (void)adjustAttributionCallback:(ADJAttribution *)attribution { + } + ``` + +3. Set the delegate with your `ADJConfig` instance: + + ```objc + [adjustConfig setDelegate:self]; + ``` + +The delegate function will get when the SDK receives 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. + +### 10. 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. ```objc -[Adjust setOfflineMode:YES]; +[Adjust setEnabled:NO]; ``` +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`. + [adjust.com]: http://adjust.com [cocoapods]: http://cocoapods.org [dashboard]: http://adjust.com +[example]: http://github.com/adjust/ios_sdk/tree/master/example [releases]: https://github.com/adjust/ios_sdk/releases [arc]: http://en.wikipedia.org/wiki/Automatic_Reference_Counting [transition]: http://developer.apple.com/library/mac/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html From 39a664e574da47720793bacd1e4e00ffa654f429 Mon Sep 17 00:00:00 2001 From: Pedro Filipe Date: Fri, 5 Dec 2014 18:00:55 +0100 Subject: [PATCH 67/86] Reworded delegate name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f8fec372e..530ca9902 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ policies.][attribution-data] your app delegate implementation. ```objc - - (void)adjustAttributionCallback:(ADJAttribution *)attribution { + - (void)adjustAttributionChanged:(ADJAttribution *)attribution { } ``` From adbf082135aa9445cd7dec1d77cc92bd083a2b86 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 18:31:59 +0100 Subject: [PATCH 68/86] Rename purchase date --- Adjust/ADJActivityHandler.m | 2 +- Adjust/ADJPackageBuilder.h | 2 +- Adjust/ADJPackageBuilder.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index c0cae6488..d4f75bfe1 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -161,7 +161,7 @@ - (void)setIadDate:(NSDate *)iAdImpressionDate withPurchaseDate:(NSDate *)appPur andConfig:self.adjustConfig]; [clickBuilder setClickTime:iAdImpressionDate]; - [clickBuilder setPurchaseDate:appPurchaseDate]; + [clickBuilder setPurchaseTime:appPurchaseDate]; ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"iad"]; [self.packageHandler sendClickPackage:clickPackage]; diff --git a/Adjust/ADJPackageBuilder.h b/Adjust/ADJPackageBuilder.h index cd95c9068..e4ed9a188 100644 --- a/Adjust/ADJPackageBuilder.h +++ b/Adjust/ADJPackageBuilder.h @@ -20,7 +20,7 @@ @property (nonatomic, assign) BOOL hasDelegate; @property (nonatomic, copy) ADJAttribution *attribution; @property (nonatomic, copy) NSDate *clickTime; -@property (nonatomic, copy) NSDate *purchaseDate; +@property (nonatomic, copy) NSDate *purchaseTime; @property (nonatomic, copy) NSDictionary* deeplinkParameters; - (id) initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index dada6b0da..4334d4764 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -71,7 +71,7 @@ - (ADJActivityPackage *)buildClickPackage:(NSString *)clickSource{ [self parameters:parameters setString:@"source" forKey:clickSource]; [self parameters:parameters setDictionaryJson:self.deeplinkParameters forKey:@"params"]; [self parameters:parameters setDate:self.clickTime forKey:@"click_time"]; - [self parameters:parameters setDate:self.purchaseDate forKey:@"purchase_time"]; + [self parameters:parameters setDate:self.purchaseTime forKey:@"purchase_time"]; if (self.attribution != nil) { [self parameters:parameters setString:self.attribution.trackerName forKey:@"tracker"]; From ffe642c2d61c9325a868bb1f32556d126a6d89c4 Mon Sep 17 00:00:00 2001 From: Pedro Date: Fri, 5 Dec 2014 18:32:32 +0100 Subject: [PATCH 69/86] Reword api comments --- Adjust/ADJConfig.h | 2 +- Adjust/ADJEvent.h | 31 +++++++------------------------ Adjust/Adjust.h | 19 ++----------------- 3 files changed, 10 insertions(+), 42 deletions(-) diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index 9d77f2bc7..b53f0364c 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -17,7 +17,7 @@ @optional /** - * Optional delegate method that will get called when a tracking attempt finished + * Optional delegate method that gets called when the attribution information changed * * @param attribution The attribution information. See ADJAttribution for details. */ diff --git a/Adjust/ADJEvent.h b/Adjust/ADJEvent.h index f297dfbdb..02267a081 100644 --- a/Adjust/ADJEvent.h +++ b/Adjust/ADJEvent.h @@ -20,20 +20,6 @@ /** * Create Event object with Event Token. * - * In your dashboard at http://adjust.com you can assign a callback URL to each - * event type. That URL will get called every time the event is triggered. On - * top of that you can pass a set of parameters to the following method that - * will be forwarded to these callbacks. - * - * TODO: Parameter parameter - * - * The event can contain some revenue. The amount is measured in units and - * rounded to the decimal cent point. It must include a currency in the - * ISO 4217 format - * - * A transaction ID can be used to avoid duplicate revenue events. The last ten - * transaction identifiers are remembered. - * * @param event Event token that is created in the dashboard * at http://adjust.com and should be six characters long. */ @@ -41,12 +27,11 @@ - (id) initWithEventToken:(NSString *)eventToken; /** - * Add a key-pair to a callback URL. You must add as many as you want before - * using tracking the ADJEvent object + * Add a key-pair to a callback URL. * * In your dashboard at http://adjust.com you can assign a callback URL to each * event type. That URL will get called every time the event is triggered. On - * top of that you can pass a set of parameters to the following method that + * top of that you can add callback parameters to the following method that * will be forwarded to these callbacks. * * @param key String key in the callback URL. @@ -57,12 +42,10 @@ value:(NSString *)value; /** - * Add a key-pair to ... - * - * ... + * Add a key-pair to be fowarded to a partner. * - * @param key ... - * @param value ... + * @param key String key to be fowarded to the partner + * @param value String value of the key to be fowarded to the partner * */ - (void) addPartnerParameter:(NSString *)key @@ -74,9 +57,9 @@ * The event can contain some revenue. The amount revenue is measured in units. * It must include a currency in the ISO 4217 format. * - * @param amount The amount in units (example: 1€50 is 1.5) + * @param amount The amount in units (example: for 1.50 EUR is 1.5) * @param currency String of the currency with ISO 4217 format. - * It should be 3 characters long (example: 1€50 is @"EUR") + * It should be 3 characters long (example: for 1.50 EUR is @"EUR") */ - (void) setRevenue:(double)amount currency:(NSString *)currency; diff --git a/Adjust/Adjust.h b/Adjust/Adjust.h index 5bf9ae883..a476601c5 100644 --- a/Adjust/Adjust.h +++ b/Adjust/Adjust.h @@ -31,11 +31,7 @@ static NSString * const ADJEnvironmentProduction = @"production"; * This is required to initialize Adjust. Call this in the didFinishLaunching * method of your AppDelegate. * - * Enable event buffering if your app triggers a lot of events. - * When enabled, events get buffered and only get tracked each - * minute. Buffered events are still persisted, of course. - * - * Disable macMd5 tracking if your privacy constraints require it. + * See ADJConfig.h for more configuration options * * @param adjustConfig The configuration object that includes the environment * and the App Token of your app. This unique identifier can @@ -47,18 +43,7 @@ static NSString * const ADJEnvironmentProduction = @"production"; /** * Tell Adjust that a particular event has happened. * - * In your dashboard at http://adjust.com you can assign a callback URL to each - * event type. That URL will get called every time the event is triggered. On - * top of that you can pass a set of parameters to the following method that - * will be forwarded to these callbacks. - * - * TODO: Partner parameter ... - * - * The event can contain some revenue. The amount revenue is measured in units. - * It must include a currency in the ISO 4217 format. - * - * A transaction ID can be used to avoid duplicate revenue events. The last ten - * transaction identifiers are remembered. + * See ADJEvent.h for more event options * * @param event The Event object for this kind of event. It needs a event token * that is created in the dashboard at http://adjust.com and should be six From d612131bb0c14b74a598ebadd3c28f2cd6bc510a Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 11:44:05 +0100 Subject: [PATCH 70/86] Deeplink adjust attribution --- Adjust/ADJActivityHandler.m | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index d4f75bfe1..933c3a6e9 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -368,7 +368,6 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { NSArray* queryArray = [url.query componentsSeparatedByString:@"&"]; NSMutableDictionary* adjustDeepLinks = [NSMutableDictionary dictionary]; ADJAttribution *attribution = [[ADJAttribution alloc] init]; - BOOL adjustParamsFound = NO; for (NSString* fieldValuePair in queryArray) { NSArray* pairComponents = [fieldValuePair componentsSeparatedByString:@"="]; @@ -383,18 +382,18 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { NSString* keyWOutPrefix = [key substringFromIndex:kAdjustPrefix.length]; if (keyWOutPrefix.length == 0) continue; - adjustParamsFound = YES; if (![self trySetAttributionDeeplink:attribution withKey:keyWOutPrefix withValue:value]) { [adjustDeepLinks setObject:value forKey:keyWOutPrefix]; } } - [self.attributionHandler getAttribution]; - - if (!adjustParamsFound) { + if ([adjustDeepLinks count] <= 0) { return; } + [self.attributionHandler getAttribution]; + + ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo andActivityState:self.activityState andConfig:self.adjustConfig]; From 20d34595dad417d04506996cbfe079f5370b6231 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 11:44:58 +0100 Subject: [PATCH 71/86] Attribution serial queue --- Adjust/ADJAttributionHandler.m | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index c8aee6f90..91f84ea98 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -14,6 +14,7 @@ #import "ADJTimer.h" static const uint64_t kTimerLeeway = 1 * NSEC_PER_SEC; // 1 second +static const char * const kInternalQueueName = "com.adjust.AttributionQueue"; @interface ADJAttributionHandler() @@ -46,14 +47,14 @@ - (id)initWithActivityHandler:(id) activityHandler self = [super init]; if (self == nil) return nil; - self.internalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); self.activityHandler = activityHandler; self.logger = ADJAdjustFactory.logger; self.attributionPackage = attributionPackage; if (milliseconds != nil) { - uint64_t timer_nano = [milliseconds intValue] * NSEC_PER_MSEC; - self.maxDelayTimer = [ADJTimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self.activityHandler launchAttributionDelegate]; }]; + uint64_t timerNano = [milliseconds intValue] * NSEC_PER_MSEC; + self.maxDelayTimer = [ADJTimer timerWithStart:timerNano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self.activityHandler launchAttributionDelegate]; }]; [self.maxDelayTimer resume]; } @@ -83,9 +84,9 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { NSDictionary* jsonAttribution = [jsonDict objectForKey:@"attribution"]; ADJAttribution *attribution = [ADJAttribution dataWithJsonDict:jsonAttribution]; - NSNumber *timer_milliseconds = [jsonDict objectForKey:@"ask_in"]; + NSNumber *timerMilliseconds = [jsonDict objectForKey:@"ask_in"]; - if (timer_milliseconds == nil) { + if (timerMilliseconds == nil) { BOOL updated = [self.activityHandler updateAttribution:attribution]; if (updated) { @@ -102,9 +103,9 @@ -(void) checkAttributionInternal:(NSDictionary *)jsonDict { [self.askInTimer cancel]; } - [self.logger debug:@"waiting to query attribution in %d milliseconds", [timer_milliseconds intValue]]; + [self.logger debug:@"waiting to query attribution in %d milliseconds", [timerMilliseconds intValue]]; - uint64_t timer_nano = [timer_milliseconds intValue] * NSEC_PER_MSEC; + uint64_t timer_nano = [timerMilliseconds intValue] * NSEC_PER_MSEC; self.askInTimer = [ADJTimer timerWithStart:timer_nano leeway:kTimerLeeway queue:self.internalQueue block:^{ [self getAttributionInternal]; }]; [self.askInTimer resume]; } From 9ab638f9d005b9e2ff14097450d93f0f991bb5b1 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Mon, 8 Dec 2014 11:10:33 +0100 Subject: [PATCH 72/86] Wrap lines in doc/migrate.md --- doc/migrate.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/migrate.md b/doc/migrate.md index 64485d2cd..76a17ce96 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -1,6 +1,8 @@ ## Migrate your adjust SDK for iOS to v4.0.0 from v3.4.0 -We changed the way to configure the SDK after launching. It should be done before with a new object `ADJConfig`. See an example of how it would look before and after the migration: +We changed the way to configure the SDK after launching. It should be done +before with a new object `ADJConfig`. See an example of how it would look +before and after the migration: ```objc // before migration @@ -42,7 +44,9 @@ ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironm } ``` -We also changed the way to track events and revenues. Now it is all configured with the `ADJEvent` object. You can follow another example of how an event/revenue would be tracked before and after the migration: +We also changed the way to track events and revenues. Now it is all configured +with the `ADJEvent` object. You can follow another example of how an +event/revenue would be tracked before and after the migration: ```objc // before the migration @@ -75,7 +79,10 @@ ADJEvent *revenue = [ADJEvent eventWithEventToken:@"xyz987"]; ## Additional steps if you come from v3.0.0 -We added an optional parameter `transactionId` to our `trackRevenue` methods. If you are tracking In-App Purchases you might want to pass in the transaction identifier provided by Apple to avoid duplicate revenue tracking. It should look roughly like this: +We added an optional parameter `transactionId` to our `trackRevenue` methods. +If you are tracking In-App Purchases you might want to pass in the transaction +identifier provided by Apple to avoid duplicate revenue tracking. It should +look roughly like this: ```objc - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { From 29906eb3f15033a20a13e16a143af33cbe9acea6 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Mon, 8 Dec 2014 11:52:08 +0100 Subject: [PATCH 73/86] Restructure doc/migrate.md --- doc/migrate.md | 84 ++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/doc/migrate.md b/doc/migrate.md index 76a17ce96..c5de21759 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -1,80 +1,82 @@ ## Migrate your adjust SDK for iOS to v4.0.0 from v3.4.0 -We changed the way to configure the SDK after launching. It should be done -before with a new object `ADJConfig`. See an example of how it would look -before and after the migration: +### Initial setup -```objc -// before migration - -// AppDelegate.h -#import "Adjust.h" -@interface AppDelegate : UIResponder +We changed how you configure the adjust SDK. All initial setup is now done with +a new config object. We also replaced the adjust prefix from `AI` to `ADJ`. +Here is an example of how the setup in `AppDelegate.m` might look before and +after the migration: -// AppDelegate.m +##### Before +```objc [Adjust appDidLaunch:@"{YourAppToken}"]; -[Adjust setLogLevel:AILogLevelInfo]; [Adjust setEnvironment:AIEnvironmentSandbox]; +[Adjust setLogLevel:AILogLevelInfo]; [Adjust setDelegate:self]; -// ... - (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData { - // ... } -// after migration - -// AppDelegate.h -#import "ADJConfig.h" -@interface AppDelegate : UIResponder +``` -// AppDelegate.m -#import "Adjust.h" +##### After +```objc NSString *yourAppToken = @"{YourAppToken}"; -NSString *enviroment = AIEnvironmentSandbox; +NSString *enviroment = ADJEnvironmentSandbox; ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; -[adjustConfig setLogLevel:ADJLogLevelVerbose]; +[adjustConfig setLogLevel:ADJLogLevelInfo]; [adjustConfig setDelegate:self]; [Adjust appDidLaunch:adjustConfig]; -// ... - (void)adjustAttributionChanged:(ADJAttribution *)attribution { - // ... } ``` -We also changed the way to track events and revenues. Now it is all configured -with the `ADJEvent` object. You can follow another example of how an -event/revenue would be tracked before and after the migration: +### Event tracking -```objc -// before the migration -#import "Adjust.h" +We also introduced proper event objects that can be set up before they get +tracked. Again, an example of how it might look like before and after: +##### Before + +```objc NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setObject:@"value" forKey:@"key"]; [parameters setObject:@"bar" forKey:@"foo"]; - [Adjust trackEvent:@"abc123" withParameters:parameters]; +``` -//[Adjust trackRevenue:1.0]; not possible in the version. You will have to create an app token -[Adjust trackRevenue:1.0 transactionId:transaction.transactionIdentifier forEvent:@"xyz987"]; - -// after the migration -#import "ADJEvent.h" -#import "Adjust.h" +##### After +```objc ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"]; [event addCallbackParameter:@"key" andValue:@"value"]; [event addCallbackParameter:@"foo" andValue:@"bar"]; [Adjust trackEvent:event]; +``` + +### Revenue tracking -ADJEvent *revenue = [ADJEvent eventWithEventToken:@"xyz987"]; -[revenue setRevenue:0.01 currency:@"EUR"]; // You have to include the currency -[revenue setTransactionId:transaction.transactionIdentifier]; -[Adjust trackEvent:revenue]; +Revenues are now handled like normal events. You just set a revenue and a +currency to track revenues. Note that it is not possible to track any revenue +without event token anymore. You might need to create an additional event token +in your dashboard. The optional transaction ID is now a property of the event +instance. +##### Before + +```objc +[Adjust trackRevenue:1.0 transactionId:transaction.transactionIdentifier forEvent:@"xyz987"]; +``` + +##### After + +```objc +ADJEvent *event = [ADJEvent eventWithEventToken:@"xyz987"]; +[event setRevenue:0.01 currency:@"EUR"]; // You have to include the currency +[event setTransactionId:transaction.transactionIdentifier]; +[Adjust trackEvent:event]; ``` ## Additional steps if you come from v3.0.0 From 6a760de697bcaa89a172daf7a091cd3318d1bbee Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 12:05:57 +0100 Subject: [PATCH 74/86] Rename andEnvironment --- Adjust/ADJActivityHandler.m | 2 +- Adjust/ADJConfig.h | 4 ++-- Adjust/ADJConfig.m | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 933c3a6e9..e5f850a2e 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -387,7 +387,7 @@ - (void) appWillOpenUrlInternal:(NSURL *)url { } } - if ([adjustDeepLinks count] <= 0) { + if ([adjustDeepLinks count] == 0) { return; } diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index b53f0364c..28d58ee46 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -43,8 +43,8 @@ * It is very important that you keep this value meaningful at all times! * Especially if you are tracking revenue. */ -+ (ADJConfig*)configWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; -- (id)initWithAppToken:(NSString *)appToken andEnvironment:(NSString *)environment; ++ (ADJConfig*)configWithAppToken:(NSString *)appToken environment:(NSString *)environment; +- (id)initWithAppToken:(NSString *)appToken environment:(NSString *)environment; /** * Enable event buffering if your app triggers a lot of events. diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index 57fd20818..d9f80c9e8 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -13,12 +13,12 @@ @implementation ADJConfig + (ADJConfig *) configWithAppToken:(NSString *)appToken - andEnvironment:(NSString *)environment { - return [[ADJConfig alloc] initWithAppToken:appToken andEnvironment:environment]; + environment:(NSString *)environment { + return [[ADJConfig alloc] initWithAppToken:appToken environment:environment]; } - (id) initWithAppToken:(NSString *)appToken - andEnvironment:(NSString *)environment + environment:(NSString *)environment { self = [super init]; if (self == nil) return nil; From 5b8c4932f3d84c9d677fb10dfd4970ee6dc72449 Mon Sep 17 00:00:00 2001 From: Simon Kendall Date: Mon, 8 Dec 2014 13:29:46 +0100 Subject: [PATCH 75/86] Update readme --- README.md | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 530ca9902..d89df47ad 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ archive into a directory of your choice. ### 2. Add it to your project 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 +group of your choice). From Finder, drag the `Adjust` subdirectory into Xcode's `Supporting Files` group. ![][drag] @@ -41,8 +41,8 @@ groups`. ### 3. Add the AdSupport and iAd framework -In the Project Navigator select your project. In the left hand side of the main -view select your target. In the tab `Build Phases` expand the group `Link +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. Repeat the same steps to add the `iAd.framework`. Change the `Status` of both frameworks to @@ -52,14 +52,14 @@ steps to add the `iAd.framework`. Change the `Status` of both frameworks to ### 4. Integrate Adjust into your app -At first we set up basic session tracking. +To start with, we'll set up basic session tracking. #### Basic Setup -In the Project Navigator open the source file your application delegate. Add -the `import` statement at the top of the file. In the `didFinishLaunching` or -`didFinishLaunchingWithOptions` method of your app delegate add the following -call to `Adjust`: +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: ```objc #import "Adjust.h" @@ -72,10 +72,10 @@ ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken ``` ![][delegate] -Replace `{YourAppToken}` with your app token. You can find in your [dashboard]. +Replace `{YourAppToken}` with your app token. You can find this in your [dashboard]. -Depending on whether you build your app for testing or for production you must -set `enviroment` with one of these values: +Depending on whether you build your app for testing or for production, you must +set `environment` with one of these values: ```objc NSString *enviroment = ADJEnvironmentSandbox; @@ -89,7 +89,7 @@ if you or someone else is testing your app. Make sure to set the environment to 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! Especially if you are tracking revenue. +all times! This is especially important if you are tracking revenue. #### Adjust Logging @@ -127,15 +127,15 @@ and press the `Return` key to change all at once). ## Additional features -Once you integrated the adjust SDK into your project, you can take advantage of +Once you integrate the adjust SDK into your project, you can take advantage of the following features. ### 6. Set up 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]. It -might look like this: `abc123`. In your button's `buttonDown` method you would -then add the following lines to track the tap: +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: ```objc ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"]; @@ -176,6 +176,9 @@ device. Also note that we don't store any of your custom parameters, but only append them to your callbacks. If you haven't registered a callback for an event, these parameters won't even be read. +You can read more about using URL callbacks, including a full list of available +values, in our [callbacks guide][callbacks-guide]. + #### Track revenue If your users can generate revenue by tapping on advertisements or making @@ -194,10 +197,10 @@ This can be combined with callback parameters of course. You can also pass in an optional transaction ID to avoid tracking duplicate revenues. The last ten transaction IDs are remembered and revenue events with -duplicate transaction IDs are skipped. This is especially useful for In-App -Purchase tracking. See an example below. +duplicate transaction IDs are skipped. This is especially useful for in-app +purchase tracking. See an example below. -If you want to track In-App Purchases, please make sure to call `trackEvent` +If you want to track in-app purchases, please make sure to call `trackEvent` after `finishTransaction` in `paymentQueue:updatedTransaction` only if the state changed to `SKPaymentTransactionStatePurchased`. That way you can avoid tracking revenue that is not actually being generated. @@ -321,6 +324,7 @@ You can check if the adjust SDK is currently enabled by calling the function [run]: https://raw.github.com/adjust/sdks/master/Resources/ios/run4.png [AEPriceMatrix]: https://github.com/adjust/AEPriceMatrix [attribution-data]: https://github.com/adjust/sdks/blob/master/doc/attribution-data.md +[callbacks-guide]: https://docs.adjust.com/en/callbacks ## License From 59346a1d5e109b78715c82b49af167ef1347c81d Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Mon, 8 Dec 2014 15:03:17 +0100 Subject: [PATCH 76/86] Fix typo enviroment -> environment --- README.md | 8 ++++---- doc/migrate.md | 4 ++-- example/example/AppDelegate.m | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d89df47ad..8aa037880 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,9 @@ delegate: #import "Adjust.h" // ... NSString *yourAppToken = @"{YourAppToken}"; -NSString *enviroment = ADJEnvironmentSandbox; +NSString *environment = ADJEnvironmentSandbox; ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken - andEnvironment:enviroment]; + andEnvironment:environment]; [Adjust appDidLaunch:adjustConfig]; ``` ![][delegate] @@ -78,8 +78,8 @@ Depending on whether you build your app for testing or for production, you must set `environment` with one of these values: ```objc -NSString *enviroment = ADJEnvironmentSandbox; -NSString *enviroment = ADJEnvironmentProduction; +NSString *environment = ADJEnvironmentSandbox; +NSString *environment = ADJEnvironmentProduction; ``` **Important:** This value should be set to `ADJEnvironmentSandbox` if and only diff --git a/doc/migrate.md b/doc/migrate.md index c5de21759..68343f323 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -23,8 +23,8 @@ after the migration: ```objc NSString *yourAppToken = @"{YourAppToken}"; -NSString *enviroment = ADJEnvironmentSandbox; -ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; +NSString *environment = ADJEnvironmentSandbox; +ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:environment]; [adjustConfig setLogLevel:ADJLogLevelInfo]; [adjustConfig setDelegate:self]; [Adjust appDidLaunch:adjustConfig]; diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m index 7b8a77e2a..f89f581b5 100644 --- a/example/example/AppDelegate.m +++ b/example/example/AppDelegate.m @@ -20,8 +20,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // configure adjust NSString *yourAppToken = @"{YourAppToken}"; - NSString *enviroment = ADJEnvironmentSandbox; - ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:enviroment]; + NSString *environment = ADJEnvironmentSandbox; + ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:environment]; // change the log level [adjustConfig setLogLevel:ADJLogLevelVerbose]; From 1f47159601cd5c776b6bcf0679f65fec669c955a Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Mon, 8 Dec 2014 15:11:18 +0100 Subject: [PATCH 77/86] Update documentation setEnvironment -> environment --- README.md | 2 +- doc/migrate.md | 3 ++- example/example/AppDelegate.m | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8aa037880..6b49ec45b 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ delegate: NSString *yourAppToken = @"{YourAppToken}"; NSString *environment = ADJEnvironmentSandbox; ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken - andEnvironment:environment]; + environment:environment]; [Adjust appDidLaunch:adjustConfig]; ``` ![][delegate] diff --git a/doc/migrate.md b/doc/migrate.md index 68343f323..1a6ca6fc9 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -24,7 +24,8 @@ after the migration: ```objc NSString *yourAppToken = @"{YourAppToken}"; NSString *environment = ADJEnvironmentSandbox; -ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:environment]; +ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken + environment:environment]; [adjustConfig setLogLevel:ADJLogLevelInfo]; [adjustConfig setDelegate:self]; [Adjust appDidLaunch:adjustConfig]; diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m index f89f581b5..d81a10a98 100644 --- a/example/example/AppDelegate.m +++ b/example/example/AppDelegate.m @@ -21,7 +21,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // configure adjust NSString *yourAppToken = @"{YourAppToken}"; NSString *environment = ADJEnvironmentSandbox; - ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken andEnvironment:environment]; + ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken environment:environment]; // change the log level [adjustConfig setLogLevel:ADJLogLevelVerbose]; From f66ccbdd5fb4631a0c678f0a37f8f0e52c0fc335 Mon Sep 17 00:00:00 2001 From: Christian Wellenbrock Date: Mon, 8 Dec 2014 15:13:14 +0100 Subject: [PATCH 78/86] Reformat documentation --- README.md | 20 +++++++++++--------- doc/migrate.md | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6b49ec45b..a93544806 100644 --- a/README.md +++ b/README.md @@ -56,10 +56,10 @@ To start with, we'll set up basic session tracking. #### 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: +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: ```objc #import "Adjust.h" @@ -72,7 +72,8 @@ ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken ``` ![][delegate] -Replace `{YourAppToken}` with your app token. You can find this in your [dashboard]. +Replace `{YourAppToken}` with your app token. You can find this in your +[dashboard]. Depending on whether you build your app for testing or for production, you must set `environment` with one of these values: @@ -133,9 +134,10 @@ the following features. ### 6. Set up 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: +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: ```objc ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"]; @@ -176,7 +178,7 @@ device. Also note that we don't store any of your custom parameters, but only append them to your callbacks. If you haven't registered a callback for an event, these parameters won't even be read. -You can read more about using URL callbacks, including a full list of available +You can read more about using URL callbacks, including a full list of available values, in our [callbacks guide][callbacks-guide]. #### Track revenue diff --git a/doc/migrate.md b/doc/migrate.md index 1a6ca6fc9..a93dfb542 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -113,6 +113,7 @@ all adjust SDK calls. 1. Right click on the old `AdjustIo` source folder and select `Delete`. Confirm `Move to Trash`. + 2. From the Xcode menu select `Find → Find and Replace in Project...` to bring up the project wide search and replace. Enter `AdjustIo` into the search field and `Adjust` into the replace field. Press enter to start the search. @@ -131,7 +132,6 @@ all adjust SDK calls. The adjust SDK v3.4.0 added delegate callbacks. Check out the [README] for details. - ## Additional steps if you come from v2.0.x In the Project Navigator open the source file your Application Delegate. Add From dbe75b14b5609f82aabd941db956210ab83bdfa5 Mon Sep 17 00:00:00 2001 From: Simon Kendall Date: Mon, 8 Dec 2014 15:53:10 +0100 Subject: [PATCH 79/86] Update migration guide --- doc/migrate.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/migrate.md b/doc/migrate.md index a93dfb542..c69eba3aa 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -36,7 +36,7 @@ ADJConfig *adjustConfig = [ADJConfig configWithAppToken:yourAppToken ### Event tracking -We also introduced proper event objects that can be set up before they get +We also introduced proper event objects that can be set up before they are tracked. Again, an example of how it might look like before and after: ##### Before @@ -60,8 +60,8 @@ ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"]; ### Revenue tracking Revenues are now handled like normal events. You just set a revenue and a -currency to track revenues. Note that it is not possible to track any revenue -without event token anymore. You might need to create an additional event token +currency to track revenues. Note that it is no longer possible to track revenues +without associated event tokens. You might need to create an additional event token in your dashboard. The optional transaction ID is now a property of the event instance. From ca3e43964ec4ab4abdcb1e4d8e3a1e21566f8a18 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 16:17:17 +0100 Subject: [PATCH 80/86] Has attribution delegate --- Adjust/ADJActivityHandler.m | 1 + Adjust/ADJConfig.h | 1 + Adjust/ADJConfig.m | 10 ++++++++++ Adjust/ADJPackageBuilder.h | 1 - Adjust/ADJPackageBuilder.m | 10 ++-------- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index e5f850a2e..602d77fa5 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -183,6 +183,7 @@ - (BOOL)updateAttribution:(ADJAttribution *)attribution { - (void)launchAttributionDelegate{ if (![self.delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { + [self.logger warn:@"Delegate can't be launched because it does not implement AdjustDelegate"]; return; } [self.delegate performSelectorOnMainThread:@selector(adjustAttributionChanged:) diff --git a/Adjust/ADJConfig.h b/Adjust/ADJConfig.h index 28d58ee46..4d37c8fac 100644 --- a/Adjust/ADJConfig.h +++ b/Adjust/ADJConfig.h @@ -72,5 +72,6 @@ * methods like adjustAttributionChanged: */ @property (nonatomic, retain) NSObject *delegate; +@property (nonatomic, assign) BOOL hasDelegate; @end diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index d9f80c9e8..326e8899e 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -36,6 +36,15 @@ - (id) initWithAppToken:(NSString *)appToken return self; } +- (void) setDelegate:(NSObject *)delegate { + _delegate = delegate; + if (![delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { + id logger = ADJAdjustFactory.logger; + [logger warn:@"Delegate configured does not implement AdjustDelegate"]; + } + self.hasDelegate = (delegate != nil); +} + - (BOOL) checkEnvironment:(NSString *)environment { id logger = ADJAdjustFactory.logger; @@ -68,6 +77,7 @@ -(id)copyWithZone:(NSZone *)zone copy.sdkPrefix = [self.environment copyWithZone:zone]; copy.eventBufferingEnabled = self.eventBufferingEnabled; copy.macMd5TrackingEnabled = self.macMd5TrackingEnabled; + copy.hasDelegate = self.hasDelegate; // adjust delegate not copied } diff --git a/Adjust/ADJPackageBuilder.h b/Adjust/ADJPackageBuilder.h index e4ed9a188..1be2d75cd 100644 --- a/Adjust/ADJPackageBuilder.h +++ b/Adjust/ADJPackageBuilder.h @@ -17,7 +17,6 @@ @property (nonatomic, copy) ADJDeviceInfo* deviceInfo; @property (nonatomic, copy) ADJActivityState *activityState; @property (nonatomic, copy) ADJConfig *adjustConfig; -@property (nonatomic, assign) BOOL hasDelegate; @property (nonatomic, copy) ADJAttribution *attribution; @property (nonatomic, copy) NSDate *clickTime; @property (nonatomic, copy) NSDate *purchaseTime; diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 4334d4764..725fc1dbb 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -25,12 +25,6 @@ - (id)initWithDeviceInfo:(ADJDeviceInfo *)deviceInfo self.activityState = activityState; self.adjustConfig = adjustConfig; - if (adjustConfig.delegate != nil) { - self.hasDelegate = YES; - } else { - self.hasDelegate = NO; - } - return self; } @@ -99,7 +93,7 @@ - (ADJActivityPackage *)buildAttributionPackage { [self parameters:parameters setString:self.adjustConfig.appToken forKey:@"app_token"]; [self parameters:parameters setString:self.adjustConfig.environment forKey:@"environment"]; [self parameters:parameters setString:self.activityState.uuid forKey:@"ios_uuid"]; - [self parameters:parameters setBool:self.hasDelegate forKey:@"needs_attribution_data"]; + [self parameters:parameters setBool:self.adjustConfig.hasDelegate forKey:@"needs_attribution_data"]; ADJActivityPackage *attributionPackage = [self defaultActivityPackage]; attributionPackage.path = @"/attribution"; @@ -120,7 +114,7 @@ - (NSMutableDictionary *)defaultParameters { [self injectDeviceInfo:self.deviceInfo andConfig:self.adjustConfig intoParameters:parameters]; [self injectActivityState:self.activityState intoParamters:parameters]; - [self parameters:parameters setBool:self.hasDelegate forKey:@"needs_attribution_data"]; + [self parameters:parameters setBool:self.adjustConfig.hasDelegate forKey:@"needs_attribution_data"]; return parameters; } From d519262555da46b6cf15e090013e49c396cdd9d7 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 16:18:27 +0100 Subject: [PATCH 81/86] Logging null messages --- Adjust/ADJActivityPackage.m | 2 +- Adjust/ADJAttributionHandler.m | 2 +- Adjust/ADJRequestHandler.m | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJActivityPackage.m b/Adjust/ADJActivityPackage.m index db2a9257f..0b7aaf9eb 100644 --- a/Adjust/ADJActivityPackage.m +++ b/Adjust/ADJActivityPackage.m @@ -27,7 +27,7 @@ - (NSString *)extendedString { [builder appendFormat:@"Parameters:"]; for (NSString *key in self.parameters) { NSString *value = [self.parameters objectForKey:key]; - [builder appendFormat:@"\n\t\t%-16s %@", [key UTF8String], value]; + [builder appendFormat:@"\n\t\t%-22s %@", [key UTF8String], value]; } } diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 91f84ea98..9e18e5666 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -144,7 +144,7 @@ -(void) getAttributionInternal { NSString* messageResponse = [jsonDict objectForKey:@"message"]; if (statusCode == 200) { - [self.logger debug:@"%@", messageResponse]; + [self.logger debug:@"Received attribution data with message: %@", messageResponse]; } else { [self.logger error:@"%@", messageResponse]; } diff --git a/Adjust/ADJRequestHandler.m b/Adjust/ADJRequestHandler.m index 3e931e419..f25ebb17d 100644 --- a/Adjust/ADJRequestHandler.m +++ b/Adjust/ADJRequestHandler.m @@ -99,6 +99,10 @@ - (void)sendInternal:(ADJActivityPackage *)package sendToPackageHandler:(BOOL)se NSString* messageResponse = [jsonDict objectForKey:@"message"]; + if (messageResponse == nil) { + messageResponse = @"No message found"; + } + if (statusCode == 200) { [self.logger info:@"%@", messageResponse]; } else { From 639f970be092d0f7861259769edc5063849fd8bd Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 17:17:32 +0100 Subject: [PATCH 82/86] Should get attribution --- Adjust/ADJActivityHandler.m | 6 +++++- Adjust/ADJAttributionHandler.h | 2 -- Adjust/ADJAttributionHandler.m | 4 ---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 602d77fa5..2d5282df2 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -42,6 +42,7 @@ @interface ADJActivityHandler() @property (nonatomic, assign) BOOL enabled; @property (nonatomic, assign) BOOL offline; +@property (nonatomic, assign) BOOL shouldGetAttribution; @property (nonatomic, copy) ADJDeviceInfo* deviceInfo; @@ -237,6 +238,8 @@ - (void)initInternal:(ADJConfig *)adjustConfig { self.attributionHandler = [self buildAttributionHandler]; + self.shouldGetAttribution = YES; + [self readAttribution]; [self startInternal]; @@ -314,7 +317,7 @@ - (void)startInternal { } if (self.attribution == nil || self.activityState.askingAttribution) { - if (![self.attributionHandler isWaitingInAskIn]) { + if (self.shouldGetAttribution) { [self.attributionHandler getAttribution]; } } @@ -493,6 +496,7 @@ - (void)transferSessionPackage { ADJActivityPackage *sessionPackage = [sessionBuilder buildSessionPackage]; [self.packageHandler addPackage:sessionPackage]; [self.packageHandler sendFirstPackage]; + self.shouldGetAttribution = NO; } # pragma mark - timer diff --git a/Adjust/ADJAttributionHandler.h b/Adjust/ADJAttributionHandler.h index 6776c994e..a93272b97 100644 --- a/Adjust/ADJAttributionHandler.h +++ b/Adjust/ADJAttributionHandler.h @@ -20,8 +20,6 @@ - (void)getAttribution; -- (BOOL)isWaitingInAskIn; - @end @interface ADJAttributionHandler : NSObject diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 9e18e5666..5aeb9d4a7 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -73,10 +73,6 @@ - (void) getAttribution { }); } -- (BOOL) isWaitingInAskIn { - return self.askInTimer != nil; -} - #pragma mark - internal -(void) checkAttributionInternal:(NSDictionary *)jsonDict { if (jsonDict == nil || jsonDict == (id)[NSNull null]) return; From 3a93933d6bbcf3524d38294b05c7acf840e75d89 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 17:18:01 +0100 Subject: [PATCH 83/86] Renaming AIEnv --- Adjust/ADJActivityHandler.m | 2 +- Adjust/ADJConfig.m | 4 ++-- Adjust/ADJPackageBuilder.m | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 2d5282df2..ba5d06cc5 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -66,7 +66,7 @@ - (id)initWithConfig:(ADJConfig *)adjustConfig { return nil; } - self.logger = ADJAdjustFactory.logger; + self.logger = ADJAdjustFactory.logger; [self addNotificationObserver]; self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL); _enabled = YES; diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index 326e8899e..71d5b9e51 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -49,10 +49,10 @@ - (BOOL) checkEnvironment:(NSString *)environment { id logger = ADJAdjustFactory.logger; if ([environment isEqualToString:ADJEnvironmentSandbox]) { - [logger assert:@"SANDBOX: Adjust will run in Sandbox mode. Use this setting for testing. Don't forget to set the environment to AIEnvironmentProduction before publishing!"]; + [logger assert:@"SANDBOX: Adjust will run in Sandbox mode. Use this setting for testing. Don't forget to set the environment to ADJEnvironmentProduction before publishing!"]; return YES; } else if ([environment isEqualToString:ADJEnvironmentProduction]) { - [logger assert:@"PRODUCTION: Adjust will run in Production mode. Use this setting only for the build that you want to publish. Set the environment to AIEnvironmentSandbox if you want to test your app!"]; + [logger assert:@"PRODUCTION: Adjust will run in Production mode. Use this setting only for the build that you want to publish. Set the environment to ADJEnvironmentSandbox if you want to test your app!"]; return YES; } [logger error:@"Malformed environment '%@'", environment]; diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index 725fc1dbb..c19c9c3ca 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -33,7 +33,7 @@ - (ADJActivityPackage *)buildSessionPackage { [self parameters:parameters setDuration:self.activityState.lastInterval forKey:@"last_interval"]; ADJActivityPackage *sessionPackage = [self defaultActivityPackage]; - sessionPackage.path = @"/startup"; + sessionPackage.path = @"/session"; sessionPackage.activityKind = ADJActivityKindSession; sessionPackage.suffix = @""; sessionPackage.parameters = parameters; From 78ebb58f1169ae48b8a19ea0f4683fe2cbcaf0b0 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 17:18:24 +0100 Subject: [PATCH 84/86] Log sent at --- Adjust/ADJUtil.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index 90517e06c..86fcca39c 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -11,6 +11,7 @@ #import "UIDevice+ADJAdditions.h" #import "ADJAdjustFactory.h" #import "NSString+ADJAdditions.h" +#import "ADJAdjustFactory.h" #include @@ -158,6 +159,9 @@ + (NSString *) queryString:(NSDictionary *)parameters { NSString *dateString = [ADJUtil formatSeconds1970:now]; NSString *escapedDate = [dateString adjUrlEncode]; NSString *sentAtPair = [NSString stringWithFormat:@"%@=%@", @"sent_at", escapedDate]; + id logger = [ADJAdjustFactory logger]; + [logger debug:@"sent_at: %@", dateString]; + [pairs addObject:sentAtPair]; NSString *queryString = [pairs componentsJoinedByString:@"&"]; From fdd06dd72380d701435e12638271c42ea9778442 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 17:39:23 +0100 Subject: [PATCH 85/86] Log attribution message --- Adjust/ADJAttributionHandler.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Adjust/ADJAttributionHandler.m b/Adjust/ADJAttributionHandler.m index 5aeb9d4a7..4fbfb7420 100644 --- a/Adjust/ADJAttributionHandler.m +++ b/Adjust/ADJAttributionHandler.m @@ -139,8 +139,12 @@ -(void) getAttributionInternal { NSString* messageResponse = [jsonDict objectForKey:@"message"]; + if (messageResponse == nil) { + messageResponse = @"No message found"; + } + if (statusCode == 200) { - [self.logger debug:@"Received attribution data with message: %@", messageResponse]; + [self.logger debug:@"%@", messageResponse]; } else { [self.logger error:@"%@", messageResponse]; } From 614bee4cc847f8679f72a46aa42e23a3ac67633a Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 8 Dec 2014 17:39:44 +0100 Subject: [PATCH 86/86] Delegate check before save --- Adjust/ADJConfig.m | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Adjust/ADJConfig.m b/Adjust/ADJConfig.m index 71d5b9e51..84b17d1f2 100644 --- a/Adjust/ADJConfig.m +++ b/Adjust/ADJConfig.m @@ -37,12 +37,23 @@ - (id) initWithAppToken:(NSString *)appToken } - (void) setDelegate:(NSObject *)delegate { - _delegate = delegate; + if (delegate == nil) { + _delegate = nil; + self.hasDelegate = NO; + return; + } + if (![delegate respondsToSelector:@selector(adjustAttributionChanged:)]) { id logger = ADJAdjustFactory.logger; - [logger warn:@"Delegate configured does not implement AdjustDelegate"]; + [logger error:@"Delegate does not implement AdjustDelegate"]; + + _delegate = nil; + self.hasDelegate = NO; + return; } - self.hasDelegate = (delegate != nil); + + _delegate = delegate; + self.hasDelegate = YES; } - (BOOL) checkEnvironment:(NSString *)environment