Remove duplicates from Initializer and move Banner logic to BannerAd class
Remove duplicates from Initializer and move Banner logic to BannerAd class
MODIFY
adapters/Unity/UnityAdapter/GADMAdapterUnityBannerAd.m
adapters/Unity/UnityAdapter/GADMAdapterUnityBannerAd.m
return;
}
+ GADAdSize supportedSize = [self supportedAdSizeFromRequestedSize:adSize];
+ if (!IsGADAdSizeValid(supportedSize)) {
+ NSString *errorMsg = [NSString
+ stringWithFormat:
+ @"UnityAds supported banner sizes are not a good fit for the requested size: %@",
+ NSStringFromGADAdSize(adSize)];
+ NSError *error =
+ GADMAdapterUnityErrorWithCodeAndDescription(GADMAdapterUnityErrorSizeMismatch, errorMsg);
+ [strongConnector adapter:strongAdapter didFailAd:error];
+ return;
+ }
+
if (![UnityAds isInitialized]) {
[[GADMAdapterUnity alloc] initializeWithGameID:_gameID withInitDelegate:Nil];
}
_bannerAd.delegate = nil;
}
+// Find closest supported ad size from a given ad size.
+- (GADAdSize)supportedAdSizeFromRequestedSize:(GADAdSize)gadAdSize {
+ NSArray *potentials =
+ @[ NSValueFromGADAdSize(kGADAdSizeBanner), NSValueFromGADAdSize(kGADAdSizeLeaderboard) ];
+ return GADClosestValidSizeForAdSizes(gadAdSize, potentials);
+}
+
#pragma mark UADSBannerView Delegate methods
- (void)bannerViewDidLoad:(UADSBannerView *)bannerView {

MODIFY
adapters/Unity/UnityAdapter/GADMUnityInitializer.m
adapters/Unity/UnityAdapter/GADMUnityInitializer.m
- (void)getInterstitial {
id<GADMAdNetworkConnector> strongConnector = _networkConnector;
- if (!strongConnector) return;
- _gameID = [[[strongConnector credentials] objectForKey:kGADMAdapterUnityGameID] copy];
+
_interstitialAd = [[GADMUnityInterstitialAd alloc] initWithGADMAdNetworkConnector:strongConnector adapter:self];
- if (!_interstitialAd) {
- NSString *description = [NSString
- stringWithFormat:@"%@ initialization failed!", NSStringFromClass([GADMUnityInterstitialAd class])];
- NSError *error = GADMAdapterUnityErrorWithCodeAndDescription(GADMAdapterUnityErrorAdInitializationFailure, description);
- [strongConnector adapter:self didFailAd:error];
- return;
- }
[_interstitialAd getInterstitial];
}
- (void)presentInterstitialFromRootViewController:(UIViewController *)rootViewController {
- id<GADMAdNetworkConnector> strongConnector = _networkConnector;
- if (strongConnector) {
- [strongConnector adapterWillPresentInterstitial:self];
- }
[_interstitialAd presentInterstitialFromRootViewController:rootViewController];
}
- (void)getBannerWithSize:(GADAdSize)adSize {
id<GADMAdNetworkConnector> strongConnector = _networkConnector;
- if (!strongConnector) {
- NSLog(@"Adapter Error: No GADMAdNetworkConnector found.");
-
- return;
- }
- GADAdSize supportedSize = [self supportedAdSizeFromRequestedSize:adSize];
- if (!IsGADAdSizeValid(supportedSize)) {
- NSString *errorMsg = [NSString
- stringWithFormat:
- @"UnityAds supported banner sizes are not a good fit for the requested size: %@",
- NSStringFromGADAdSize(adSize)];
- NSError *error =
- GADMAdapterUnityErrorWithCodeAndDescription(GADMAdapterUnityErrorSizeMismatch, errorMsg);
- [strongConnector adapter:self didFailAd:error];
- return;
- }
- _gameID = [strongConnector.credentials[kGADMAdapterUnityGameID] copy];
- _placementID = [strongConnector.credentials[kGADMAdapterUnityPlacementID] copy];
- if (!_gameID || !_placementID) {
- NSError *error = GADMAdapterUnityErrorWithCodeAndDescription( GADMAdapterUnityErrorInvalidServerParameters, kMISSING_ID_ERROR);
- [strongConnector adapter:self didFailAd:error];
- return;
- }
_bannerAd = [[GADMAdapterUnityBannerAd alloc] initWithGADMAdNetworkConnector:strongConnector
adapter:self];
-
- if (!_bannerAd) {
- NSString *description = [NSString
- stringWithFormat:@"%@ initialization failed!", NSStringFromClass([GADMAdapterUnityBannerAd class])];
- NSError *error = GADMAdapterUnityErrorWithCodeAndDescription(GADMAdapterUnityErrorAdInitializationFailure, description);
- [strongConnector adapter:self didFailAd:error];
- return;
- }
- [_bannerAd loadBannerWithSize:supportedSize];
-}
-
-/// Find closest supported ad size from a given ad size.
-- (GADAdSize)supportedAdSizeFromRequestedSize:(GADAdSize)gadAdSize {
- NSArray *potentials =
- @[ NSValueFromGADAdSize(kGADAdSizeBanner), NSValueFromGADAdSize(kGADAdSizeLeaderboard) ];
- return GADClosestValidSizeForAdSizes(gadAdSize, potentials);
+ [_bannerAd loadBannerWithSize:adSize];
}
@end

Remove duplicates from Initializer and move Banner logic to BannerAd class

Remove duplicates from Initializer and move Banner logic to BannerAd class