Skip to content

Commit

Permalink
Merge pull request #17 from adeven/development
Browse files Browse the repository at this point in the history
Version 2.1.0
  • Loading branch information
wellle committed Sep 16, 2013
2 parents a9fc1a4 + a56f129 commit b3b8e53
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 54 deletions.
4 changes: 2 additions & 2 deletions AdjustIO.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "AdjustIO"
s.version = "2.0.1"
s.version = "2.1.0"
s.summary = "This is the iOS SDK of AdjustIo. You can read more about it at http://adjust.io."
s.homepage = "http://adjust.io"
s.license = { :type => 'MIT', :file => 'MIT-LICENSE' }
s.author = { "Christian Wellenbrock" => "welle@adeven.com" }
s.source = { :git => "https://github.com/adeven/adjust_ios_sdk.git", :tag => "v2.0.1" }
s.source = { :git => "https://github.com/adeven/adjust_ios_sdk.git", :tag => "v2.1.0" }
s.platform = :ios, '4.3'
s.framework = 'AdSupport', 'SystemConfiguration'
s.source_files = 'AdjustIo/*.{h,m}', 'AdjustIo/AIAdditions/*.{h,m}'
Expand Down
5 changes: 5 additions & 0 deletions AdjustIo/AIActivityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
// Copyright (c) 2013 adeven. All rights reserved.
//

#import "AdjustIo.h"

@interface AIActivityHandler : NSObject

@property (nonatomic, copy) NSString *environment;
@property (nonatomic, assign) BOOL bufferEvents;

+ (AIActivityHandler *)handlerWithAppToken:(NSString *)appToken;
- (id)initWithAppToken:(NSString *)appToken;

Expand Down
37 changes: 28 additions & 9 deletions AdjustIo/AIActivityHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright (c) 2013 adeven. All rights reserved.
//

#import "AIActivityPackage.h"
#import "AIActivityHandler.h"
#import "AIActivityState.h"
#import "AIPackageBuilder.h"
Expand Down Expand Up @@ -40,6 +41,7 @@ @interface AIActivityHandler()
@property (nonatomic, copy) NSString *fbAttributionId;
@property (nonatomic, copy) NSString *userAgent;
@property (nonatomic, copy) NSString *clientSdk;
@property (nonatomic, assign) BOOL trackingEnabled;

@end

Expand All @@ -57,6 +59,7 @@ - (id)initWithAppToken:(NSString *)yourAppToken {

[self addNotificationObserver];
self.internalQueue = dispatch_queue_create(kInternalQueueName, DISPATCH_QUEUE_SERIAL);
self.environment = @"unknown"; // default value

dispatch_async(self.internalQueue, ^{
[self initInternal:yourAppToken];
Expand Down Expand Up @@ -105,6 +108,7 @@ - (void)initInternal:(NSString *)yourAppToken {
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;
Expand Down Expand Up @@ -201,6 +205,12 @@ - (void)eventInternal:(NSString *)eventToken
AIActivityPackage *eventPackage = [eventBuilder buildEventPackage];
[self.packageHandler addPackage:eventPackage];

if (self.bufferEvents) {
[AILogger info:@"Buffered event%@", eventPackage.suffix];
} else {
[self.packageHandler sendFirstPackage];
}

[self writeActivityState];
[AILogger debug:@"Event %d", self.activityState.eventCount];
}
Expand Down Expand Up @@ -229,6 +239,12 @@ - (void)revenueInternal:(double)amount
AIActivityPackage *revenuePackage = [revenueBuilder buildRevenuePackage];
[self.packageHandler addPackage:revenuePackage];

if (self.bufferEvents) {
[AILogger info:@"Buffered revenue%@", revenuePackage.suffix];
} else {
[self.packageHandler sendFirstPackage];
}

[self writeActivityState];
[AILogger debug:@"Event %d (revenue)", self.activityState.eventCount];
}
Expand Down Expand Up @@ -302,25 +318,28 @@ - (void)transferSessionPackage {
[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;
builder.appToken = self.appToken;
builder.macShortMd5 = self.macShortMd5;
builder.macSha1 = self.macSha1;
builder.userAgent = self.userAgent;
builder.clientSdk = self.clientSdk;
builder.appToken = self.appToken;
builder.macShortMd5 = self.macShortMd5;
builder.macSha1 = self.macSha1;
builder.trackingEnabled = self.trackingEnabled;
builder.idForAdvertisers = self.idForAdvertisers;
builder.fbAttributionId = self.fbAttributionId;
builder.fbAttributionId = self.fbAttributionId;
builder.environment = self.environment;
}

# pragma mark - timer
- (void)startTimer {
if (self.timer == nil) {
self.timer = [AITimer timerWithInterval:kTimerInterval
leeway:kTimerLeeway
queue:self.internalQueue
block:^{ [self timerFired]; }];
leeway:kTimerLeeway
queue:self.internalQueue
block:^{ [self timerFired]; }];
}
[self.timer resume];
}
Expand Down
2 changes: 1 addition & 1 deletion AdjustIo/AIAdditions/NSData+AIAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 01.10.12.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

#import <Foundation/Foundation.h>
Expand Down
2 changes: 1 addition & 1 deletion AdjustIo/AIAdditions/NSData+AIAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 01.10.12.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

#import "NSData+AIAdditions.h"
Expand Down
2 changes: 1 addition & 1 deletion AdjustIo/AIAdditions/NSString+AIAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 23.07.12.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

#import <Foundation/Foundation.h>
Expand Down
2 changes: 1 addition & 1 deletion AdjustIo/AIAdditions/NSString+AIAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 23.07.12.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

#import "NSString+AIAdditions.h"
Expand Down
3 changes: 2 additions & 1 deletion AdjustIo/AIAdditions/UIDevice+AIAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 23.07.12.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface UIDevice(AIAdditions)

- (BOOL)aiTrackingEnabled;
- (NSString *)aiIdForAdvertisers;
- (NSString *)aiFbAttributionId;
- (NSString *)aiMacAddress;
Expand Down
10 changes: 9 additions & 1 deletion AdjustIo/AIAdditions/UIDevice+AIAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 23.07.12.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

#import "UIDevice+AIAdditions.h"
Expand All @@ -17,6 +17,14 @@

@implementation UIDevice(AIAdditions)

- (BOOL)aiTrackingEnabled {
if (NSClassFromString(@"ASIdentifierManager")) {
return ASIdentifierManager.sharedManager.advertisingTrackingEnabled;
} else {
return NO;
}
}

- (NSString *)aiIdForAdvertisers {
if (NSClassFromString(@"ASIdentifierManager")) {
return ASIdentifierManager.sharedManager.advertisingIdentifier.UUIDString;
Expand Down
4 changes: 3 additions & 1 deletion AdjustIo/AILogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 2012-11-15.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

typedef enum {
Expand All @@ -29,6 +29,7 @@ typedef enum {
+ (void)info: (NSString *)message, ...;
+ (void)warn: (NSString *)message, ...;
+ (void)error: (NSString *)message, ...;
+ (void)assert: (NSString *)message, ...;

+ (AILogger *)loggerWithTag:(NSString *)logTag;
- (id)initWithTag:(NSString *)logTag;
Expand All @@ -38,5 +39,6 @@ typedef enum {
- (void)info: (NSString *)message, ...;
- (void)warn: (NSString *)message, ...;
- (void)error: (NSString *)message, ...;
- (void)assert: (NSString *)message, ...;

@end
14 changes: 13 additions & 1 deletion AdjustIo/AILogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 2012-11-15.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

#import "AILogger.h"
Expand Down Expand Up @@ -66,6 +66,12 @@ - (void)error:(NSString *)format, ... {
[self logLevel:@"e" format:format parameters:parameters];
}

- (void)assert: (NSString *)format, ... {
if (self.logLevel > AILogLevelAssert) return;
va_list parameters; va_start(parameters, format);
[self logLevel:@"a" format:format parameters:parameters];
}

+ (void)verbose:(NSString *)format, ... {
if (AILogger.getDefaultLogger.logLevel > AILogLevelVerbose) return;
va_list parameters; va_start(parameters, format);
Expand Down Expand Up @@ -96,6 +102,12 @@ + (void)error:(NSString *)format, ... {
[AILogger.getDefaultLogger logLevel:@"e" format:format parameters:parameters];
}

+ (void)assert:(NSString *)format, ... {
if (AILogger.getDefaultLogger.logLevel > AILogLevelAssert) return;
va_list parameters; va_start(parameters, format);
[AILogger.getDefaultLogger logLevel:@"e" format:format parameters:parameters];
}

- (void)logLevel:(NSString *)logLevel format:(NSString *)format parameters:(va_list) parameters {
NSString *string = [[NSString alloc] initWithFormat:format arguments:parameters];
va_end(parameters);
Expand Down
2 changes: 2 additions & 0 deletions AdjustIo/AIPackageBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
@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, assign) BOOL trackingEnabled;

// sessions
@property (nonatomic, assign) int sessionCount;
Expand Down
2 changes: 2 additions & 0 deletions AdjustIo/AIPackageBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ - (NSMutableDictionary *)defaultParameters {
[self parameters:parameters setString:self.macShortMd5 forKey:@"mac_md5"];
[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"];

// session related (used for events as well)
[self parameters:parameters setInt:self.sessionCount forKey:@"session_count"];
Expand Down
1 change: 0 additions & 1 deletion AdjustIo/AIPackageHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ - (void)addInternal:(AIActivityPackage *)newPackage {
[AILogger verbose:@"%@", newPackage.extendedString];

[self writePackageQueue];
[self sendFirstInternal];
}

- (void)sendFirstInternal {
Expand Down
2 changes: 1 addition & 1 deletion AdjustIo/AIUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "UIDevice+AIAdditions.h"

static NSString * const kBaseUrl = @"https://app.adjust.io";
static NSString * const kClientSdk = @"ios2.0.1";
static NSString * const kClientSdk = @"ios2.1.0";


#pragma mark -
Expand Down
15 changes: 14 additions & 1 deletion AdjustIo/AdjustIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 2012-07-23.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

#import "AILogger.h"

// TODO: add comment
static NSString * const AIEnvironmentSandbox = @"sandbox";
static NSString * const AIEnvironmentProduction = @"production";

/**
* The main interface to AdjustIo.
*
Expand Down Expand Up @@ -61,6 +65,15 @@
+ (void)trackRevenue:(double)amountInCents forEvent:(NSString *)eventToken;
+ (void)trackRevenue:(double)amountInCents forEvent:(NSString *)eventToken withParameters:(NSDictionary *)parameters;

// TODO: add comment
// sets logLevel to Assert
// should be called after appDidLaunch and setLogLevel
+ (void)setEnvironment:(NSString *)environment;

// TODO: add comment
// should be called after appDidLaunch
+ (void)setEventBufferingEnabled:(BOOL)enabled;

/**
* Change the verbosity of AdjustIo's logs.
*
Expand Down
28 changes: 27 additions & 1 deletion AdjustIo/AdjustIo.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// AdjustIo
//
// Created by Christian Wellenbrock on 2012-07-23.
// Copyright (c) 2012 adeven. All rights reserved.
// Copyright (c) 2012-2013 adeven. All rights reserved.
//

#import "AdjustIo.h"
Expand Down Expand Up @@ -47,6 +47,32 @@ + (void)trackRevenue:(double)amountInCents
[activityHandler trackRevenue:amountInCents forEvent:eventToken withParameters:parameters];
}

+ (void)setEnvironment:(NSString *)environment {
if (activityHandler == nil) {
[AILogger error:@"Please call `setEnvironment` after `appDidLaunch`!"];
} else if ([environment isEqualToString:AIEnvironmentSandbox]) {
activityHandler.environment = environment;
[AILogger assert:@"SANDBOX: AdjustIo 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;
[AILogger assert:@"PRODUCTION: AdjustIo 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!"];
[AILogger setLogLevel:AILogLevelAssert];
} else {
activityHandler.environment = @"malformed";
[AILogger error:@"Malformed environment '%@'", environment];
}
}

+ (void)setEventBufferingEnabled:(BOOL)enabled {
if (activityHandler == nil) {
[AILogger error:@"Please call `setEventBufferingEnabled` after `appDidLaunch`!"];
return;
}

activityHandler.bufferEvents = enabled;
if (enabled) [AILogger info:@"Event buffering is enabled"];
}

+ (void)setLogLevel:(AILogLevel)logLevel {
[AILogger setLogLevel:logLevel];
}
Expand Down
4 changes: 2 additions & 2 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012 adeven GmbH,
Copyright (c) 2012-2013 adeven GmbH,
http://www.adeven.com

Permission is hereby granted, free of charge, to any person obtaining
Expand All @@ -18,4 +18,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit b3b8e53

Please sign in to comment.