Skip to content

Commit fc48037

Browse files
author
Unity Ads Travis
committed
Release 2.3.0
1 parent de12d89 commit fc48037

File tree

6 files changed

+45
-25
lines changed

6 files changed

+45
-25
lines changed

UnityAds/Api/UADSApiRequest.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ + (void)WebViewExposed_post:(NSString *)requestId url:(NSString *)url body:(NSSt
8585
[callback invoke:requestId, nil];
8686
}
8787

88+
+ (void)WebViewExposed_setConcurrentRequestCount: (int) count callback:(UADSWebViewCallback *)callback {
89+
[UADSWebRequestQueue setConcurrentRequestCount: count];
90+
[callback invoke:nil];
91+
}
92+
8893
+ (NSDictionary<NSString*,NSArray*> *)getHeadersMap:(NSArray *)headers {
8994
NSMutableDictionary *mappedHeaders = [[NSMutableDictionary alloc] init];
9095

UnityAds/Properties/UADSSdkProperties.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
NSString * const kUnityAdsLocalCacheFilePrefix = @"UnityAdsCache-";
55
NSString * const kUnityAdsLocalStorageFilePrefix = @"UnityAdsStorage-";
66
NSString * const kUnityAdsWebviewBranchInfoDictionaryKey = @"UADSWebviewBranch";
7-
NSString * const kUnityAdsVersionName = @"2.2.1";
7+
NSString * const kUnityAdsVersionName = @"2.3.0";
88
NSString * const kUnityAdsFlavorDebug = @"debug";
99
NSString * const kUnityAdsFlavorRelease = @"release";
10-
int const kUnityAdsVersionCode = 2201;
10+
int const kUnityAdsVersionCode = 2300;
1111

1212
@implementation UADSSdkProperties
1313

UnityAds/Request/UADSWebRequestQueue.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
@interface UADSWebRequestQueue : NSObject
55

66
+ (void)start;
7+
+ (void)setConcurrentRequestCount: (int) count;
78
+ (void)requestUrl:(NSString *)url type:(NSString *)type headers:(NSDictionary<NSString*, NSArray*> *)headers body:(NSString *)body completeBlock:(UnityAdsWebRequestCompletion)completeBlock connectTimeout:(int)connectTimeout;
89
+ (void)requestUrl:(NSString *)url type:(NSString *)type headers:(NSDictionary<NSString*, NSArray*> *)headers completeBlock:(UnityAdsWebRequestCompletion)completeBlock connectTimeout:(int)connectTimeout;
910
+ (BOOL)resolve:(NSString *)host completeBlock:(UnityAdsResolveRequestCompletion)completeBlock;
1011
+ (void)cancelAllOperations;
1112

12-
@end
13+
@end

UnityAds/Request/UADSWebRequestQueue.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ + (void)start {
2222
});
2323
}
2424

25+
+ (void)setConcurrentRequestCount: (int) count {
26+
requestQueue.maxConcurrentOperationCount = count;
27+
}
28+
2529
+ (void)requestUrl:(NSString *)url type:(NSString *)type headers:(NSDictionary<NSString*, NSArray*> *)headers completeBlock:(UnityAdsWebRequestCompletion)completeBlock connectTimeout:(int)connectTimeout {
2630
[UADSWebRequestQueue requestUrl:url type:type headers:headers body:NULL completeBlock:completeBlock connectTimeout:connectTimeout];
2731
}

UnityAds/UnityAds.m

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ + (void)initialize:(NSString *)gameId
112112
}
113113

114114
+ (void)show:(UIViewController *)viewController {
115-
[UnityAds show:viewController placementId:[UADSPlacement getDefaultPlacement]];
115+
if([UADSPlacement getDefaultPlacement]) {
116+
[UnityAds show:viewController placementId:[UADSPlacement getDefaultPlacement]];
117+
} else {
118+
[self handleShowError:@"" unityAdsError:kUnityAdsErrorNotInitialized message:@"Unity Ads default placement is not initialized"];
119+
}
116120
}
117121

118122
+ (void)show:(UIViewController *)viewController placementId:(NSString *)placementId {
@@ -135,10 +139,7 @@ + (void)show:(UIViewController *)viewController placementId:(NSString *)placemen
135139

136140
[UADSWebViewMethodInvokeQueue addOperation:operation];
137141
} else {
138-
if (!placementId) {
139-
NSException *exception = [NSException exceptionWithName:@"IllegalArgumentException" reason:@"PlacementID is nil" userInfo:nil];
140-
@throw exception;
141-
} else if (![self isSupported]) {
142+
if (![self isSupported]) {
142143
[self handleShowError:placementId unityAdsError:kUnityAdsErrorNotInitialized message:@"Unity Ads is not supported for this device"];
143144
} else if (![self isInitialized]) {
144145
[self handleShowError:placementId unityAdsError:kUnityAdsErrorNotInitialized message:@"Unity Ads is not initialized"];
@@ -203,14 +204,21 @@ + (BOOL)isInitialized {
203204
}
204205

205206
+ (void)handleShowError:(NSString *)placementId unityAdsError:(UnityAdsError)unityAdsError message:(NSString *)message {
206-
NSString *errorMessage = [NSString stringWithFormat:@"Unity Ads show failed: %@", message];
207-
UADSLogError(@"%@", errorMessage);
208-
if ([self getDelegate] && [[self getDelegate]respondsToSelector:@selector(unityAdsDidError:withMessage:)]) {
209-
[[self getDelegate] unityAdsDidError:unityAdsError withMessage:errorMessage];
210-
}
211-
if ([self getDelegate] && [[self getDelegate]respondsToSelector:@selector(unityAdsDidFinish:withFinishState:)]) {
212-
[[self getDelegate] unityAdsDidFinish:placementId withFinishState:kUnityAdsFinishStateError];
213-
}
207+
dispatch_async(dispatch_get_main_queue(), ^{
208+
NSString *errorMessage = [NSString stringWithFormat:@"Unity Ads show failed: %@", message];
209+
UADSLogError(@"%@", errorMessage);
210+
if ([self getDelegate] && [[self getDelegate]respondsToSelector:@selector(unityAdsDidError:withMessage:)]) {
211+
[[self getDelegate] unityAdsDidError:unityAdsError withMessage:errorMessage];
212+
}
213+
214+
if ([self getDelegate] && [[self getDelegate]respondsToSelector:@selector(unityAdsDidFinish:withFinishState:)]) {
215+
if (placementId) {
216+
[[self getDelegate] unityAdsDidFinish:placementId withFinishState:kUnityAdsFinishStateError];
217+
} else {
218+
[[self getDelegate] unityAdsDidFinish:@"" withFinishState:kUnityAdsFinishStateError];
219+
}
220+
}
221+
});
214222
}
215223

216224
@end

UnityAds/WebView/Bridge/UADSWebViewShowOperation.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ - (void)main {
1919

2020
if (!self.success) {
2121
UADSLogError(@"Unity Ads webapp timeout, shutting down Unity Ads");
22-
id delegate = [UADSClientProperties getDelegate];
23-
if (delegate) {
24-
if ([delegate respondsToSelector:@selector(unityAdsDidError:withMessage:)]) {
25-
[delegate unityAdsDidError:kUnityAdsErrorShowError withMessage:@"Webapp timeout, shutting down Unity Ads"];
22+
dispatch_async(dispatch_get_main_queue(), ^{
23+
id delegate = [UADSClientProperties getDelegate];
24+
if (delegate) {
25+
if ([delegate respondsToSelector:@selector(unityAdsDidError:withMessage:)]) {
26+
[delegate unityAdsDidError:kUnityAdsErrorShowError withMessage:@"Webapp timeout, shutting down Unity Ads"];
27+
}
28+
if ([delegate respondsToSelector:@selector(unityAdsDidFinish:withFinishState:)]) {
29+
NSString *placementId = [self.parameters objectAtIndex:0];
30+
[delegate unityAdsDidFinish:placementId withFinishState:kUnityAdsFinishStateError];
31+
}
2632
}
27-
if ([delegate respondsToSelector:@selector(unityAdsDidFinish:withFinishState:)]) {
28-
NSString *placementId = [self.parameters objectAtIndex:0];
29-
[delegate unityAdsDidFinish:placementId withFinishState:kUnityAdsFinishStateError];
30-
}
31-
}
33+
});
3234

3335
[UADSInitialize reset];
3436
}

0 commit comments

Comments
 (0)