Add lazy init into load
Add lazy init into load.
MODIFY
adapters/Unity/UnityAdapter/GADMAdapterUnityBannerAd.m
adapters/Unity/UnityAdapter/GADMAdapterUnityBannerAd.m
/// Unity Ads banner ad object.
UADSBannerView *_bannerAd;
+ /// Unity ads game ID.
+ NSString *_gameID;
+
/// Unity ads placement ID.
NSString *_placementID;
}
id<GADMAdNetworkConnector> strongConnector = _connector;
id<GADMAdNetworkAdapter> strongAdapter = _adapter;
- if (![UnityAds isInitialized]) {
- [GADMAdapterUnity initialize];
- }
-
if (!strongConnector) {
NSLog(@"Unity Ads Adapter Error: No GADMAdNetworkConnector found.");
return;
return;
}
+ _gameID = [[[strongConnector credentials] objectForKey:kGADMAdapterUnityGameID] copy];
_placementID = [strongConnector.credentials[kGADMAdapterUnityPlacementID] copy];
- if (!_placementID) {
+ if (!_gameID || !_placementID) {
NSError *error = GADUnityErrorWithDescription(kMISSING_ID_ERROR);
[strongConnector adapter:strongAdapter didFailAd:error];
return;
}
+
+ if (![UnityAds isInitialized]) {
+ [[GADMAdapterUnity alloc] initializeWithGameID:_gameID withInitDelegate:Nil];
+ }
+
_bannerAd = [[UADSBannerView alloc] initWithPlacementId:_placementID size:adSize.size];
if (!_bannerAd) {
NSError *error = GADMAdapterUnityErrorWithCodeAndDescription(GADMAdapterUnityErrorAdObjectNil, @"Unity banner failed to initialize.");

MODIFY
adapters/Unity/UnityAdapter/GADMAdapterUnityRewardedAd.h
adapters/Unity/UnityAdapter/GADMAdapterUnityRewardedAd.h
#import <Foundation/Foundation.h>
#import <GoogleMobileAds/GoogleMobileAds.h>
#import <UnityAds/UnityAds.h>
+#import "GADMUnityInitializer.h"
@interface GADMAdapterUnityRewardedAd
: NSObject <GADMediationRewardedAd, UnityAdsExtendedDelegate>

MODIFY
adapters/Unity/UnityAdapter/GADMAdapterUnityRewardedAd.m
adapters/Unity/UnityAdapter/GADMAdapterUnityRewardedAd.m
return;
}
+ if (![UnityAds isInitialized]) {
+ [[GADMAdapterUnity alloc] initializeWithGameID:_gameID withInitDelegate:Nil];
+ }
+
[UnityAds addDelegate:self];
[UnityAds load:_placementID loadDelegate:self];
}
newState:(UnityAdsPlacementState)newState {
}
+#pragma mark - UnityLoadDelegate Methods
+
- (void)unityAdsAdFailedToLoad:(nonnull NSString *)placementId {
[UnityAds removeDelegate:self];
if (_adLoadCompletionHandler) {

MODIFY
adapters/Unity/UnityAdapter/GADMUnityInterstitialAd.h
adapters/Unity/UnityAdapter/GADMUnityInterstitialAd.h
#import <Foundation/Foundation.h>
#import <GoogleMobileAds/GoogleMobileAds.h>
-#import <UnityAds/UnityAds.h>'
-
+#import <UnityAds/UnityAds.h>
#import "GADMUnityInitializer.h"
@protocol GADMAdNetworkAdapter;

MODIFY
adapters/Unity/UnityAdapter/GADMUnityInterstitialAd.m
adapters/Unity/UnityAdapter/GADMUnityInterstitialAd.m
id<GADMAdNetworkConnector> strongConnector = _connector;
id<GADMAdNetworkAdapter> strongAdapter = _adapter;
- if (![UnityAds isInitialized]) {
- //[GADMAdapterUnity initializeWithGameID: _gameID withInitDelegate:Nil];
- [GADMAdapterUnity initialize];
- }
-
if (!strongConnector) {
NSLog(@"Unity Ads Adapter Error: No GADMAdNetworkConnector found.");
return;
[strongConnector adapter:strongAdapter didFailAd:error];
return;
}
+
+ if (![UnityAds isInitialized]) {
+ [[GADMAdapterUnity alloc] initializeWithGameID: _gameID withInitDelegate:Nil];
+ }
+
_isLoading = YES;
[UnityAds addDelegate:self];
[UnityAds load:_placementID loadDelegate:self];
// unityAdsAdLoaded.
}
-
-// UnityAdsLoadDelegate methods
+#pragma mark - UnityAdsLoadDelegate Methods
- (void)unityAdsAdFailedToLoad:(nonnull NSString *)placementId {
[UnityAds removeDelegate:self];

Add lazy init into load

Add lazy init into load.