Updated to support AdMob Dashboard change - certification process phase 2
MODIFY
adapters/Vungle/VungleAdapter/GADMAdapterVungleInterstitial.m
adapters/Vungle/VungleAdapter/GADMAdapterVungleInterstitial.m
#import "GADMAdapterVungleInterstitial.h"
#import "vungleHelper.h"
-static NSString *const kGADMAdapterVungleInterstitialKeyApplicationID = @"application_id";
-
@interface GADMAdapterVungleInterstitial () <VungleDelegate>
@property(nonatomic, weak) id<GADMAdNetworkConnector> connector;
@end
@@ -32,8 +30,7 @@ static NSString *const kGADMAdapterVungleInterstitialKeyApplicationID = @"applic
}
- (void)getBannerWithSize:(GADAdSize)adSize{
- NSError *error =
- [NSError errorWithDomain:@"google"
+ NSError *error = [NSError errorWithDomain:@"google"
code:0
userInfo:@{
NSLocalizedDescriptionKey : @"Vungle doesn't support banner ads."
@@ -46,24 +43,24 @@ static NSString *const kGADMAdapterVungleInterstitialKeyApplicationID = @"applic
}
- (void)getInterstitial {
- VungleAdNetworkExtras *extras = [_connector networkExtras];
- desiredPlacement = extras.playingPlacement;
- if (!extras || !extras.allPlacements || [extras.allPlacements count] == 0) {
- NSLog(@"Placements should be specified!");
- [_connector
- adapter:self
+ [vungleHelper parseServerParameters:[_connector credentials]
+ networkExtras:[_connector networkExtras]
+ result:^void(NSDictionary* error, NSString* appId, NSArray* placements) {
+ if (error) {
+ [_connector adapter:self
didFailAd:[NSError errorWithDomain:@"GADMAdapterVungleInterstitial"
code:0
- userInfo:@{
- NSLocalizedDescriptionKey : @"Placements should be specified!"
- }]];
+ userInfo:error]];
return;
}
+ desiredPlacement = [vungleHelper findPlacement:[_connector credentials] networkExtras:[_connector networkExtras]];
+ if (!desiredPlacement) {
+ desiredPlacement = [placements firstObject];
+ NSLog(@"'placementID' not specified. Used first from 'allPlacements': %@", desiredPlacement);
+ }
waitingInit = YES;
- NSDictionary *serverParameters = [_connector credentials];
- NSString *applicationID =
- [serverParameters objectForKey:kGADMAdapterVungleInterstitialKeyApplicationID];
- [[vungleHelper sharedInstance] initWithAppId:applicationID placements:extras.allPlacements];
+ [[vungleHelper sharedInstance] initWithAppId:appId placements:placements];
+ }];
}
- (void)stopBeingDelegate {

MODIFY
adapters/Vungle/VungleAdapter/GADMAdapterVungleRewardBasedVideoAd.m
adapters/Vungle/VungleAdapter/GADMAdapterVungleRewardBasedVideoAd.m
#import "vungleHelper.h"
#import "VungleAdNetworkExtras.h"
-static NSString *const kGADMAdapterVungleRewardBasedVideoAdKeyApplicationID = @"application_id";
-
@interface GADMAdapterVungleRewardBasedVideoAd () <VungleDelegate>
@property(nonatomic, weak) id<GADMRewardBasedVideoAdNetworkConnector> connector;
@end
@@ -34,27 +32,26 @@ static NSString *const kGADMAdapterVungleRewardBasedVideoAdKeyApplicationID = @"
}
- (void)setUp {
- NSDictionary *serverParameters = [_connector credentials];
- NSString *applicationID =
- [serverParameters objectForKey:kGADMAdapterVungleRewardBasedVideoAdKeyApplicationID];
- VungleAdNetworkExtras *extras = [_connector networkExtras];
- if (!extras || !extras.allPlacements || [extras.allPlacements count] == 0) {
- NSLog(@"Placements should be specified!");
- [_connector adapter:self
- didFailToSetUpRewardBasedVideoAdWithError:
- [NSError errorWithDomain:@"GADMAdapterVungleRewardBasedVideoAd"
+ [vungleHelper parseServerParameters:[_connector credentials]
+ networkExtras:[_connector networkExtras]
+ result:^void(NSDictionary* error, NSString* appId, NSArray* placements) {
+ if (error) {
+ [_connector adapter:self didFailToSetUpRewardBasedVideoAdWithError:[NSError errorWithDomain:@"GADMAdapterVungleRewardBasedVideoAd"
code:0
- userInfo:@{
- NSLocalizedDescriptionKey : @"Placements should be specified!"
- }]];
+ userInfo:error]];
return;
}
waitingInit = YES;
- [[vungleHelper sharedInstance] initWithAppId:applicationID placements:extras.allPlacements];
+ [[vungleHelper sharedInstance] initWithAppId:appId placements:placements];
+ }];
}
- (void)requestRewardBasedVideoAd {
- desiredPlacement = ((VungleAdNetworkExtras *)[_connector networkExtras]).playingPlacement;
+ desiredPlacement = [vungleHelper findPlacement:[_connector credentials] networkExtras:[_connector networkExtras]];
+ if (!desiredPlacement) {
+ desiredPlacement = [[vungleHelper sharedInstance].allPlacements firstObject];
+ NSLog(@"'placementID' not specified. Used first one from 'allPlacements': %@", desiredPlacement);
+ }
[[vungleHelper sharedInstance] loadAd:desiredPlacement];
}
@@ -101,8 +98,7 @@ static NSString *const kGADMAdapterVungleRewardBasedVideoAdKeyApplicationID = @"
-(void)willCloseAd:(bool)completedView{
if (completedView){
- GADAdReward *reward =
- [[GADAdReward alloc] initWithRewardType:@"vungle"
+ GADAdReward* reward = [[GADAdReward alloc] initWithRewardType:@"vungle"
rewardAmount:[NSDecimalNumber decimalNumberWithString:@"1"]];
[_connector adapter:self didRewardUserWithReward:reward];
}

MODIFY
adapters/Vungle/VungleAdapter/vungleHelper.h
adapters/Vungle/VungleAdapter/vungleHelper.h
@interface vungleHelper : NSObject<VungleSDKDelegate>
@property(readonly) BOOL isInitialising;
+@property(readonly, strong) NSArray *allPlacements;
+typedef void(^ParameterCB)(NSDictionary*, NSString*, NSArray<NSString*>*);
+ (NSString *)adapterVersion;
+ (vungleHelper *)sharedInstance;
++ (void)parseServerParameters:(NSDictionary*)serverParameters networkExtras:(VungleAdNetworkExtras*)networkExtras result:(ParameterCB)result;
++ (NSString*)findPlacement:(NSDictionary*)serverParameters networkExtras:(VungleAdNetworkExtras*)networkExtras;
- (void)initWithAppId:(NSString *)appId placements:(NSArray<NSString *>*)placements;
-- (BOOL)playAd:(UIViewController *)viewController
- delegate:(id<VungleDelegate>)delegate
- extras:(VungleAdNetworkExtras *)extras;
+- (BOOL)playAd:(UIViewController *)viewController delegate:(id<VungleDelegate>)delegate extras:(VungleAdNetworkExtras *)extras;
- (void)loadAd:(NSString *)placement;
- (void)addDelegate:(id<VungleDelegate>)delegate;
- (void)removeDelegate:(id<VungleDelegate>)delegate;

MODIFY
adapters/Vungle/VungleAdapter/vungleHelper.m
adapters/Vungle/VungleAdapter/vungleHelper.m
#import "vungleHelper.h"
+static NSString *const kApplicationID = @"application_id";
+static NSString *const kPlacementID = @"placementID";
+static NSString *const placementsDelimiter = @",";
+
@interface vungleHelper()
@property (strong) NSMutableArray<id<VungleDelegate>> * delegates;
@property (strong) id<VungleDelegate> playingDelegate;
@implementation vungleHelper
+
+ (NSString *)adapterVersion {
return @"5.1.0";
}
-(void)initWithAppId:(NSString *)appId placements:(NSArray<NSString *>*)placements{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- NSString *version =
- [[vungleHelper adapterVersion] stringByReplacingOccurrencesOfString:@"." withString:@"_"];
+ NSString *version = [[vungleHelper adapterVersion] stringByReplacingOccurrencesOfString:@"." withString:@"_"];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
[[VungleSDK sharedSDK] performSelector:@selector(setPluginName:version:)
_isInitialising = true;
NSError* err = nil;
+ _allPlacements = placements;
[sdk startWithAppId:appId placements:placements error:&err];
if (err) {
[self initialized:false error:err];
}
}
++(void)parseServerParameters:(NSDictionary*)serverParameters networkExtras:(VungleAdNetworkExtras*)networkExtras result:(ParameterCB)result {
+ NSMutableArray* allPlacements = [NSMutableArray array];
+ if (networkExtras && networkExtras.allPlacements && [networkExtras.allPlacements count] > 0) {
+ [allPlacements addObjectsFromArray:networkExtras.allPlacements];
+ }
+
+ if (!serverParameters || ![serverParameters objectForKey:kApplicationID]) {
+ NSLog(@"Vungle app ID should be specified!");
+ result(@{NSLocalizedDescriptionKey: @"Vungle app ID should be specified!"}, nil, nil);
+ return;
+ }
+ NSString* appId = [serverParameters objectForKey:kApplicationID];
+ if ([appId containsString:placementsDelimiter]){
+ NSMutableArray* parts = [[appId componentsSeparatedByString:placementsDelimiter] mutableCopy];
+ appId = [parts objectAtIndex:0];
+ [parts removeObjectAtIndex:0];
+ if (allPlacements.count > 0) {
+ NSLog(@"'allPlacements' had a value in both serverParameters and networkExtras. Used combined value");
+ }
+ for(NSString* placement in parts) {
+ if (placement.length > 0 && ![allPlacements containsObject:placement]) {
+ [allPlacements addObject:placement];
+ }
+ }
+ }
+
+ if (allPlacements.count == 0) {
+ NSLog(@"At least one placement should be specified!");
+ result(@{NSLocalizedDescriptionKey: @"At least one placement should be specified!"}, nil, nil);
+ return;
+ }
+ result(nil, appId, allPlacements);
+}
+
++(NSString*)findPlacement:(NSDictionary*)serverParameters networkExtras:(VungleAdNetworkExtras*)networkExtras {
+ NSString* ret = nil;
+ if (serverParameters && [serverParameters objectForKey:kPlacementID]) {
+ ret = [serverParameters objectForKey:kPlacementID];
+ }
+ if (networkExtras && networkExtras.playingPlacement) {
+ if (ret)
+ NSLog(@"'placementID' had a value in both serverParameters and networkExtras. Used one from serverParameters");
+ else
+ ret = networkExtras.playingPlacement;
+ }
+
+ return ret;
+}
+
-(void)addDelegate:(id<VungleDelegate>)delegate {
if (delegate && ![_delegates containsObject:delegate]) {
[_delegates addObject:delegate];
}
}
-- (BOOL)playAd:(UIViewController *)viewController
- delegate:(id<VungleDelegate>)delegate
- extras:(VungleAdNetworkExtras *)extras {
- if (!delegate || !delegate.desiredPlacement ||
- ![[VungleSDK sharedSDK] isAdCachedForPlacementID:delegate.desiredPlacement]) {
+- (BOOL)playAd:(UIViewController *)viewController delegate:(id<VungleDelegate>)delegate extras:(VungleAdNetworkExtras *)extras {
+ if (!delegate || !delegate.desiredPlacement || ![[VungleSDK sharedSDK] isAdCachedForPlacementID:delegate.desiredPlacement]) {
return false;
}
NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
NSError *error = nil;
bool startPlaying = true;
[VungleSDK sharedSDK].muted = extras.muted;
- if (extras.userId) [options setObject:extras.userId forKey:VunglePlayAdOptionKeyUser];
+ if (extras.userId)
+ [options setObject:extras.userId forKey:VunglePlayAdOptionKeyUser];
if (![[VungleSDK sharedSDK] playAd:viewController
options:options
placementID:delegate.desiredPlacement
startPlaying = false;
}
if (error) {
- NSLog(@"Adapter failed to present reward based video ad, error %@",
- [error localizedDescription]);
+ NSLog(@"Adapter failed to present reward based video ad, error %@", [error localizedDescription]);
startPlaying = false;
};
if (startPlaying) {
}
}
-- (void)vungleWillCloseAdWithViewInfo:(nonnull VungleViewInfo *)info
- placementID:(nonnull NSString *)placementID {
+- (void)vungleWillCloseAdWithViewInfo:(nonnull VungleViewInfo *)info placementID:(nonnull NSString *)placementID {
if (_playingDelegate) {
[_playingDelegate willCloseAd:info.completedView];
}

Updated to support AdMob Dashboard change - certification process phase 2