Skip to content

Commit dddce04

Browse files
runnerrunner
runner
authored and
runner
committed
Release
1 parent b3d4a74 commit dddce04

File tree

269 files changed

+10724
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+10724
-332
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
#import "UADSApiToken.h"
22
#import "USRVWebViewCallback.h"
33
#import "UADSTokenStorage.h"
4+
#import "UADSHeaderBiddingTokenReaderBuilder.h"
45

56
@implementation UADSApiToken
67

78
+ (void)WebViewExposed_createTokens: (NSArray *)tokens callback: (USRVWebViewCallback *)callback {
8-
[[UADSTokenStorage sharedInstance] createTokens: tokens];
9+
[self.tokenStorage createTokens: tokens];
910
[callback invoke: nil];
1011
}
1112

1213
+ (void)WebViewExposed_appendTokens: (NSArray *)tokens callback: (USRVWebViewCallback *)callback {
13-
[[UADSTokenStorage sharedInstance] appendTokens: tokens];
14+
[self.tokenStorage appendTokens: tokens];
1415
[callback invoke: nil];
1516
}
1617

1718
+ (void)WebViewExposed_deleteTokens: (USRVWebViewCallback *)callback {
18-
[[UADSTokenStorage sharedInstance] deleteTokens];
19+
[self.tokenStorage deleteTokens];
1920
[callback invoke: nil];
2021
}
2122

2223
+ (void)WebViewExposed_setPeekMode: (NSNumber *)value callback: (USRVWebViewCallback *)callback {
23-
[[UADSTokenStorage sharedInstance] setPeekMode: [value boolValue]];
24+
[self.tokenStorage setPeekMode: [value boolValue]];
2425
[callback invoke: nil];
2526
}
2627

28+
+ (id<UADSHeaderBiddingTokenCRUD>)tokenStorage {
29+
return UADSHeaderBiddingTokenReaderBuilder.sharedInstance.defaultReader;
30+
}
31+
2732
@end

SourceCode/Private/Ads/Configuration/UADSAdsModuleConfiguration.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#import "UADSWebViewShowOperation.H"
33
#import "UADSTokenStorage.h"
44
#import "UADSAbstractModule.h"
5+
#import "UADSHeaderBiddingTokenReaderBuilder.h"
6+
57
@implementation UADSAdsModuleConfiguration
68

79
- (NSArray<NSString *> *)getWebAppApiClassList {
@@ -29,6 +31,9 @@ - (BOOL)initModuleState: (USRVConfiguration *)configuration {
2931
}
3032

3133
- (BOOL)initErrorState: (USRVConfiguration *)configuration state: (NSString *)state message: (NSString *)message {
34+
[UADSHeaderBiddingTokenReaderBuilder.sharedInstance.defaultReader setInitToken: nil];
35+
[UADSHeaderBiddingTokenReaderBuilder.sharedInstance.defaultReader deleteTokens];
36+
3237
return true;
3338
}
3439

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
#import "UADSTokenStorageEventProtocol.h"
2+
#import "UADSHeaderBiddingTokenReaderBase.h"
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@protocol UADSHeaderBiddingTokenCRUD <NSObject>
6+
- (void)createTokens: (NSArray<NSString *> *)tokens;
7+
- (void)appendTokens: (NSArray<NSString *> *)tokens;
8+
- (NSString *) getToken;
9+
- (void) deleteTokens;
10+
- (void)setPeekMode: (BOOL)mode;
11+
- (void)setInitToken: (nullable NSString *)token;
12+
13+
@end
14+
15+
@interface UADSTokenStorage : NSObject<UADSHeaderBiddingTokenCRUD>
216

3-
@interface UADSTokenStorage : NSObject
417

518
+ (instancetype)sharedInstance;
619

720
- (instancetype)initWithEventHandler: (id<UADSTokenStorageEventProtocol>)eventHandler;
8-
921
- (void)createTokens: (NSArray<NSString *> *)tokens;
1022
- (void)appendTokens: (NSArray<NSString *> *)tokens;
1123
- (NSString *) getToken;
1224
- (void) deleteTokens;
1325
- (void)setPeekMode: (BOOL)mode;
14-
26+
- (void)setInitToken: (nullable NSString *)token;
1527
@end
28+
29+
NS_ASSUME_NONNULL_END

SourceCode/Private/Ads/Token/UADSTokenStorage.m

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "UADSTokenStorage.h"
22
#import "UADSTokenStorageEventHandler.h"
3+
#import "UADSInitializeEventsMetricSender.h"
34

45
@interface UADSTokenStorage ()
56

@@ -8,7 +9,7 @@ @interface UADSTokenStorage ()
89
@property int accessCounter;
910
@property (nonatomic) BOOL peekMode;
1011
@property dispatch_queue_t dispatchQueue;
11-
12+
@property (nonatomic, copy) NSString *firstToken;
1213
@property NSObject *lockObject;
1314

1415
@end
@@ -42,6 +43,7 @@ - (void)createTokens: (NSArray<NSString *> *)tokens {
4243
self.accessCounter = 0;
4344
self.queue = [[NSMutableArray alloc] initWithCapacity: tokens.count];
4445
[self.queue addObjectsFromArray: tokens];
46+
[self sendWebViewTokenAvailabilityMetricsIfRequired];
4547
}
4648
}
4749

@@ -50,6 +52,7 @@ - (void)appendTokens: (NSArray<NSString *> *)tokens {
5052
if (self.queue == nil) {
5153
self.accessCounter = 0;
5254
self.queue = [[NSMutableArray alloc] initWithCapacity: tokens.count];
55+
[self sendWebViewTokenAvailabilityMetricsIfRequired];
5356
}
5457

5558
[self.queue addObjectsFromArray: tokens];
@@ -65,12 +68,12 @@ - (void)setPeekMode: (BOOL)mode {
6568
- (NSString *)getToken {
6669
@synchronized (_lockObject) {
6770
if (self.queue == nil) {
68-
return nil;
71+
return self.firstToken;
6972
}
7073

7174
if (self.queue.count == 0) {
7275
[self.eventHandler sendQueueEmpty];
73-
return nil;
76+
return self.firstToken;
7477
}
7578

7679
[self.eventHandler sendTokenAccessIndex: [NSNumber numberWithInt: self.accessCounter++]];
@@ -92,4 +95,27 @@ - (void)deleteTokens {
9295
}
9396
}
9497

98+
- (void)setInitToken: (NSString *)token {
99+
@synchronized (_lockObject) {
100+
self.firstToken = token;
101+
}
102+
[self sendFirstInitTokenAvailabilityMetricsIfRequired];
103+
}
104+
105+
- (void)sendFirstInitTokenAvailabilityMetricsIfRequired {
106+
if (_firstToken) {
107+
[self.metricsSender sendTokenAvailabilityLatencyOnceOfType: kUADSTokenAvailabilityTypeFirstToken];
108+
}
109+
}
110+
111+
- (void)sendWebViewTokenAvailabilityMetricsIfRequired {
112+
if (_queue.count > 0) {
113+
[self.metricsSender sendTokenAvailabilityLatencyOnceOfType: kUADSTokenAvailabilityTypeWeb];
114+
}
115+
}
116+
117+
- (UADSInitializeEventsMetricSender *)metricsSender {
118+
return UADSInitializeEventsMetricSender.sharedInstance;
119+
}
120+
95121
@end

SourceCode/Private/Core/Api/USRVApiSdk.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ + (void)WebViewExposed_loadComplete: (USRVWebViewCallback *)callback {
2929
[NSNumber numberWithBool: YES], // placement load enabled
3030
[NSNumber numberWithBool: [USRVSdkProperties getLatestConfiguration] != nil],
3131
[USRVDevice getElapsedRealtime],
32+
[[[USRVWebViewApp getCurrentApp] configuration] stateId] ? : @"",
3233
nil];
3334
} /* WebViewExposed_loadComplete */
3435

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@protocol UADSPlistReader <NSObject>
6+
7+
- (NSString *)getStringValueForKey: (NSString *)key;
8+
9+
@end
10+
11+
@interface NSBundle (TypecastGet)<UADSPlistReader>
12+
- (NSString *)getStringValueForKey: (NSString *)key;
13+
+ (NSString *)getBuiltSDKVersion;
14+
+ (NSString *)getFromMainBundleValueForKey: (NSString *)key;
15+
@end
16+
17+
NS_ASSUME_NONNULL_END
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#import "NSBundle + TypecastGet.h"
2+
#import "UADSTools.h"
3+
4+
@implementation NSBundle (TypecastGet)
5+
- (NSString *)getStringValueForKey: (NSString *)key {
6+
id obj = [self objectForInfoDictionaryKey: key];
7+
8+
return typecast(obj, [NSString class]);
9+
}
10+
11+
+ (NSString *)getFromMainBundleValueForKey: (NSString *)key {
12+
return [[self mainBundle] getStringValueForKey: key];
13+
}
14+
15+
+ (NSString *)getBuiltSDKVersion {
16+
return [self getFromMainBundleValueForKey: @"DTSDKName"];
17+
}
18+
19+
@end

SourceCode/Private/Core/Categories/NSDictionary+Merge.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

SourceCode/Private/Core/Categories/NSDictionary+Merge.m

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@interface NSDictionary<__covariant KeyType, __covariant ObjectType> (Filter)
6+
7+
- (NSDictionary *)uads_filter: (BOOL(NS_NOESCAPE ^)(KeyType key, ObjectType obj))block;
8+
- (NSDictionary *)uads_mapKeys: (KeyType(NS_NOESCAPE ^)(KeyType key))block;
9+
@end
10+
11+
NS_ASSUME_NONNULL_END
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#import "NSDictionary+Filter.h"
2+
3+
@implementation NSDictionary (Filter)
4+
- (NSDictionary *)uads_filter: (BOOL(NS_NOESCAPE ^)(id key, id obj))block; {
5+
NSMutableDictionary *newDictionary = [NSMutableDictionary new];
6+
7+
[self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL *_Nonnull stop) {
8+
if (block(key, obj)) {
9+
newDictionary[key] = obj;
10+
}
11+
}];
12+
13+
return newDictionary;
14+
}
15+
16+
- (NSDictionary *)uads_mapKeys: (id(NS_NOESCAPE ^)(id key))block {
17+
NSMutableDictionary *newDictionary = [NSMutableDictionary new];
18+
19+
[self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL *_Nonnull stop) {
20+
newDictionary[block(key)] = obj;
21+
}];
22+
23+
return newDictionary;
24+
}
25+
26+
@end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@interface NSDictionary (JSONString)
6+
- (NSString *) jsonEncodedString;
7+
- (NSData *_Nullable)jsonData;
8+
- (NSString *) queryString;
9+
- (BOOL) isEmpty;
10+
@end
11+
12+
NS_ASSUME_NONNULL_END
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#import "NSDictionary+JSONString.h"
2+
3+
@implementation NSDictionary (JSONString)
4+
- (NSString *)jsonEncodedString {
5+
NSData *jsonData = [self jsonData];
6+
7+
if (!jsonData) {
8+
return @"";
9+
}
10+
11+
return [[NSString alloc] initWithData: jsonData
12+
encoding: NSUTF8StringEncoding];
13+
}
14+
15+
- (NSData *)jsonData {
16+
NSError *err;
17+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject: self
18+
options: 0
19+
error: &err];
20+
21+
if (err) {
22+
return nil;
23+
}
24+
25+
GUARD_OR_NIL(jsonData)
26+
return jsonData;
27+
}
28+
29+
- (NSString *)queryString {
30+
__block NSString *queryString = @"";
31+
__block BOOL first = true;
32+
33+
[self enumerateKeysAndObjectsUsingBlock: ^(id _Nonnull key, id _Nonnull obj, BOOL *_Nonnull stop) {
34+
if (first) {
35+
queryString = [NSString stringWithFormat: @"?%@%@=%@", queryString, key, obj];
36+
first = false;
37+
} else {
38+
queryString = [NSString stringWithFormat: @"%@&%@=%@", queryString, key, obj];
39+
}
40+
}];
41+
42+
return queryString;
43+
}
44+
45+
- (BOOL)isEmpty {
46+
return self.count <= 0;
47+
}
48+
49+
@end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@interface NSDictionary (Merge)
2+
3+
+ (NSDictionary *)unityads_dictionaryByMerging: (NSDictionary *)primary secondary: (NSDictionary *)secondary;
4+
5+
- (NSDictionary *)uads_newdictionaryByMergingWith: (NSDictionary *)dictionary;
6+
7+
- (NSDictionary *)uads_flatUsingSeparator: (NSString *)separator
8+
includeTopLevelKeys: (NSArray<NSString *> *)topLevelToInclude
9+
andReduceKeys: (NSArray<NSString *> *)reduceKeys
10+
andSkipKeys: (NSArray<NSString *> *)keysToSkip;
11+
@end

0 commit comments

Comments
 (0)