From 535acdbfb7737529184cafea70d1864db672bd97 Mon Sep 17 00:00:00 2001 From: Tina Han Date: Thu, 25 Apr 2019 23:48:55 -0700 Subject: [PATCH] Fix configure check bug and add more config checks --- .../Unity/UnityAdapter/GADMAdapterUnity.m | 38 +++++++++++++------ .../UnityAdapter/GADMAdapterUnitySingleton.m | 2 +- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/adapters/Unity/UnityAdapter/GADMAdapterUnity.m b/adapters/Unity/UnityAdapter/GADMAdapterUnity.m index 690a940a5..d9f9658a6 100644 --- a/adapters/Unity/UnityAdapter/GADMAdapterUnity.m +++ b/adapters/Unity/UnityAdapter/GADMAdapterUnity.m @@ -127,12 +127,19 @@ - (void)getInterstitial { [strongConnector adapter:self didFailAd:error]; return; } - [[GADMAdapterUnitySingleton sharedInstance] configureWithGameID:gameID]; - - if (!_interstitialAd) { - _interstitialAd = [[UADSInterstitialAd alloc] initWithPlacementId:_placementID]; - _interstitialAd.delegate = self; - [_interstitialAd load]; + BOOL isConfigured = [[GADMAdapterUnitySingleton sharedInstance] configureWithGameID:gameID]; + if (!isConfigured) { + NSString *description = + [[NSString alloc] initWithFormat:@"%@ is not supported for this device.", + NSStringFromClass([UnityAds class])]; + NSError *error = GADUnityErrorWithDescription(description); + [strongConnector adapter:self didFailAd:error]; + } else { + if (!_interstitialAd) { + _interstitialAd = [[UADSInterstitialAd alloc] initWithPlacementId:_placementID]; + _interstitialAd.delegate = self; + [_interstitialAd load]; + } } } @@ -156,12 +163,19 @@ - (void)getBannerWithSize:(GADAdSize)adSize { [strongNetworkConnector adapter:self didFailAd:error]; return; } - [[GADMAdapterUnitySingleton sharedInstance] configureWithGameID:gameID]; - - if (!_bannerAd) { - _bannerAd = [[UADSBannerAd alloc] initWithPlacementId:_placementID]; - _bannerAd.delegate = self; - [_bannerAd load]; + BOOL isConfigured = [[GADMAdapterUnitySingleton sharedInstance] configureWithGameID:gameID]; + if (!isConfigured) { + NSString *description = + [[NSString alloc] initWithFormat:@"%@ is not supported for this device.", + NSStringFromClass([UnityAds class])]; + NSError *error = GADUnityErrorWithDescription(description); + [strongNetworkConnector adapter:self didFailAd:error]; + } else { + if (!_bannerAd) { + _bannerAd = [[UADSBannerAd alloc] initWithPlacementId:_placementID]; + _bannerAd.delegate = self; + [_bannerAd load]; + } } } diff --git a/adapters/Unity/UnityAdapter/GADMAdapterUnitySingleton.m b/adapters/Unity/UnityAdapter/GADMAdapterUnitySingleton.m index 375a026e2..85e81a161 100644 --- a/adapters/Unity/UnityAdapter/GADMAdapterUnitySingleton.m +++ b/adapters/Unity/UnityAdapter/GADMAdapterUnitySingleton.m @@ -32,8 +32,8 @@ -(BOOL)configureWithGameID:(NSString *)gameID { if ([UnityAds isSupported]) { if (![UnityAds isInitialized]) { [UnityAds initialize:gameID]; - return YES; } + return YES; } return NO; }