AFUnityUtils.mm
2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// AFUnityUtils.mm
// Unity-iPhone
//
// Created by Jonathan Wesfield on 24/07/2019.
//
#if __has_include(<AppsFlyerLib/AppsFlyerTracker.h>)
#import <AppsFlyerLib/AppsFlyerTracker.h>
#else
#import "AppsFlyerTracker.h"
#endif
static NSString* stringFromChar(const char *str) {
return str ? [NSString stringWithUTF8String:str] : nil;
}
static NSDictionary* dictionaryFromJson(const char *jsonString) {
if(jsonString){
NSData *jsonData = [[NSData alloc] initWithBytes:jsonString length:strlen(jsonString)];
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
return dictionary;
}
return nil;
}
static const char* stringFromdictionary(NSDictionary* dictionary) {
if(dictionary){
NSError * err;
NSData * jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&err];
NSString * myString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
return [myString UTF8String];
}
return nil;
}
static NSArray<NSString*> *NSArrayFromCArray(int length, const char **arr) {
NSMutableArray<NSString *> *res = [[NSMutableArray alloc] init];
for(int i = 0; i < length; i++) {
if (arr[i]) {
[res addObject:[NSString stringWithUTF8String:arr[i]]];
}
}
return res;
}
static char* getCString(const char* string){
if (string == NULL){
return NULL;
}
char* res = (char*)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}
static AppsFlyerLinkGenerator* generatorFromDictionary(NSDictionary* dictionary, AppsFlyerLinkGenerator* generator) {
NSArray* generatorKeys = @[@"channel", @"customerID", @"campaign", @"referrerName", @"referrerImageUrl", @"deeplinkPath", @"baseDeeplink", @"brandDomain"];
NSMutableDictionary* mutableDictionary = [dictionary mutableCopy];
[generator setChannel:[dictionary objectForKey: @"channel"]];
[generator setReferrerCustomerId:[dictionary objectForKey: @"customerID"]];
[generator setCampaign:[dictionary objectForKey: @"campaign"]];
[generator setReferrerName:[dictionary objectForKey: @"referrerName"]];
[generator setReferrerImageURL:[dictionary objectForKey: @"referrerImageUrl"]];
[generator setDeeplinkPath:[dictionary objectForKey: @"deeplinkPath"]];
[generator setBaseDeeplink:[dictionary objectForKey: @"baseDeeplink"]];
[generator setBrandDomain:[dictionary objectForKey: @"brandDomain"]];
[mutableDictionary removeObjectsForKeys:generatorKeys];
[generator addParameters:mutableDictionary];
return generator;
}
static EmailCryptType emailCryptTypeFromInt(int emailCryptTypeInt){
EmailCryptType emailCryptType;
switch (emailCryptTypeInt){
case 1:
emailCryptType = EmailCryptTypeSHA256;
break;
default:
emailCryptType = EmailCryptTypeNone;
break;
}
return emailCryptType;
}