diff --git a/ChangeLog.txt b/ChangeLog.txt index d0ff092ef..644a79a4e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,15 @@ Google Mobile Ads Unity Plugin Change Log +************* +Version 3.1.2 +************* +- Fix NPE when ad events are not hooked up. + +Built and tested with: +- Google Play services 9.8.0 +- Google Mobile Ads iOS SDK 7.13.0 +- Unity Jar Resolver 1.2.2.0 + ************* Version 3.1.1 ************* diff --git a/source/plugin/Assets/GoogleMobileAds/Api/AdLoader.cs b/source/plugin/Assets/GoogleMobileAds/Api/AdLoader.cs index 7f90ad29c..edeb0c67d 100644 --- a/source/plugin/Assets/GoogleMobileAds/Api/AdLoader.cs +++ b/source/plugin/Assets/GoogleMobileAds/Api/AdLoader.cs @@ -39,16 +39,21 @@ private AdLoader(Builder builder) this.AdTypes = new HashSet(builder.AdTypes); this.adLoaderClient = GoogleMobileAdsClientFactory.BuildAdLoaderClient(this); - this.adLoaderClient.OnCustomNativeTemplateAdLoaded += - delegate(object sender, CustomNativeEventArgs args) - { - this.OnCustomNativeTemplateAdLoaded(this, args); - }; - this.adLoaderClient.OnAdFailedToLoad += delegate( - object sender, AdFailedToLoadEventArgs args) - { - this.OnAdFailedToLoad(this, args); - }; + this.adLoaderClient.OnCustomNativeTemplateAdLoaded += (sender, args) => + { + if(this.OnCustomNativeTemplateAdLoaded != null) + { + this.OnCustomNativeTemplateAdLoaded(this, args); + } + }; + + this.adLoaderClient.OnAdFailedToLoad += (sender, args) => + { + if(this.OnAdFailedToLoad != null) + { + this.OnAdFailedToLoad(this, args); + } + }; } public event EventHandler OnAdFailedToLoad; diff --git a/source/plugin/Assets/GoogleMobileAds/Api/AdLoader.cs.meta b/source/plugin/Assets/GoogleMobileAds/Api/AdLoader.cs.meta new file mode 100644 index 000000000..c5ea30758 --- /dev/null +++ b/source/plugin/Assets/GoogleMobileAds/Api/AdLoader.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f5474196001554b6da135319d9475e61 +timeCreated: 1477084497 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs b/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs index 330b8d008..20fa4dcf7 100644 --- a/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs +++ b/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs @@ -20,7 +20,7 @@ namespace GoogleMobileAds.Api { public class AdRequest { - public const string Version = "3.1.1"; + public const string Version = "3.1.2"; public const string TestDeviceSimulator = "SIMULATOR"; public class Builder diff --git a/source/plugin/Assets/GoogleMobileAds/Api/BannerView.cs b/source/plugin/Assets/GoogleMobileAds/Api/BannerView.cs index b25fe336b..373b20c3c 100644 --- a/source/plugin/Assets/GoogleMobileAds/Api/BannerView.cs +++ b/source/plugin/Assets/GoogleMobileAds/Api/BannerView.cs @@ -23,11 +23,11 @@ public class BannerView private IBannerClient client; // These are the ad callback events that can be hooked into. - public event EventHandler OnAdLoaded = delegate {}; - public event EventHandler OnAdFailedToLoad = delegate {}; - public event EventHandler OnAdOpening = delegate {}; - public event EventHandler OnAdClosed = delegate {}; - public event EventHandler OnAdLeavingApplication = delegate {}; + public event EventHandler OnAdLoaded; + public event EventHandler OnAdFailedToLoad; + public event EventHandler OnAdOpening; + public event EventHandler OnAdClosed; + public event EventHandler OnAdLeavingApplication; // Creates a BannerView and adds it to the view hierarchy. public BannerView(string adUnitId, AdSize adSize, AdPosition position) @@ -35,30 +35,45 @@ public BannerView(string adUnitId, AdSize adSize, AdPosition position) client = GoogleMobileAdsClientFactory.BuildBannerClient(); client.CreateBannerView(adUnitId, adSize, position); - client.OnAdLoaded += delegate(object sender, EventArgs args) - { - OnAdLoaded(this, args); - }; + this.client.OnAdLoaded += (sender, args) => + { + if(this.OnAdLoaded != null) + { + this.OnAdLoaded(this, args); + } + }; - client.OnAdFailedToLoad += delegate(object sender, AdFailedToLoadEventArgs args) - { - OnAdFailedToLoad(this, args); - }; + this.client.OnAdFailedToLoad += (sender, args) => + { + if(this.OnAdLoaded != null) + { + this.OnAdLoaded(this, args); + } + }; - client.OnAdOpening += delegate(object sender, EventArgs args) - { - OnAdOpening(this, args); - }; + this.client.OnAdOpening += (sender, args) => + { + if(this.OnAdOpening != null) + { + this.OnAdOpening(this, args); + } + }; - client.OnAdClosed += delegate(object sender, EventArgs args) - { - OnAdClosed(this, args); - }; + this.client.OnAdClosed += (sender, args) => + { + if(this.OnAdClosed != null) + { + this.OnAdClosed(this, args); + } + }; - client.OnAdLeavingApplication += delegate(object sender, EventArgs args) - { - OnAdLeavingApplication(this, args); - }; + this.client.OnAdLeavingApplication += (sender, args) => + { + if(this.OnAdLeavingApplication != null) + { + this.OnAdLeavingApplication(this, args); + } + }; } // Loads an ad into the BannerView. diff --git a/source/plugin/Assets/GoogleMobileAds/Api/CustomNativeEventArgs.cs.meta b/source/plugin/Assets/GoogleMobileAds/Api/CustomNativeEventArgs.cs.meta new file mode 100644 index 000000000..7b9cb1b49 --- /dev/null +++ b/source/plugin/Assets/GoogleMobileAds/Api/CustomNativeEventArgs.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5188b1fa1a1b148ce8e88835595e660d +timeCreated: 1477084497 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/source/plugin/Assets/GoogleMobileAds/Api/CustomNativeTemplateAd.cs.meta b/source/plugin/Assets/GoogleMobileAds/Api/CustomNativeTemplateAd.cs.meta new file mode 100644 index 000000000..30e8c0e49 --- /dev/null +++ b/source/plugin/Assets/GoogleMobileAds/Api/CustomNativeTemplateAd.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6f029b4086c1141ffad2e59dd23f14f4 +timeCreated: 1477084497 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/source/plugin/Assets/GoogleMobileAds/Api/InterstitialAd.cs b/source/plugin/Assets/GoogleMobileAds/Api/InterstitialAd.cs index 8c7b6792f..b783e6355 100644 --- a/source/plugin/Assets/GoogleMobileAds/Api/InterstitialAd.cs +++ b/source/plugin/Assets/GoogleMobileAds/Api/InterstitialAd.cs @@ -34,30 +34,45 @@ public InterstitialAd(string adUnitId) client = GoogleMobileAdsClientFactory.BuildInterstitialClient(); client.CreateInterstitialAd(adUnitId); - client.OnAdLoaded += delegate(object sender, EventArgs args) - { - OnAdLoaded(this, args); - }; + this.client.OnAdLoaded += (sender, args) => + { + if(this.OnAdLoaded != null) + { + this.OnAdLoaded(this, args); + } + }; - client.OnAdFailedToLoad += delegate(object sender, AdFailedToLoadEventArgs args) - { - OnAdFailedToLoad(this, args); - }; + this.client.OnAdFailedToLoad += (sender, args) => + { + if(this.OnAdLoaded != null) + { + this.OnAdLoaded(this, args); + } + }; - client.OnAdOpening += delegate(object sender, EventArgs args) - { - OnAdOpening(this, args); - }; + this.client.OnAdOpening += (sender, args) => + { + if(this.OnAdOpening != null) + { + this.OnAdOpening(this, args); + } + }; - client.OnAdClosed += delegate(object sender, EventArgs args) - { - OnAdClosed(this, args); - }; + this.client.OnAdClosed += (sender, args) => + { + if(this.OnAdClosed != null) + { + this.OnAdClosed(this, args); + } + }; - client.OnAdLeavingApplication += delegate(object sender, EventArgs args) - { - OnAdLeavingApplication(this, args); - }; + this.client.OnAdLeavingApplication += (sender, args) => + { + if(this.OnAdLeavingApplication != null) + { + this.OnAdLeavingApplication(this, args); + } + }; } // Loads an InterstitialAd. diff --git a/source/plugin/Assets/GoogleMobileAds/Api/NativeExpressAdView.cs b/source/plugin/Assets/GoogleMobileAds/Api/NativeExpressAdView.cs index bc6ac2a2d..64c22ceee 100644 --- a/source/plugin/Assets/GoogleMobileAds/Api/NativeExpressAdView.cs +++ b/source/plugin/Assets/GoogleMobileAds/Api/NativeExpressAdView.cs @@ -28,16 +28,45 @@ public NativeExpressAdView(string adUnitId, AdSize adSize, AdPosition position) this.client = GoogleMobileAdsClientFactory.BuildNativeExpressAdClient(); this.client.CreateNativeExpressAdView(adUnitId, adSize, position); - this.client.OnAdLoaded += (sender, args) => this.OnAdLoaded(this, args); - - this.client.OnAdFailedToLoad += (sender, args) => this.OnAdFailedToLoad(this, args); - - this.client.OnAdOpening += (sender, args) => this.OnAdOpening(this, args); - - this.client.OnAdClosed += (sender, args) => this.OnAdClosed(this, args); + this.client.OnAdLoaded += (sender, args) => + { + if(this.OnAdLoaded != null) + { + this.OnAdLoaded(this, args); + } + }; + + this.client.OnAdFailedToLoad += (sender, args) => + { + if(this.OnAdLoaded != null) + { + this.OnAdLoaded(this, args); + } + }; + + this.client.OnAdOpening += (sender, args) => + { + if(this.OnAdOpening != null) + { + this.OnAdOpening(this, args); + } + }; + + this.client.OnAdClosed += (sender, args) => + { + if(this.OnAdClosed != null) + { + this.OnAdClosed(this, args); + } + }; this.client.OnAdLeavingApplication += (sender, args) => - this.OnAdLeavingApplication(this, args); + { + if(this.OnAdLeavingApplication != null) + { + this.OnAdLeavingApplication(this, args); + } + }; } // These are the ad callback events that can be hooked into. diff --git a/source/plugin/Assets/GoogleMobileAds/Api/RewardBasedVideoAd.cs b/source/plugin/Assets/GoogleMobileAds/Api/RewardBasedVideoAd.cs index ba4f3f987..f9f8b7290 100644 --- a/source/plugin/Assets/GoogleMobileAds/Api/RewardBasedVideoAd.cs +++ b/source/plugin/Assets/GoogleMobileAds/Api/RewardBasedVideoAd.cs @@ -50,40 +50,61 @@ private RewardBasedVideoAd() client = GoogleMobileAdsClientFactory.BuildRewardBasedVideoAdClient(); client.CreateRewardBasedVideoAd(); - client.OnAdLoaded += delegate(object sender, EventArgs args) - { - OnAdLoaded(this, args); - }; + this.client.OnAdLoaded += (sender, args) => + { + if (this.OnAdLoaded != null) + { + this.OnAdLoaded(this, args); + } + }; - client.OnAdFailedToLoad += delegate(object sender, AdFailedToLoadEventArgs args) - { - OnAdFailedToLoad(this, args); - }; + this.client.OnAdFailedToLoad += (sender, args) => + { + if (this.OnAdLoaded != null) + { + this.OnAdLoaded(this, args); + } + }; - client.OnAdOpening += delegate(object sender, EventArgs args) - { - OnAdOpening(this, args); - }; + this.client.OnAdOpening += (sender, args) => + { + if (this.OnAdOpening != null) + { + this.OnAdOpening(this, args); + } + }; - client.OnAdStarted += delegate(object sender, EventArgs args) - { - OnAdStarted(this, args); - }; + this.client.OnAdStarted += (sender, args) => + { + if (this.OnAdStarted != null) + { + this.OnAdStarted(this, args); + } + }; - client.OnAdRewarded += delegate(object sender, Reward args) - { - OnAdRewarded(this, args); - }; + this.client.OnAdClosed += (sender, args) => + { + if (this.OnAdClosed != null) + { + this.OnAdClosed(this, args); + } + }; - client.OnAdClosed += delegate(object sender, EventArgs args) - { - OnAdClosed(this, args); - }; + this.client.OnAdLeavingApplication += (sender, args) => + { + if (this.OnAdLeavingApplication != null) + { + this.OnAdLeavingApplication(this, args); + } + }; - client.OnAdLeavingApplication += delegate(object sender, EventArgs args) - { - OnAdLeavingApplication(this, args); - }; + this.client.OnAdRewarded += (sender, args) => + { + if (this.OnAdRewarded != null) + { + this.OnAdRewarded(this, args); + } + }; } // Loads a new reward based video ad request diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/AdLoaderClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/AdLoaderClient.cs index 3cd6667c7..2ba8f2d34 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/AdLoaderClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/AdLoaderClient.cs @@ -59,18 +59,25 @@ public void LoadAd(AdRequest request) public void onCustomTemplateAdLoaded(AndroidJavaObject ad) { - CustomNativeEventArgs args = new CustomNativeEventArgs() { - nativeAd = new CustomNativeTemplateAd(new CustomNativeTemplateClient(ad)) - }; - OnCustomNativeTemplateAdLoaded(this, args); + if (this.OnCustomNativeTemplateAdLoaded != null) + { + CustomNativeEventArgs args = new CustomNativeEventArgs() { + nativeAd = new CustomNativeTemplateAd(new CustomNativeTemplateClient(ad)) + }; + this.OnCustomNativeTemplateAdLoaded(this, args); + } } void onAdFailedToLoad(string errorReason) { - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() { - Message = errorReason - }; - OnAdFailedToLoad(this, args); + if (this.OnAdFailedToLoad != null) + { + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = errorReason + }; + this.OnAdFailedToLoad(this, args); + } } public void onCustomClick(AndroidJavaObject ad, string assetName) diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/AdLoaderClient.cs.meta b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/AdLoaderClient.cs.meta new file mode 100644 index 000000000..26de1aa99 --- /dev/null +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/AdLoaderClient.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5bc0a5f7f000d4027bd3e5192cc1269a +timeCreated: 1477084497 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/BannerClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/BannerClient.cs index ff025c448..b26c1ccc6 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/BannerClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/BannerClient.cs @@ -82,31 +82,46 @@ public void DestroyBannerView() public void onAdLoaded() { - this.OnAdLoaded(this, EventArgs.Empty); + if (this.OnAdLoaded != null) + { + this.OnAdLoaded(this, EventArgs.Empty); + } } public void onAdFailedToLoad(string errorReason) { - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + if (this.OnAdFailedToLoad != null) { - Message = errorReason - }; - this.OnAdFailedToLoad(this, args); + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = errorReason + }; + this.OnAdFailedToLoad(this, args); + } } public void onAdOpened() { - this.OnAdOpening(this, EventArgs.Empty); + if (this.OnAdOpening != null) + { + this.OnAdOpening(this, EventArgs.Empty); + } } public void onAdClosed() { - this.OnAdClosed(this, EventArgs.Empty); + if (this.OnAdClosed != null) + { + this.OnAdClosed(this, EventArgs.Empty); + } } public void onAdLeftApplication() { - this.OnAdLeavingApplication(this, EventArgs.Empty); + if (this.OnAdLeavingApplication != null) + { + this.OnAdLeavingApplication(this, EventArgs.Empty); + } } #endregion diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/CustomNativeTemplateClient.cs.meta b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/CustomNativeTemplateClient.cs.meta new file mode 100644 index 000000000..1e3794ea1 --- /dev/null +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/CustomNativeTemplateClient.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7e76e9223a0d64aa7972f18446dab8ff +timeCreated: 1477084497 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/InterstitialClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/InterstitialClient.cs index dcfb8941c..fa678dd77 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/InterstitialClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/InterstitialClient.cs @@ -98,31 +98,46 @@ public void SetCustomInAppPurchaseProcessor(ICustomInAppPurchaseProcessor proces public void onAdLoaded() { - this.OnAdLoaded(this, EventArgs.Empty); + if (this.OnAdLoaded != null) + { + this.OnAdLoaded(this, EventArgs.Empty); + } } public void onAdFailedToLoad(string errorReason) { - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + if (this.OnAdFailedToLoad != null) { - Message = errorReason - }; - this.OnAdFailedToLoad(this, args); + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = errorReason + }; + this.OnAdFailedToLoad(this, args); + } } public void onAdOpened() { - this.OnAdOpening(this, EventArgs.Empty); + if (this.OnAdOpening != null) + { + this.OnAdOpening(this, EventArgs.Empty); + } } public void onAdClosed() { - this.OnAdClosed(this, EventArgs.Empty); + if (this.OnAdClosed != null) + { + this.OnAdClosed(this, EventArgs.Empty); + } } public void onAdLeftApplication() { - this.OnAdLeavingApplication(this, EventArgs.Empty); + if (this.OnAdLeavingApplication != null) + { + this.OnAdLeavingApplication(this, EventArgs.Empty); + } } #endregion diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/NativeExpressAdClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/NativeExpressAdClient.cs index ab26604e4..1bd75c23d 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/NativeExpressAdClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/NativeExpressAdClient.cs @@ -88,31 +88,46 @@ public void DestroyNativeExpressAdView() public void onAdLoaded() { - this.OnAdLoaded(this, EventArgs.Empty); + if (this.OnAdLoaded != null) + { + this.OnAdLoaded(this, EventArgs.Empty); + } } public void onAdFailedToLoad(string errorReason) { - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + if (this.OnAdFailedToLoad != null) { - Message = errorReason - }; - this.OnAdFailedToLoad(this, args); + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = errorReason + }; + this.OnAdFailedToLoad(this, args); + } } public void onAdOpened() { - this.OnAdOpening(this, EventArgs.Empty); + if (this.OnAdOpening != null) + { + this.OnAdOpening(this, EventArgs.Empty); + } } public void onAdClosed() { - this.OnAdClosed(this, EventArgs.Empty); + if (this.OnAdClosed != null) + { + this.OnAdClosed(this, EventArgs.Empty); + } } public void onAdLeftApplication() { - this.OnAdLeavingApplication(this, EventArgs.Empty); + if (this.OnAdLeavingApplication != null) + { + this.OnAdLeavingApplication(this, EventArgs.Empty); + } } #endregion diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/RewardBasedVideoAdClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/RewardBasedVideoAdClient.cs index 9da9ca561..55f8c6f5d 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/Android/RewardBasedVideoAdClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/Android/RewardBasedVideoAdClient.cs @@ -73,44 +73,66 @@ public void DestroyRewardBasedVideoAd() { void onAdLoaded() { - OnAdLoaded(this, EventArgs.Empty); + if (this.OnAdLoaded != null) + { + this.OnAdLoaded(this, EventArgs.Empty); + } } void onAdFailedToLoad(string errorReason) { - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() { - Message = errorReason - }; - OnAdFailedToLoad(this, args); + if (this.OnAdFailedToLoad != null) + { + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = errorReason + }; + this.OnAdFailedToLoad(this, args); + } } void onAdOpened() { - OnAdOpening(this , EventArgs.Empty); + if (this.OnAdOpening != null) + { + this.OnAdOpening(this, EventArgs.Empty); + } } void onAdStarted() { - OnAdStarted(this, EventArgs.Empty); + if (this.OnAdStarted != null) + { + this.OnAdStarted(this, EventArgs.Empty); + } } void onAdClosed() { - OnAdClosed(this, EventArgs.Empty); + if (this.OnAdClosed != null) + { + this.OnAdClosed(this, EventArgs.Empty); + } } void onAdRewarded(string type, float amount) { - Reward args = new Reward() { - Type = type, - Amount = amount - }; - OnAdRewarded(this, args); + if (this.OnAdRewarded != null) + { + Reward args = new Reward() { + Type = type, + Amount = amount + }; + this.OnAdRewarded(this, args); + } } void onAdLeftApplication() { - OnAdLeavingApplication(this, EventArgs.Empty); + if (this.OnAdLeavingApplication != null) + { + this.OnAdLeavingApplication(this, EventArgs.Empty); + } } #endregion diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/AdLoaderClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/AdLoaderClient.cs index c5e8bf9f2..afeefb61f 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/AdLoaderClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/AdLoaderClient.cs @@ -124,12 +124,16 @@ private static void AdLoaderDidReceiveNativeCustomTemplateAdCallback( client.customNativeTemplateCallbacks.ContainsKey(templateID) ? client.customNativeTemplateCallbacks[templateID] : null; - CustomNativeEventArgs args = new CustomNativeEventArgs() + if (client.OnCustomNativeTemplateAdLoaded != null) { - nativeAd = new CustomNativeTemplateAd(new CustomNativeTemplateClient( - nativeCustomTemplateAd, clickHandler)) - }; - client.OnCustomNativeTemplateAdLoaded(client, args); + CustomNativeEventArgs args = new CustomNativeEventArgs() + { + nativeAd = new CustomNativeTemplateAd(new CustomNativeTemplateClient( + nativeCustomTemplateAd, clickHandler)) + }; + client.OnCustomNativeTemplateAdLoaded(client, args); + } + } [MonoPInvokeCallback(typeof(GADUAdLoaderDidFailToReceiveAdWithErrorCallback))] @@ -137,11 +141,14 @@ private static void AdLoaderDidFailToReceiveAdWithErrorCallback( IntPtr adLoader, string error) { AdLoaderClient client = IntPtrToAdLoaderClient(adLoader); - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + if (client.OnAdFailedToLoad != null) { - Message = error - }; - client.OnAdFailedToLoad(client, args); + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = error + }; + client.OnAdFailedToLoad(client, args); + } } private static AdLoaderClient IntPtrToAdLoaderClient(IntPtr adLoader) diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/BannerClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/BannerClient.cs index 506e81c14..7076a2c4e 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/BannerClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/BannerClient.cs @@ -142,7 +142,10 @@ public void Dispose() private static void AdViewDidReceiveAdCallback(IntPtr bannerClient) { BannerClient client = IntPtrToBannerClient(bannerClient); - client.OnAdLoaded(client, EventArgs.Empty); + if (client.OnAdLoaded != null) + { + client.OnAdLoaded(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADUAdViewDidFailToReceiveAdWithErrorCallback))] @@ -150,32 +153,44 @@ private static void AdViewDidFailToReceiveAdWithErrorCallback( IntPtr bannerClient, string error) { BannerClient client = IntPtrToBannerClient(bannerClient); - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + if (client.OnAdFailedToLoad != null) { - Message = error - }; - client.OnAdFailedToLoad(client, args); + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = error + }; + client.OnAdFailedToLoad(client, args); + } } [MonoPInvokeCallback(typeof(GADUAdViewWillPresentScreenCallback))] private static void AdViewWillPresentScreenCallback(IntPtr bannerClient) { BannerClient client = IntPtrToBannerClient(bannerClient); - client.OnAdOpening(client, EventArgs.Empty); + if (client.OnAdOpening != null) + { + client.OnAdOpening(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADUAdViewDidDismissScreenCallback))] private static void AdViewDidDismissScreenCallback(IntPtr bannerClient) { BannerClient client = IntPtrToBannerClient(bannerClient); - client.OnAdClosed(client, EventArgs.Empty); + if (client.OnAdClosed != null) + { + client.OnAdClosed(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADUAdViewWillLeaveApplicationCallback))] private static void AdViewWillLeaveApplicationCallback(IntPtr bannerClient) { BannerClient client = IntPtrToBannerClient(bannerClient); - client.OnAdLeavingApplication(client, EventArgs.Empty); + if (client.OnAdLeavingApplication != null) + { + client.OnAdLeavingApplication(client, EventArgs.Empty); + } } private static BannerClient IntPtrToBannerClient(IntPtr bannerClient) diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/CustomNativeTemplateClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/CustomNativeTemplateClient.cs index 0e78863bf..cd08e7708 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/CustomNativeTemplateClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/CustomNativeTemplateClient.cs @@ -142,8 +142,12 @@ private static void NativeCustomTemplateDidReceiveClickCallback( IntPtr nativeCustomAd, string assetName) { CustomNativeTemplateClient client = IntPtrToAdLoaderClient(nativeCustomAd); - CustomNativeTemplateAd nativeAd = new CustomNativeTemplateAd(client); - client.clickHandler(nativeAd, assetName); + if (client.clickHandler != null) + { + CustomNativeTemplateAd nativeAd = new CustomNativeTemplateAd(client); + client.clickHandler(nativeAd, assetName); + } + } private static CustomNativeTemplateClient IntPtrToAdLoaderClient( diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/InterstitialClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/InterstitialClient.cs index 85e3fd9ca..ff27a588a 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/InterstitialClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/InterstitialClient.cs @@ -143,7 +143,10 @@ public void SetCustomInAppPurchaseProcessor(ICustomInAppPurchaseProcessor proces private static void InterstitialDidReceiveAdCallback(IntPtr interstitialClient) { InterstitialClient client = IntPtrToInterstitialClient(interstitialClient); - client.OnAdLoaded(client, EventArgs.Empty); + if (client.OnAdLoaded != null) + { + client.OnAdLoaded(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADUInterstitialDidFailToReceiveAdWithErrorCallback))] @@ -151,32 +154,44 @@ private static void InterstitialDidFailToReceiveAdWithErrorCallback( IntPtr interstitialClient, string error) { InterstitialClient client = IntPtrToInterstitialClient(interstitialClient); - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + if (client.OnAdFailedToLoad != null) { - Message = error - }; - client.OnAdFailedToLoad(client, args); + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = error + }; + client.OnAdFailedToLoad(client, args); + } } [MonoPInvokeCallback(typeof(GADUInterstitialWillPresentScreenCallback))] private static void InterstitialWillPresentScreenCallback(IntPtr interstitialClient) { InterstitialClient client = IntPtrToInterstitialClient(interstitialClient); - client.OnAdOpening(client, EventArgs.Empty); + if (client.OnAdOpening != null) + { + client.OnAdOpening(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADUInterstitialDidDismissScreenCallback))] private static void InterstitialDidDismissScreenCallback(IntPtr interstitialClient) { InterstitialClient client = IntPtrToInterstitialClient(interstitialClient); - client.OnAdClosed(client, EventArgs.Empty); + if (client.OnAdClosed != null) + { + client.OnAdClosed(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADUInterstitialWillLeaveApplicationCallback))] private static void InterstitialWillLeaveApplicationCallback(IntPtr interstitialClient) { InterstitialClient client = IntPtrToInterstitialClient(interstitialClient); - client.OnAdLeavingApplication(client, EventArgs.Empty); + if (client.OnAdLeavingApplication != null) + { + client.OnAdLeavingApplication(client, EventArgs.Empty); + } } private static InterstitialClient IntPtrToInterstitialClient(IntPtr interstitialClient) diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/NativeExpressAdClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/NativeExpressAdClient.cs index 2094e0a44..a82e5845c 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/NativeExpressAdClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/NativeExpressAdClient.cs @@ -132,7 +132,10 @@ public void Dispose() private static void NativeExpressAdViewDidReceiveAdCallback(IntPtr nativeExpressClient) { NativeExpressAdClient client = IntPtrToNativeExpressAdClient(nativeExpressClient); - client.OnAdLoaded(client, EventArgs.Empty); + if(client.OnAdLoaded != null) + { + client.OnAdLoaded(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADUNativeExpressAdViewDidFailToReceiveAdWithErrorCallback))] @@ -140,32 +143,44 @@ private static void NativeExpressAdViewDidFailToReceiveAdWithErrorCallback( IntPtr nativeExpressClient, string error) { NativeExpressAdClient client = IntPtrToNativeExpressAdClient(nativeExpressClient); - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + if(client.OnAdFailedToLoad != null) { - Message = error - }; - client.OnAdFailedToLoad(client, args); + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = error + }; + client.OnAdFailedToLoad(client, args); + } } [MonoPInvokeCallback(typeof(GADUNativeExpressAdViewWillPresentScreenCallback))] private static void NativeExpressAdViewWillPresentScreenCallback(IntPtr nativeExpressClient) { NativeExpressAdClient client = IntPtrToNativeExpressAdClient(nativeExpressClient); - client.OnAdOpening(client, EventArgs.Empty); + if(client.OnAdOpening != null) + { + client.OnAdOpening(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADUNativeExpressAdViewDidDismissScreenCallback))] private static void NativeExpressAdViewDidDismissScreenCallback(IntPtr nativeExpressClient) { NativeExpressAdClient client = IntPtrToNativeExpressAdClient(nativeExpressClient); - client.OnAdClosed(client, EventArgs.Empty); + if(client.OnAdClosed != null) + { + client.OnAdClosed(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADUNativeExpressAdViewWillLeaveApplicationCallback))] private static void NativeExpressAdViewWillLeaveApplicationCallback(IntPtr nativeExpressClient) { NativeExpressAdClient client = IntPtrToNativeExpressAdClient(nativeExpressClient); - client.OnAdLeavingApplication(client, EventArgs.Empty); + if(client.OnAdLeavingApplication != null) + { + client.OnAdLeavingApplication(client, EventArgs.Empty); + } } private static NativeExpressAdClient IntPtrToNativeExpressAdClient(IntPtr nativeExpressAdClient) diff --git a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/RewardBasedVideoAdClient.cs b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/RewardBasedVideoAdClient.cs index deab0ff80..82b238f85 100644 --- a/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/RewardBasedVideoAdClient.cs +++ b/source/plugin/Assets/GoogleMobileAds/Platforms/iOS/RewardBasedVideoAdClient.cs @@ -146,7 +146,10 @@ private static void RewardBasedVideoAdDidReceiveAdCallback(IntPtr rewardBasedVid { RewardBasedVideoAdClient client = IntPtrToRewardBasedVideoClient( rewardBasedVideoAdClient); - client.OnAdLoaded(client, EventArgs.Empty); + if (client.OnAdLoaded != null) + { + client.OnAdLoaded(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADURewardBasedVideoAdDidFailToReceiveAdWithErrorCallback))] @@ -155,11 +158,14 @@ private static void RewardBasedVideoAdDidFailToReceiveAdWithErrorCallback( { RewardBasedVideoAdClient client = IntPtrToRewardBasedVideoClient( rewardBasedVideoAdClient); - AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + if (client.OnAdFailedToLoad != null) { - Message = error - }; - client.OnAdFailedToLoad(client, args); + AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs() + { + Message = error + }; + client.OnAdFailedToLoad(client, args); + } } [MonoPInvokeCallback(typeof(GADURewardBasedVideoAdDidOpenCallback))] @@ -167,7 +173,10 @@ private static void RewardBasedVideoAdDidOpenCallback(IntPtr rewardBasedVideoAdC { RewardBasedVideoAdClient client = IntPtrToRewardBasedVideoClient( rewardBasedVideoAdClient); - client.OnAdOpening(client, EventArgs.Empty); + if (client.OnAdOpening != null) + { + client.OnAdOpening(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADURewardBasedVideoAdDidStartCallback))] @@ -175,7 +184,10 @@ private static void RewardBasedVideoAdDidStartCallback(IntPtr rewardBasedVideoAd { RewardBasedVideoAdClient client = IntPtrToRewardBasedVideoClient( rewardBasedVideoAdClient); - client.OnAdStarted(client, EventArgs.Empty); + if (client.OnAdStarted != null) + { + client.OnAdStarted(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADURewardBasedVideoAdDidCloseCallback))] @@ -183,21 +195,27 @@ private static void RewardBasedVideoAdDidCloseCallback(IntPtr rewardBasedVideoAd { RewardBasedVideoAdClient client = IntPtrToRewardBasedVideoClient( rewardBasedVideoAdClient); - client.OnAdClosed(client, EventArgs.Empty); + if (client.OnAdClosed != null) + { + client.OnAdClosed(client, EventArgs.Empty); + } } [MonoPInvokeCallback(typeof(GADURewardBasedVideoAdDidRewardCallback))] private static void RewardBasedVideoAdDidRewardUserCallback( IntPtr rewardBasedVideoAdClient, string rewardType, double rewardAmount) { - Reward args = new Reward() - { - Type = rewardType, - Amount = rewardAmount - }; RewardBasedVideoAdClient client = IntPtrToRewardBasedVideoClient( rewardBasedVideoAdClient); - client.OnAdRewarded(client, args); + if (client.OnAdRewarded != null) + { + Reward args = new Reward() + { + Type = rewardType, + Amount = rewardAmount + }; + client.OnAdRewarded(client, args); + } } [MonoPInvokeCallback(typeof(GADURewardBasedVideoAdWillLeaveApplicationCallback))] @@ -206,7 +224,10 @@ private static void RewardBasedVideoAdWillLeaveApplicationCallback( { RewardBasedVideoAdClient client = IntPtrToRewardBasedVideoClient( rewardBasedVideoAdClient); - client.OnAdLeavingApplication(client, EventArgs.Empty); + if (client.OnAdLeavingApplication != null) + { + client.OnAdLeavingApplication(client, EventArgs.Empty); + } } private static RewardBasedVideoAdClient IntPtrToRewardBasedVideoClient(