Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

Admob on iOS and Android. Interstitial ads are showing but events are not firing.

$
0
0
When I tested demo scene from the admob plugin for unity in empty project - the interstitial ads were showing and events were fired well. But when I am trying to integrate the plugin with my game - the interstitial ads are showing but events are not firing. I thought that it caused because of another plugin integrated with my game, but I tried also remove all the plugins and integrate only admob, and interstitial ads are showing but events still are not firing. Here is my AdMobManager: using System; using UnityEngine; using System.Collections; using GoogleMobileAds.Api; public class AdMobManager : MonoBehaviour { public static AdMobManager Instance{ get; private set; } private InterstitialAd _interstitial; private Action _callback; #if UNITY_ANDROID string adUnitId = "MyAdUnitId"; #elif UNITY_IPHONE string adUnitId = "MyAdUnitId"; #else string adUnitId = "unexpected_platform"; #endif void Awake(){ if (Instance == null) Instance = this; else if (Instance != null) Destroy (gameObject); DontDestroyOnLoad (gameObject); } void Start(){ // Initialize an InterstitialAd. //_interstitial = new InterstitialAd(adUnitId); //SignEventsToHandlers (); } //Events handlers void OnAdClosed (object sender, System.EventArgs e){ Debug.Log (string.Format ("AdMob.AdClosed - OK. sender: {0}, eventArgs: {1}", sender, e)); if (_callback != null) _callback(); else Debug.Log("_callback is null"); } void OnAdClosing (object sender, System.EventArgs e){ Debug.Log (string.Format ("AdMob.AdClosing - OK. sender: {0}, eventArgs: {1}", sender, e)); } //void OnAdFailedLoad (object sender, AdFailedToLoadEventArgs e){ // Debug.Log (string.Format ("AdMob.AdFailedLoad - OK. sender: {0}, eventArgs: {1}", sender, e)); //} //void OnAdLeftApplication (object sender, System.EventArgs e){ // Debug.Log (string.Format ("AdMob.AdLeftApplication - OK. sender: {0}, eventArgs: {1}", sender, e)); //} private void OnAdLoaded(object sender, System.EventArgs e){ Debug.Log(string.Format("AdMob.AdLoaded - OK. sender: {0}, eventArgs: {1}", sender, e)); } private void OnAdOpened(object sender, System.EventArgs e){ Debug.Log(string.Format("AdMob.AdOpened - OK. sender: {0}, eventArgs: {1}", sender, e)); } //Public interface public void ShowInterstital(Action callback){ //if (IapManager.Instance.IsXlPackBought) return; _callback = callback; if (_interstitial.IsLoaded()) _interstitial.Show(); } //TODO: Every time to show interstital animation I need to request this ad from server, check if it was loaded successfully and then show it //TODO: Or mayby to see on events. Maybe there event something like this: OnInterstitial loaded; //Actions public void RequestInterstitial(){ // Create an empty ad request. #if UNITY_IOS AdRequest request = new AdRequest.Builder ().AddTestDevice (GameTools.GetIOSAdMobID ()).Build (); // Load the interstitial with the request. _interstitial.LoadAd(request); #endif #if UNITY_ANDROID _interstitial = new InterstitialAd(adUnitId); _interstitial.AdClosed += OnAdClosed; _interstitial.AdClosing += OnAdClosing; _interstitial.AdLoaded += OnAdLoaded; _interstitial.AdOpened += OnAdOpened; AdRequest request = new AdRequest.Builder() .AddTestDevice(AdRequest.TestDeviceSimulator) .AddTestDevice("E6CDB888557BA9A0") // My device ID .AddKeyword("game") .SetGender(Gender.Male) .SetBirthday(new DateTime(1985, 1, 1)) .TagForChildDirectedTreatment(false) .AddExtra("color_bg", "9B30FF") .Build(); _interstitial.LoadAd(request); #endif }

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>