Skip to content

Commit

Permalink
Initial deploy for all network adapters using MoPub mediation
Browse files Browse the repository at this point in the history
  • Loading branch information
PoojaChirp committed Feb 20, 2018
0 parents commit 55e2ef2
Show file tree
Hide file tree
Showing 144 changed files with 7,413 additions and 0 deletions.
39 changes: 39 additions & 0 deletions AdColony/AdColonyController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// AdColonyController.h
// MoPubSDK
//
// Copyright (c) 2016 MoPub. All rights reserved.
//

#import "AdColonyInterstitialCustomEvent.h"
#import "AdColonyRewardedVideoCustomEvent.h"
#import "AdColonyInstanceMediationSettings.h"
#import "AdColonyGlobalMediationSettings.h"

/*
* Internal controller to handle initialization and common routines across ad types.
*/
@interface AdColonyController : NSObject

/*
* Initialize AdColony for the given zone IDs and app ID.
*
* Multiple calls to this method will result in initialiazing AdColony only once.
*
* @param appId The application's AdColony App ID.
* @param allZoneIds All the possible zone IDs the application may use across all ad formats.
* @param userId The user ID to attribute ads/rewards.
*/
+ (void)initializeAdColonyCustomEventWithAppId:(NSString *)appId allZoneIds:(NSArray *)allZoneIds userId:(NSString *)userId callback:(void(^)())callback;

/*
* Enables test ads for your application without changing dashboard settings.
*/
+ (void)enableClientSideTestMode;

/*
* Disables test ads for your application without changing dashboard settings.
*/
+ (void)disableClientSideTestMode;

@end
119 changes: 119 additions & 0 deletions AdColony/AdColonyController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// AdColonyController.m
// MoPubSDK
//
// Copyright (c) 2016 MoPub. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AdColony/AdColony.h>
#import "AdColonyController.h"
#import "AdColonyGlobalMediationSettings.h"
#import "MoPub.h"
#import "MPRewardedVideo.h"

typedef enum {
INIT_STATE_UNKNOWN,
INIT_STATE_INITIALIZED,
INIT_STATE_INITIALIZING
} InitState;

@interface AdColonyController()

@property (atomic, assign) InitState initState;
@property (atomic, retain) NSArray *callbacks;
@property (atomic, strong) NSSet *currentAllZoneIds;
@property (atomic, assign) BOOL testModeEnabled;

@end

@implementation AdColonyController

+ (void)initializeAdColonyCustomEventWithAppId:(NSString *)appId allZoneIds:(NSArray *)allZoneIds userId:(NSString *)userId callback:(void(^)())callback {
AdColonyController *instance = [AdColonyController sharedInstance];

@synchronized (instance) {
NSSet * allZoneIdsSet = [NSSet setWithArray:allZoneIds];
BOOL zoneIdsSame = [instance.currentAllZoneIds isEqualToSet:allZoneIdsSet];

if (instance.initState == INIT_STATE_INITIALIZED && zoneIdsSame) {
if (callback) {
callback();
}
} else {
instance.callbacks = [instance.callbacks arrayByAddingObject:callback];

if (instance.initState != INIT_STATE_INITIALIZING) {
instance.initState = INIT_STATE_INITIALIZING;

AdColonyGlobalMediationSettings *settings = [[MoPub sharedInstance] globalMediationSettingsForClass:[AdColonyGlobalMediationSettings class]];
AdColonyAppOptions *options = [AdColonyAppOptions new];

if (userId && userId.length > 0) {
options.userID = userId;
} else if (settings && settings.customId.length > 0) {
options.userID = settings.customId;
}

instance.currentAllZoneIds = allZoneIdsSet;
options.testMode = instance.testModeEnabled;

[AdColony configureWithAppID:appId zoneIDs:allZoneIds options:options completion:^(NSArray<AdColonyZone *> * _Nonnull zones) {
@synchronized (instance) {
instance.initState = INIT_STATE_INITIALIZED;
for (void(^localCallback)() in instance.callbacks) {
localCallback();
}
}
}];
}
}
}
}

+ (void)enableClientSideTestMode {
AdColonyController *instance = [AdColonyController sharedInstance];

@synchronized (instance) {
instance.testModeEnabled = YES;

if (instance.initState == INIT_STATE_INITIALIZED || instance.initState == INIT_STATE_INITIALIZING) {
AdColonyAppOptions *options = [AdColony getAppOptions];
options.testMode = YES;
[AdColony setAppOptions:options];
}
}
}

+ (void)disableClientSideTestMode {
AdColonyController *instance = [AdColonyController sharedInstance];

@synchronized (instance) {
instance.testModeEnabled = NO;

if (instance.initState == INIT_STATE_INITIALIZED || instance.initState == INIT_STATE_INITIALIZING) {
AdColonyAppOptions *options = [AdColony getAppOptions];
options.testMode = NO;
[AdColony setAppOptions:options];
}
}
}

+ (AdColonyController *)sharedInstance {
static dispatch_once_t onceToken;
static AdColonyController *instance = nil;
dispatch_once(&onceToken, ^{
instance = [AdColonyController new];
});
return instance;
}

- (id)init {
if (self = [super init]) {
_initState = INIT_STATE_UNKNOWN;
_callbacks = @[];
}
return self;
}

@end
44 changes: 44 additions & 0 deletions AdColony/AdColonyGlobalMediationSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// AdColonyGlobalMediationSettings.h
// MoPubSDK
//
// Copyright (c) 2016 MoPub. All rights reserved.
//

#import <Foundation/Foundation.h>

#if __has_include(<MoPub/MoPub.h>)
#import <MoPub/MoPub.h>
#else
#import "MPMediationSettingsProtocol.h"
#endif

#import <AdColony/AdColony.h>

/*
* `AdColonyGlobalMediationSettings` allows the application to provide constant global properties
* to configure aspects of AdColony. See `MPMediationSettingsProtocol` to see how mediation settings
* are used. This only apply to AdColonyRewardedVideoCustomEvents.
*/
@interface AdColonyGlobalMediationSettings : NSObject <MPMediationSettingsProtocol>

/*
* Sets the customId to utilize server-side mode for AdColony V4VC.
*/
@property (nonatomic, copy) NSString *customId;

/*
* Enables test ads for your application without changing dashboard settings.
* Note this method simply just wraps the identical method on the AdColonyController class.
* This is so we can keep that class private and have developers just use what's already available to them.
*/
+ (void)enableClientSideTestMode;

/*
* Disables test ads for your application without changing dashboard settings.
* Note this method simply just wraps the identical method on the AdColonyController class.
* This is so we can keep that class private and have developers just use what's already available to them.
*/
+ (void)disableClientSideTestMode;

@end
21 changes: 21 additions & 0 deletions AdColony/AdColonyGlobalMediationSettings.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AdColonyGlobalMediationSettings.m
// MoPubSDK
//
// Copyright (c) 2016 MoPub. All rights reserved.
//

#import "AdColonyGlobalMediationSettings.h"
#import "AdColonyController.h"

@implementation AdColonyGlobalMediationSettings

+ (void)enableClientSideTestMode {
[AdColonyController enableClientSideTestMode];
}

+ (void)disableClientSideTestMode {
[AdColonyController disableClientSideTestMode];
}

@end
35 changes: 35 additions & 0 deletions AdColony/AdColonyInstanceMediationSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// AdColonyInstanceMediationSettings.h
// MoPubSDK
//
// Copyright (c) 2016 MoPub. All rights reserved.
//

#import <Foundation/Foundation.h>

#if __has_include(<MoPub/MoPub.h>)
#import <MoPub/MoPub.h>
#else
#import "MPMediationSettingsProtocol.h"
#endif

/*
* `AdColonyInstanceMediationSettings` allows the application to provide per-instance properties
* to configure aspects of AdColony ads. See `MPMediationSettingsProtocol` to see how mediation settings
* are used. This only apply to AdColonyRewardedVideoCustomEvents.
*/
@interface AdColonyInstanceMediationSettings : NSObject <MPMediationSettingsProtocol>

/*
* Set to true if you wish to show a pre-popup dialog for AdColony V4VC ads.
* Default behavior treats this property as if it is set to false.
*/
@property (nonatomic, assign) BOOL showPrePopup;

/*
* Set to true if you wish to show a post-popup dialog for AdColony V4VC ads.
* Default behavior treats this property as if it is set to false.
*/
@property (nonatomic, assign) BOOL showPostPopup;

@end
12 changes: 12 additions & 0 deletions AdColony/AdColonyInstanceMediationSettings.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// AdColonyInstanceMediationSettings.m
// MoPubSDK
//
// Copyright (c) 2016 MoPub. All rights reserved.
//

#import "AdColonyInstanceMediationSettings.h"

@implementation AdColonyInstanceMediationSettings

@end
24 changes: 24 additions & 0 deletions AdColony/AdColonyInterstitialCustomEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// AdColonyInterstitialCustomEvent.h
// MoPubSDK
//
// Copyright (c) 2016 MoPub. All rights reserved.
//

#if __has_include(<MoPub/MoPub.h>)
#import <MoPub/MoPub.h>
#else
#import "MPInterstitialCustomEvent.h"
#endif

/*
* Certified with AdColony 3.2.1
*/

/*
* Please reference the Supported Mediation Partner page at http://bit.ly/2mqsuFH for the
* latest version and ad format certifications.
*/
@interface AdColonyInterstitialCustomEvent : MPInterstitialCustomEvent

@end
92 changes: 92 additions & 0 deletions AdColony/AdColonyInterstitialCustomEvent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// AdColonyInterstitialCustomEvent.m
// MoPubSDK
//
// Copyright (c) 2016 MoPub. All rights reserved.
//

#import <AdColony/AdColony.h>
#import "AdColonyInterstitialCustomEvent.h"
#import "MPLogging.h"
#import "AdColonyController.h"

@interface AdColonyInterstitialCustomEvent ()

@property (nonatomic, retain) AdColonyInterstitial *ad;

@end

@implementation AdColonyInterstitialCustomEvent

#pragma mark - MPInterstitialCustomEvent Subclass Methods

- (void)requestInterstitialWithCustomEventInfo:(NSDictionary *)info {
NSString *appId = [info objectForKey:@"appId"];
if (appId == nil) {
MPLogError(@"Invalid setup. Use the appId parameter when configuring your network in the MoPub website.");
return;
}

NSArray *allZoneIds = [info objectForKey:@"allZoneIds"];
if (allZoneIds.count == 0) {
MPLogError(@"Invalid setup. Use the allZoneIds parameter when configuring your network in the MoPub website.");
return;
}

NSString *zoneId = [info objectForKey:@"zoneId"];
if (zoneId == nil) {
zoneId = allZoneIds[0];
}

NSString *userId = [info objectForKey:@"userId"];

[AdColonyController initializeAdColonyCustomEventWithAppId:appId allZoneIds:allZoneIds userId:userId callback:^{
__weak AdColonyInterstitialCustomEvent *weakSelf = self;
[AdColony requestInterstitialInZone:zoneId options:nil success:^(AdColonyInterstitial * _Nonnull ad) {
weakSelf.ad = ad;

[ad setOpen:^{
MPLogInfo(@"AdColony zone %@ started", zoneId);
[weakSelf.delegate interstitialCustomEventDidAppear:weakSelf];
}];
[ad setClose:^{
MPLogInfo(@"AdColony zone %@ finished", zoneId);
[weakSelf.delegate interstitialCustomEventWillDisappear:weakSelf];
[weakSelf.delegate interstitialCustomEventDidDisappear:weakSelf];
}];
[ad setExpire:^{
MPLogInfo(@"AdColony zone %@ expired", zoneId);
[weakSelf.delegate interstitialCustomEventDidExpire:weakSelf];
}];
[ad setLeftApplication:^{
MPLogInfo(@"AdColony zone %@ click caused application transition", zoneId);
[weakSelf.delegate interstitialCustomEventWillLeaveApplication:weakSelf];
}];
[ad setClick:^{
MPLogInfo(@"AdColony zone %@ ad clicked", zoneId);
[weakSelf.delegate interstitialCustomEventDidReceiveTapEvent:weakSelf];
}];

[weakSelf.delegate interstitialCustomEvent:weakSelf didLoadAd:(id)ad];
} failure:^(AdColonyAdRequestError * _Nonnull error) {
MPLogInfo(@"Failed to load AdColony video interstitial: %@", error);
weakSelf.ad = nil;
[weakSelf.delegate interstitialCustomEvent:weakSelf didFailToLoadAdWithError:error];
}];

}];
}

- (void)showInterstitialFromRootViewController:(UIViewController *)rootViewController {
if (self.ad) {
if ([self.ad showWithPresentingViewController:rootViewController]) {
[self.delegate interstitialCustomEventWillAppear:self];
} else {
MPLogInfo(@"Failed to show AdColony video");
}
} else {
MPLogInfo(@"Failed to show AdColony video, ad is not available");
}
}

@end
Loading

0 comments on commit 55e2ef2

Please sign in to comment.