question

pixelelement avatar image
pixelelement asked

Events not triggering Amazon Ads Unity plugin (IOS)

I'm able to get and display an interstitial Ad when I invoke ShowInterstitialAd after waiting about 2 seconds, but my [b]Event Handler methods are not firing/triggering.[/b] This is my code: using UnityEngine; using System.Collections; using com.amazon.mas.cpt.ads; public class DisplayAmazonAd : MonoBehaviour { // Use this for initialization void Start () { // Obtain object used to interact with the plugin IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance; // Register for an event mobileAds.AddAdLoadedListener(AdLoadedEventHandler); // Register for an event mobileAds.AddAdFailedToLoadListener(AdFailedToLoadEventHandler); // Register for an event mobileAds.AddAdDismissedListener(AdDismissedEventHandler); CreateInterstitialAd (); LoadInterstitialAd (); Invoke ("ShowInterstitialAd", 2f); } void CreateInterstitialAd() { Debug.Log ("CreateInterstitialAd()"); // Obtain object used to interact with the plugin IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance; // Call method with no input // This method returns an Ad object, which you must save and keep track of Ad response = mobileAds.CreateInterstitialAd(); // Get return values string adType = response.AdType.ToString(); long identifier = response.Identifier; } void LoadInterstitialAd() { Debug.Log ("LoadInterstitialAd()"); // Obtain object used to interact with the plugin IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance; // Call method with no input // This method returns a LoadingStarted object LoadingStarted response = mobileAds.LoadInterstitialAd(); // Get return value bool loadingStarted = response.BooleanValue; } void ShowInterstitialAd() { Debug.Log ("ShowInterstitialAd()"); // Obtain object used to interact with the plugin IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance; // Call method with no input // This method returns an AdShown object AdShown response = mobileAds.ShowInterstitialAd(); // Get return value bool adShown = response.BooleanValue; } // Define event handler private void AdDismissedEventHandler(Ad args) { Debug.Log ("AdDismissedEventHandler()"); string adType = args.AdType.ToString(); long identifier = args.Identifier; } // Define event handler private void AdFailedToLoadEventHandler(Ad args) { Debug.Log ("AdFailedToLoadEventHandler()"); string adType = args.AdType.ToString(); long identifier = args.Identifier; } // Define event handler private void AdLoadedEventHandler(Ad args) { Debug.Log ("AdLoadedEventHandler()"); string adType = args.AdType.ToString(); long identifier = args.Identifier; } } I would like to call ShowInterstitialAd when AdLoadedEventHandler() is triggered, but for some reason events are not triggering. I'll appreciate any help. Thanks.
mobile ads
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

justin avatar image
justin answered
Hi pixelelement, Sorry for the delay! I've put together a reference on how you could use the event listeners to automatically load an ad as soon as it's ready. In order to do this, we use a coroutine, and the boolean adLoaded, in order to check if the AdLoadedEventHandler() method has executed. You'll also see I've used the AdDismissedHandler, which is ideal for queuing up an ad as soon as you've closed one out. I hope this helps! [code]using UnityEngine; using System.Collections; using com.amazon.mas.cpt.ads; public class MobileAdsTest : MonoBehaviour { IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance; ApplicationKey key = new ApplicationKey(); ShouldEnable shouldEnable = new ShouldEnable(); public bool adLoaded = false; void Start () { InitInterstitialAds(); } void OnEnable () { // Set up event handlers mobileAds.AddAdDismissedListener (AdDismissedHandler); mobileAds.AddAdLoadedListener (AdLoadedEventHandler); } void OnDisable () { // Set up event handler removal mobileAds.RemoveAdDismissedListener (AdDismissedHandler); mobileAds.RemoveAdLoadedListener (AdLoadedEventHandler); } // Create a new slot for interstitial ads then load the first round. public void InitInterstitialAds () { // Set initial properties key.StringValue = "sample-app-v1_pub-2"; shouldEnable.BooleanValue = true; mobileAds.SetApplicationKey (key); mobileAds.EnableLogging (shouldEnable); mobileAds.EnableTesting (shouldEnable); mobileAds.EnableGeoLocation(shouldEnable); // Create interstitial slot Ad interstialAd = mobileAds.CreateInterstitialAd(); // Get return values string adType = interstialAd.AdType.ToString(); long identifier = interstialAd.Identifier; Debug.Log (identifier + " " + adType); // Load first intersitial LoadInterstitialAds (); } #region Ad Methods public void LoadInterstitialAds() { LoadingStarted response = mobileAds.LoadInterstitialAd(); bool loadingStarted = response.BooleanValue; Debug.Log (loadingStarted); } public void ShowInterstitialAds() { AdShown shownInterstitialAd = mobileAds.ShowInterstitialAd(); bool adShown = shownInterstitialAd.BooleanValue; Debug.Log("adShown: " + adShown); } IEnumerator QueueInterstitialAd() { while (!adLoaded) { yield return false; } ShowInterstitialAds(); } #endregion #region Event Handlers private void AdDismissedHandler(Ad args) { // Whatever functionality you want to happen when an Ad is dismissed // In this case, load an interstitial as soon as one is closed, create a queue. adLoaded = false; LoadInterstitialAds (); } private void AdLoadedEventHandler(Ad args) { // Set ad loaded to true, so the coroutine can move on to ShowInterstitialAds() adLoaded = true; } #endregion void OnGUI () { if(GUI.Button(new Rect(Screen.width/4, Screen.height/2, Screen.width/2, 200), "Show Ads")) { // Queue next ad StartCoroutine(QueueInterstitialAd ()); } } } [/code]
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

pixelelement avatar image
pixelelement answered
Hi Justin@Amazon thanks for your help and your sample code. For some reason [b]private void AdLoadedEventHandler(Ad args)[/b] is never triggered. I created an empty scene with a game object containing you code sample, in the Xcode console output I can see that the ad is loaded, but since the [b]private void AdLoadedEventHandler(Ad args)[/b] is never triggered, the boolean [b]adLoaded[/b] is never true and therefore no ad is shown in the device even though the ad data was loaded. I added a debug line in: private void AdLoadedEventHandler(Ad args) { Debug.Log ("AdLoadedEventHandler() was triggered."); // Set ad loaded to true, so the coroutine can move on to ShowInterstitialAds() adLoaded = true; } but Debug.Log ("AdLoadedEventHandler() was triggered."); is never printed. This is my Xcode console output: 2015-08-17 10:19:51.414 ProductName[797:432373] -> registered mono modules 0x100e363e0 -> applicationDidFinishLaunching() -> applicationDidBecomeActive() Requesting Resolution: 1920x1080 Init: screen size 1920x1080 Initializing Metal device caps Initialize engine version: 5.1.2f1 (afd2369b692a) OnEnable () (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) Start () (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) InitInterstitialAds () (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) AmazonMobileAdsUnityIPhone: Successfully called native code in 7 ms (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) AmazonMobileAdsUnityIPhone: Successfully called native code in 0 ms (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) AmazonMobileAdsUnityIPhone: Successfully called native code in 0 ms (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) AmazonMobileAdsUnityIPhone: Successfully called native code in 0 ms (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) AmazonMobileAdsUnityIPhone: Successfully called native code in 0 ms (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) 0 INTERSTITIAL (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) LoadInterstitialAds() (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) 2015-08-17 10:19:55.162 ProductName[797:432373] AmazonAd: Configuration load request fired: https://mads.amazon-adsystem.com/msdk/getConfig?appId=sample-app-v1_pub-2&dinfo=%7B%22make%22%3A%22Apple%22%2C%22os%22%3A%22iOS%22%2C%22osVersion%22%3A%228.4%22%2C%22model%22%3A%22iPhone7%2C1%22%2C%22screenSize%22%3A%22414x736%22%2C%22scalingFactor%22%3A%223.0%22%2C%22orientation%22%3A%22portrait%22%7D&sdkVer=amznAdSDK-ios-2.2.8 AmazonMobileAdsUnityIPhone: Successfully called native code in 5 ms MobileAdsTest:InitInterstitialAds() (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) True (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65) 2015-08-17 10:19:55.950 ProductName[797:432373] AmazonAd: Configuration loaded: { aaxHostname = " aax-us-east.amazon-adsystem.com"; adPrefURL = " https://s.amazon-adsystem.com/gp/aw/aap/app"; featureUseGPSAID = 1; gpsDistance = 800; madsHostname = " mads.amazon.com"; region = us; sendGeo = 1; sisDomain = 3p; sisURL = " s.amazon-adsystem.com"; truncateLatLon = 0; ttl = 86400; } 2015-08-17 10:19:56.325 ProductName[797:432373] AmazonAd: AMAInterstitialAdManager (0x1742a4080) fired initial ad request. Ad Request URL https://aax-us-east.amazon-adsystem.com/e/msdk/ads Http headers { "Content-Type" = "application/json"; "User-Agent" = "Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12H143"; } Http body{"isTest":"true","slots":[{"slot":"portrait","slotId":"1","sz":"interstitial","supportedMediaTypes":["DISPLAY","VIDEO"],"video":{"minAdDuration":0,"maxAdDuration":30000}}],"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12H143","appId":"sample-app-v1_pub-2","oo":"false","adsdk":"amznAdSDK-ios-2.2.8","dinfo":{"make":"Apple","os":"iOS","country":"US","connectionType":"Wifi","osVersion":"8.4","model":"iPhone7,1","language":"en","carrier":"T-Mobile","screenSize":"414x736","scalingFactor":"3.0","orientation":"portrait"},"pkg":{"pn":"com.Company.ProductName","lbl":"ProductName","v":"1.0","vn":"1.0"},"idfa":"B895E143-0C75-4C02-B0EC-5310DCB1F7DA"} 2015-08-17 10:19:56.339 ProductName[797:432373] AmazonAd: Location service disabled 2015-08-17 10:19:56.398 ProductName[797:432373] AmazonAd: SIS(0x1740170a0)/generate_did URL http://s.amazon-adsystem.com/api3/generate_did?dt=iphone&app=app&aud=3p&idfa=B895E143-0C75-4C02-B0EC-5310DCB1F7DA&appId=sample-app-v1_pub-2&ua=Mozilla%2F5.0%20%28iPhone%3B%20CPU%20iPhone%20OS%208_4%20like%20Mac%20OS%20X%29%20AppleWebKit%2F600.1.4%20%28KHTML%2C%20like%20Gecko%29%20Mobile%2F12H143&dinfo=%7B%22make%22%3A%22Apple%22%2C%22os%22%3A%22iOS%22%2C%22osVersion%22%3A%228.4%22%2C%22model%22%3A%22iPhone7%2C1%22%2C%22screenSize%22%3A%22414x736%22%2C%22scalingFactor%22%3A%223.0%22%2C%22orientation%22%3A%22portrait%22%7D&pkg=%7B%22pn%22%3A%22com.Company.ProductName%22%2C%22lbl%22%3A%22ProductName%22%2C%22v%22%3A%221.0%22%2C%22vn%22%3A%221.0%22%7D&sdkVer=amznAdSDK-ios-2.2.8&oo=0 Http headers (null) 2015-08-17 10:19:56.542 ProductName[797:432373] AmazonAd: AMAInterstitialAdManager (0x1742a4080) received valid response from AAX server. 2015-08-17 10:19:56.576 ProductName[797:432373] AmazonAd: Interstitial Ad manager (0x1742a4080) received ad payload data string {"request_id":"g1jWKSjfFkJ54p7rbjU10w","status":"ok","errorCode":"200","ads":[{"creativeTypes":[1008,1016,1100],"cacheTTL":3600,"impPixelURL":" http://aax-us-east.amazon-adsystem.com/e/msdk/imp?b=IJyQvorthU9el6N-WRpzMd0AAAFPPD7bYwEAAA-h1QzoSg","cacheRank":1,"slotId":1,"slotCpms":[],"html":"rn
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

justin avatar image
justin answered
Hi pixelelement, I believe I may have missed that this was an iOS issue, not Android. Let me try running through this sometime today and I'll be sure to get back to you. Thanks!
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

justin avatar image
justin answered
Hi pixelelement, I just tested the event handlers in iOS and was unfortunately running into the same problem you were. I've escalated this to the appropriate team and they are looking into further causes. I'll ping this thread once I know additional details. In the mean time, while it's not the most ideal -- you could use a similar setup that doesn't rely on the ad being closed, gives enough headway to queue up the next ad after displaying one. Some pseudocode: [i]player presses start[/i] [code]loadInterstitialAdMethod()[/code] [i]player dies[/i] [code]if(playerHealth ]]]
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

pixelelement avatar image
pixelelement answered
Thanks Justin@Amazon, I was thinking of something similar as you suggested as a second option. Thanks for taking the time for the help.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andrew@Amazon avatar image
Andrew@Amazon answered
The new plugins for the Cross-Platform Engines have been released. You can find the information about the release here: https://forums.developer.amazon.com/forums/thread.jspa?threadID=10039&tstart=0 And you can download the new zip from the Mobile Ads page on the developer portal: https://developer.amazon.com/public/apis/earn/mobile-ads
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.