Skip to content

Commit

Permalink
Merge pull request #26 from adjust/scripts
Browse files Browse the repository at this point in the history
Fix scripts
  • Loading branch information
nonelse committed Oct 14, 2014
2 parents 5fa65ad + d36ad7a commit 927b8de
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,6 @@ Thumbs.db
*.pyc*
AndroidManifest.xml*
MetroTestCertificate.pfx*
src/
src.meta
ProjectSettings/
Binary file added Adjust_v3.4.2.unitypackage
Binary file not shown.
2 changes: 1 addition & 1 deletion Assets/Adjust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Adjust : MonoBehaviour {
public AdjustUtil.AdjustEnvironment environment = AdjustUtil.AdjustEnvironment.Sandbox;
public bool eventBuffering = false;
public bool startManually = false;
public const string sdkPrefix = "unity3.4.1";
public const string sdkPrefix = "unity3.4.2";

void Awake() {
if (!this.startManually) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def LogInput(writeObject):
return Log

def parse_input(Log, parser):
args = parser.parse_known_args()
args, ignored_args = parser.parse_known_args()
assets_path = args.assets_path

android_plugin_path = os.path.join(assets_path, "Plugins/Android/")
Expand Down
2 changes: 1 addition & 1 deletion Assets/Editor/PostprocessBuildPlayer_AdjustPostBuildiOS
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def LogInput(writeObject):
return Log

def get_paths(Log, parser, xcode_sdk_path):
args = parser.parse_known_args()
args, ignored_args = parser.parse_known_args()
ios_project_path = args.ios_project_path

unity_xcode_project_path = ios_project_path + "/Unity-iPhone.xcodeproj/project.pbxproj"
Expand Down
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed Assets/Plugins/Android/adjust.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions Assets/Plugins/Metro/WindowsUap.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Assets/Plugins/WP8/AdjustWP80.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Assets/Plugins/iOS/AIActivityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@property (nonatomic, assign) BOOL bufferEvents;
@property (nonatomic, assign) BOOL trackMacMd5;
@property (nonatomic, assign) NSObject<AdjustDelegate> *delegate;
@property (nonatomic, assign) BOOL isIad;

- (id)initWithAppToken:(NSString *)appToken;
- (void)setSdkPrefix:(NSString *)sdkPrefix;
Expand All @@ -29,10 +30,11 @@
forEvent:(NSString *)eventToken
withParameters:(NSDictionary *)parameters;

- (void)finishedTrackingWithResponse:(AIResponseData *)response;
- (void)finishedTrackingWithResponse:(AIResponseData *)response deepLink:(NSString *)deepLink;
- (void)setEnabled:(BOOL)enabled;
- (BOOL)isEnabled;
- (void)readOpenUrl:(NSURL*)url;
- (void)savePushToken:(NSData *)pushToken;

@end

Expand Down
66 changes: 51 additions & 15 deletions Assets/Plugins/iOS/AIActivityHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#import "UIDevice+AIAdditions.h"
#import "NSString+AIAdditions.h"
#import "AIAdjustFactory.h"
#if !ADJUST_NO_IDA
#import <iAd/iAd.h>
#endif

static NSString * const kActivityStateFilename = @"AdjustIoActivityState";
static NSString * const kAdjustPrefix = @"adjust_";
Expand Down Expand Up @@ -47,8 +44,8 @@ @interface AIActivityHandler()
@property (nonatomic, copy) NSString *clientSdk;
@property (nonatomic, assign) BOOL trackingEnabled;
@property (nonatomic, assign) BOOL internalEnabled;
@property (nonatomic, assign) BOOL isIad;
@property (nonatomic, copy) NSString *vendorId;
@property (nonatomic, copy) NSString *pushToken;

@end

Expand All @@ -60,6 +57,7 @@ @implementation AIActivityHandler
@synthesize bufferEvents;
@synthesize trackMacMd5;
@synthesize delegate;
@synthesize isIad;

+ (id<AIActivityHandler>)handlerWithAppToken:(NSString *)appToken {
return [[AIActivityHandler alloc] initWithAppToken:appToken];
Expand Down Expand Up @@ -120,11 +118,37 @@ - (void)trackRevenue:(double)amount
});
}

- (void)finishedTrackingWithResponse:(AIResponseData *)response {
if ([self.delegate respondsToSelector:@selector(adjustFinishedTrackingWithResponse:)]) {
[self.delegate performSelectorOnMainThread:@selector(adjustFinishedTrackingWithResponse:)
withObject:response waitUntilDone:NO];
- (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 (response == nil) {
return;
}
[self.delegate performSelectorOnMainThread:@selector(adjustFinishedTrackingWithResponse:)
withObject:response waitUntilDone:NO];

}

- (void)launchDeepLink:(NSString *) deepLink{
if (deepLink == nil) return;

NSURL* deepLinkUrl = [NSURL URLWithString:deepLink];

if (![[UIApplication sharedApplication]
canOpenURL:deepLinkUrl]) {
[self.logger error:@"Unable to open deep link (%@)", deepLink];
return;
}

[self.logger info:@"Open deep link (%@)", deepLink];

[[UIApplication sharedApplication] openURL:deepLinkUrl];
}

- (void)setEnabled:(BOOL)enabled {
Expand Down Expand Up @@ -153,6 +177,12 @@ - (void)readOpenUrl:(NSURL*)url {
});
}

- (void)savePushToken:(NSData *)pushToken {
dispatch_async(self.internalQueue, ^{
[self savePushTokenInternal:pushToken];
});
}

#pragma mark - internal
- (void)initInternal:(NSString *)yourAppToken {
if (![self checkAppTokenNotNil:yourAppToken]) return;
Expand All @@ -170,13 +200,7 @@ - (void)initInternal:(NSString *)yourAppToken {
self.userAgent = AIUtil.userAgent;
self.vendorId = UIDevice.currentDevice.aiVendorId;

#if !ADJUST_NO_IDA
if (NSClassFromString(@"ADClient")) {
[ADClient.sharedClient determineAppInstallationAttributionWithCompletionHandler:^(BOOL appInstallationWasAttributedToiAd) {
self.isIad = appInstallationWasAttributedToiAd;
}];
}
#endif
[[UIDevice currentDevice] aiSetIad:self];

self.packageHandler = [AIAdjustFactory packageHandlerForActivityHandler:self];
[self readActivityState];
Expand Down Expand Up @@ -364,6 +388,17 @@ - (void) readOpenUrlInternal:(NSURL *)url {
[self.logger debug:@"Reattribution %@", adjustDeepLinks];
}

- (void) savePushTokenInternal:(NSData *)pushToken {
if (pushToken == nil) {
return;
}

NSString *token = [pushToken.description stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];

self.pushToken = token;
}

#pragma mark - private

// returns whether or not the activity state should be written
Expand Down Expand Up @@ -446,6 +481,7 @@ - (void)injectGeneralAttributes:(AIPackageBuilder *)builder {
builder.environment = self.environment;
builder.isIad = self.isIad;
builder.vendorId = self.vendorId;
builder.pushToken = self.pushToken;

if (self.trackMacMd5) {
builder.macShortMd5 = self.macShortMd5;
Expand Down
1 change: 1 addition & 0 deletions Assets/Plugins/iOS/AIPackageBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@property (nonatomic, assign) BOOL trackingEnabled;
@property (nonatomic, assign) BOOL isIad;
@property (nonatomic, copy) NSString *vendorId;
@property (nonatomic, copy) NSString *pushToken;

// sessions
@property (nonatomic, assign) int sessionCount;
Expand Down
1 change: 1 addition & 0 deletions Assets/Plugins/iOS/AIPackageBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ - (NSMutableDictionary *)defaultParameters {
[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"];
Expand Down
2 changes: 1 addition & 1 deletion Assets/Plugins/iOS/AIPackageHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- (void)pauseSending;
- (void)resumeSending;

- (void)finishedTrackingActivity:(AIActivityPackage *)activityPackage withResponse:(AIResponseData *)response;
- (void)finishedTrackingActivity:(AIActivityPackage *)activityPackage withResponse:(AIResponseData *)response jsonDict:(NSDictionary *)jsonDict;

@end

Expand Down
12 changes: 10 additions & 2 deletions Assets/Plugins/iOS/AIPackageHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,17 @@ - (void)resumeSending {
self.paused = NO;
}

- (void)finishedTrackingActivity:(AIActivityPackage *)activityPackage withResponse:(AIResponseData *)response {
- (void)finishedTrackingActivity:(AIActivityPackage *)activityPackage withResponse:(AIResponseData *)response jsonDict:(NSDictionary *)jsonDict{

response.activityKind = activityPackage.activityKind;
[self.activityHandler finishedTrackingWithResponse:response];

NSString * deepLink = nil;

if (jsonDict != nil) {
deepLink = [jsonDict objectForKey:@"deeplink"];
}

[self.activityHandler finishedTrackingWithResponse:response deepLink:deepLink];
}


Expand Down
8 changes: 4 additions & 4 deletions Assets/Plugins/iOS/AIRequestHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ - (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];
[self.packageHandler finishedTrackingActivity:package withResponse:responseData jsonDict:nil];
[self.packageHandler closeFirstPackage];
return;
}

NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
AIResponseData *responseData = [AIResponseData dataWithJsonString:responseString];
NSDictionary *jsonDict = [AIUtil buildJsonDict:responseString];
AIResponseData *responseData = [AIResponseData dataWithJsonDict:jsonDict jsonString:responseString];

if (response.statusCode == 200) {
// success
Expand All @@ -89,7 +90,7 @@ - (void)sendInternal:(AIActivityPackage *)package {
[self.logger error:@"%@. (%@)", package.failureMessage, responseData.error];
}

[self.packageHandler finishedTrackingActivity:package withResponse:responseData];
[self.packageHandler finishedTrackingActivity:package withResponse:responseData jsonDict:jsonDict];
[self.packageHandler sendNextPackage];
}

Expand Down Expand Up @@ -127,5 +128,4 @@ - (NSData *)bodyForParameters:(NSDictionary *)parameters {
NSData *body = [NSData dataWithBytes:bodyString.UTF8String length:bodyString.length];
return body;
}

@end
4 changes: 2 additions & 2 deletions Assets/Plugins/iOS/AIResponseData.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@

#pragma mark internals

+ (AIResponseData *)dataWithJsonString:(NSString *)string;
+ (AIResponseData *)dataWithJsonDict:(NSDictionary *)jsonDict jsonString:(NSString *)jsonString;
+ (AIResponseData *)dataWithError:(NSString *)error;

- (id)initWithJsonString:(NSString *)string;
- (id)initWithJsonDict:(NSDictionary *)jsonDict jsonString:(NSString *)jsonString;
- (id)initWithError:(NSString *)error;

@end
11 changes: 4 additions & 7 deletions Assets/Plugins/iOS/AIResponseData.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@

@implementation AIResponseData

+ (AIResponseData *)dataWithJsonString:(NSString *)string {
return [[AIResponseData alloc] initWithJsonString:string];
+ (AIResponseData *)dataWithJsonDict:(NSDictionary *)jsonDict jsonString:(NSString *)jsonString {
return [[AIResponseData alloc] initWithJsonDict:jsonDict jsonString:jsonString];
}

+ (AIResponseData *)dataWithError:(NSString *)error {
return [[AIResponseData alloc] initWithError:error];
}

- (id)initWithJsonString:(NSString *)jsonString {
- (id)initWithJsonDict:(NSDictionary *)jsonDict jsonString:(NSString *)jsonString {
self = [super init];
if (self == nil) return nil;

NSError *error = nil;
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (error != nil) {
if (jsonDict == nil) {
self.error = [NSString stringWithFormat:@"Failed to parse json response: %@", jsonString.aiTrim];
return self;
}
Expand Down
1 change: 1 addition & 0 deletions Assets/Plugins/iOS/AIUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@

+ (void)excludeFromBackup:(NSString *)filename;
+ (NSString *)dateFormat:(double)value;
+ (NSDictionary *) buildJsonDict:(NSString *)jsonString;

@end
15 changes: 14 additions & 1 deletion Assets/Plugins/iOS/AIUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#import "AILogger.h"
#import "UIDevice+AIAdditions.h"
#import "AIAdjustFactory.h"
#import "NSString+AIAdditions.h"

#include <sys/xattr.h>

static NSString * const kBaseUrl = @"https://app.adjust.io";
static NSString * const kClientSdk = @"ios3.3.4";
static NSString * const kClientSdk = @"ios3.4.0";

static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'Z";
static NSDateFormatter * dateFormat;
Expand Down Expand Up @@ -124,4 +125,16 @@ + (NSString *)dateFormat:(double) value {
return [dateFormat stringFromDate:date];
}

+ (NSDictionary *)buildJsonDict:(NSString *)jsonString {
NSError *error = nil;
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

if (error != nil) {
return nil;
}

return jsonDict;
}

@end
5 changes: 5 additions & 0 deletions Assets/Plugins/iOS/Adjust.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ static NSString * const AIEnvironmentProduction = @"production";
* an adjust deep link
*/
+ (void)appWillOpenUrl:(NSURL *)url;

/**
* Set the device token used by push notifications
*/
+ (void)setDeviceToken:(NSData *)deviceToken;
@end


Expand Down
4 changes: 4 additions & 0 deletions Assets/Plugins/iOS/Adjust.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ + (void)appWillOpenUrl:(NSURL *)url {
[activityHandler readOpenUrl:url];
}

+ (void)setDeviceToken:(NSData *)deviceToken {
[activityHandler savePushToken:deviceToken];
}

@end
3 changes: 2 additions & 1 deletion Assets/Plugins/iOS/UIDevice+AIAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AIActivityHandler.h"

@interface UIDevice(AIAdditions)

Expand All @@ -18,5 +19,5 @@
- (NSString *)aiDeviceName;
- (NSString *)aiCreateUuid;
- (NSString *)aiVendorId;

- (void)aiSetIad:(AIActivityHandler *)activityHandler;
@end
Loading

0 comments on commit 927b8de

Please sign in to comment.