Skip to content

Commit

Permalink
Release 2.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Str4tos committed Jul 28, 2022
1 parent 96cc280 commit e950f64
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 140 deletions.
92 changes: 47 additions & 45 deletions Plugins/iOS/CASUCallback.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,75 @@

@implementation CASUCallback
{
BOOL withComplete;
BOOL withComplete;
NSString* _lastImpression;
}

- (id)initWithComplete:(BOOL)complete {
self = [super init];
if (self) {
withComplete = complete;
}
return self;
self = [super init];
if (self) {
withComplete = complete;
}
return self;
}

- (void)willShownWithAd:(id<CASStatusHandler>)adStatus {
[CASUPluginUtil onAdsWillPressent];
if (self.client) {
if (self.willOpeningCallback) {
self.willOpeningCallback(self.client, [CASUPluginUtil adMetaDataToStringPointer:adStatus]);
}
}
[CASUPluginUtil onAdsWillPressent];
if (self.client) {
if (self.willOpeningCallback) {
_lastImpression = [CASUPluginUtil adMetaDataToStringPointer:adStatus];
self.willOpeningCallback(self.client, [_lastImpression cStringUsingEncoding:NSUTF8StringEncoding] );
}
}
}

- (void)didShowAdFailedWithError:(NSString *)error {
[CASUPluginUtil onAdsDidClosed];
if (self.didShowFailedCallback) {
if (self.client) {
self.didShowFailedCallback(self.client, [error cStringUsingEncoding:NSUTF8StringEncoding]);
}
}
[CASUPluginUtil onAdsDidClosed];
if (self.didShowFailedCallback) {
if (self.client) {
self.didShowFailedCallback(self.client, [error cStringUsingEncoding:NSUTF8StringEncoding]);
}
}
}

- (void)didCompletedAd {
if (!withComplete) {
return;
}
if (self.didCompleteCallback) {
if (self.client) {
self.didCompleteCallback(self.client);
}
}
if (!withComplete) {
return;
}
if (self.didCompleteCallback) {
if (self.client) {
self.didCompleteCallback(self.client);
}
}
}

- (void)didClickedAd {
if (self.didClickCallback) {
if (self.client) {
self.didClickCallback(self.client);
}
}
if (self.didClickCallback) {
if (self.client) {
self.didClickCallback(self.client);
}
}
}

- (void)didClosedAd {
// Escape from callback when App on background. Not supported for Cross Promo logic.
// extern bool _didResignActive;
// if (_didResignActive) {
// // We are in the middle of the shutdown sequence, and at this point unity runtime is already destroyed.
// // We shall not call unity API, and definitely not script callbacks, so nothing to do here
// return;
// }
// Escape from callback when App on background. Not supported for Cross Promo logic.
// extern bool _didResignActive;
// if (_didResignActive) {
// // We are in the middle of the shutdown sequence, and at this point unity runtime is already destroyed.
// // We shall not call unity API, and definitely not script callbacks, so nothing to do here
// return;
// }

[CASUPluginUtil onAdsDidClosed];
if (self.didClosedCallback) {
if (self.client) {
self.didClosedCallback(self.client);
}
}
[CASUPluginUtil onAdsDidClosed];
if (self.didClosedCallback) {
if (self.client) {
self.didClosedCallback(self.client);
}
}
}

- (UIViewController *)viewControllerForPresentingAppReturnAd {
return [CASUPluginUtil unityGLViewController];
return [CASUPluginUtil unityGLViewController];
}

@end
6 changes: 0 additions & 6 deletions Plugins/iOS/CASUInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ void CASUFreeManager(CASUTypeManagerRef managerRef)
}

#pragma mark - General Ads functions
const char * CASUGetLastActiveMediationWithType(CASUTypeManagerRef managerRef, int adType)
{
CASUManager *manager = (__bridge CASUManager *)managerRef;
return [CASUPluginUtil stringToUnity:[manager.casManager getLastActiveMediationWithType:(CASType)adType]];
}

BOOL CASUIsAdEnabledType(CASUTypeManagerRef managerRef, int adType)
{
CASUManager *manager = (__bridge CASUManager *)managerRef;
Expand Down
2 changes: 1 addition & 1 deletion Plugins/iOS/CASUPluginUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)stringFromUnity:(const char *_Nullable)bytes;
/// Returns a C string from a C array of UTF8-encoded bytes.
+ (const char *)stringToUnity:(NSString *)str;
+ (const char *)adMetaDataToStringPointer:(id<CASStatusHandler>)ad;
+ (NSString *)adMetaDataToStringPointer:(id<CASStatusHandler>)ad;
+ (UIViewController *)unityGLViewController;
+ (void)onAdsWillPressent;
+ (void)onAdsDidClosed;
Expand Down
154 changes: 77 additions & 77 deletions Plugins/iOS/CASUPluginUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
#endif
UIViewController * UnityGetGLViewController(void)
{
return nil;
return nil;
}

UIWindow * UnityGetMainWindow(void)
{
return nil;
return nil;
}

int UnityIsPaused(void)
{
return 0;
return 0;
}

void UnityPause(int pause)
Expand All @@ -49,121 +49,121 @@ @interface CASUPluginUtil ()

@implementation CASUPluginUtil
{
dispatch_queue_t _lockQueue;
dispatch_queue_t _lockQueue;
}

+ (instancetype)sharedInstance {
static CASUPluginUtil *sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
static CASUPluginUtil *sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}

- (id)init {
self = [super init];
if (self) {
_internalReferences = [[NSMutableDictionary alloc] init];
_lockQueue = dispatch_queue_create("CASUObjectCache lock queue", DISPATCH_QUEUE_SERIAL);
}
return self;
self = [super init];
if (self) {
_internalReferences = [[NSMutableDictionary alloc] init];
_lockQueue = dispatch_queue_create("CASUObjectCache lock queue", DISPATCH_QUEUE_SERIAL);
}
return self;
}

- (void)saveObject:(id)obj withKey:(NSString *)key {
dispatch_async(_lockQueue, ^{
self->_internalReferences[key] = obj;
});
dispatch_async(_lockQueue, ^{
self->_internalReferences[key] = obj;
});
}

- (void)removeObjectWithKey:(NSString *)key {
dispatch_async(_lockQueue, ^{
[self->_internalReferences removeObjectForKey:key];
});
dispatch_async(_lockQueue, ^{
[self->_internalReferences removeObjectForKey:key];
});
}

- (void)analyticsEvent:(NSString *)eventName map:(NSDictionary<NSString *, id> *)map {
#if __has_include(<FirebaseAnalytics/FIRAnalytics.h>)
[FIRAnalytics logEventWithName:eventName parameters:map];
[FIRAnalytics logEventWithName:eventName parameters:map];
#else
NSLog(@"[CAS] Framework bridge cant find Firebase Analytics");
NSLog(@"[CAS] Framework bridge cant find Firebase Analytics");
#endif
}

static BOOL _pauseOnBackground = YES;

+ (BOOL)pauseOnBackground {
return _pauseOnBackground;
return _pauseOnBackground;
}

+ (void)setPauseOnBackground:(BOOL)pause {
_pauseOnBackground = pause;
_pauseOnBackground = pause;
}

+ (NSString *)stringFromUnity:(const char *)bytes {
return bytes ? @(bytes) : nil;
return bytes ? @(bytes) : nil;
}

+ (const char *)stringToUnity:(NSString *)str {
if (!str) {
return NULL;
}
const char *string = str.UTF8String;
char *res = (char *)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}

+ (const char *)adMetaDataToStringPointer:(id<CASStatusHandler>)ad {
NSMutableString *result = [[NSMutableString alloc] initWithCapacity:64];
[result appendString:@"cpm="];
[result appendString:[@(ad.cpm) stringValue]];
[result appendString:@";accuracy="];
[result appendString:[@(ad.priceAccuracy) stringValue]];
[result appendString:@";"];

NSString *network = ad.network;
if (![network isEqualToString:CASNetwork.lastPageAd]) {
NSUInteger netIndex = [[CASNetwork values] indexOfObject:network];
if (netIndex != NSNotFound) {
[result appendString:@"network="];
[result appendString:[@(netIndex) stringValue]];
[result appendString:@";"];
}
}

NSString *creativeId = ad.creativeIdentifier;
if (creativeId.length != 0) {
[result appendString:@"creative="];
[result appendString:creativeId];
[result appendString:@";"];
}

NSString *identifier = ad.identifier;
if (creativeId.length != 0) {
[result appendString:@"id="];
[result appendString:identifier];
[result appendString:@";"];
}
return [CASUPluginUtil stringToUnity:result];
if (!str) {
return NULL;
}
const char *string = str.UTF8String;
char *res = (char *)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}

+ (NSString *)adMetaDataToStringPointer:(id<CASStatusHandler>)ad {
NSMutableString *result = [[NSMutableString alloc] initWithCapacity:64];
[result appendString:@"cpm="];
[result appendString:[@(ad.cpm) stringValue]];
[result appendString:@";accuracy="];
[result appendString:[@(ad.priceAccuracy) stringValue]];
[result appendString:@";"];

NSString *network = ad.network;
if (![network isEqualToString:CASNetwork.lastPageAd]) {
NSUInteger netIndex = [[CASNetwork values] indexOfObject:network];
if (netIndex != NSNotFound) {
[result appendString:@"network="];
[result appendString:[@(netIndex) stringValue]];
[result appendString:@";"];
}
}

NSString *creativeId = ad.creativeIdentifier;
if (creativeId.length != 0) {
[result appendString:@"creative="];
[result appendString:creativeId];
[result appendString:@";"];
}

NSString *identifier = ad.identifier;
if (creativeId.length != 0) {
[result appendString:@"id="];
[result appendString:identifier];
[result appendString:@";"];
}
return result;
}

+ (UIViewController *)unityGLViewController {
return UnityGetGLViewController()
? : UnityGetMainWindow().rootViewController
? : [[UIApplication sharedApplication].keyWindow rootViewController];
return UnityGetGLViewController()
? : UnityGetMainWindow().rootViewController
? : [[UIApplication sharedApplication].keyWindow rootViewController];
}

+ (void)onAdsWillPressent {
if ([CASUPluginUtil pauseOnBackground]) {
UnityPause(YES);
}
if ([CASUPluginUtil pauseOnBackground]) {
UnityPause(YES);
}
}

+ (void)onAdsDidClosed {
if (UnityIsPaused()) {
UnityPause(NO);
}
if (UnityIsPaused()) {
UnityPause(NO);
}
}

@end
8 changes: 6 additions & 2 deletions Plugins/iOS/CASUView.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ @interface CASUView () <CASBannerDelegate>
@property (nonatomic, assign) int activePos;
@end

@implementation CASUView
@implementation CASUView {
NSString* _lastImpression;
}

- (id)initWithManager:(CASMediationManager *)manager
forClient:(CASUTypeViewClientRef *)adViewClient
size:(int)size {
Expand Down Expand Up @@ -222,7 +225,8 @@ - (void)bannerAdViewDidLoad:(CASBannerView *_Nonnull)view {

- (void)bannerAdView:(CASBannerView *)adView willPresent:(id<CASStatusHandler>)impression {
if (self.adPresentedCallback) {
self.adPresentedCallback(self.client, [CASUPluginUtil adMetaDataToStringPointer:impression]);
_lastImpression = [CASUPluginUtil adMetaDataToStringPointer:impression];
self.adPresentedCallback(self.client, [_lastImpression cStringUsingEncoding:NSUTF8StringEncoding] );
}
}

Expand Down
2 changes: 1 addition & 1 deletion Runtime/Common/MobileAds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class MobileAds
/// <summary>
/// CAS Unity wrapper version
/// </summary>
public const string wrapperVersion = "2.8.4-rc1";
public const string wrapperVersion = "2.8.4";

/// <summary>
/// Get singleton instance for configure all mediation managers.
Expand Down
Loading

0 comments on commit e950f64

Please sign in to comment.