AppLovin Ads in Unity3D : onAppLovinEventReceived not fired

谁说胖子不能爱 提交于 2019-12-11 04:38:43

问题


I used Applovin fullscreen ads in Unity3D iOS game.

Ads are working good. But event listener not fired. I wish to track fail event call.

public static void StartApplovin () 
    {
        AppLovin.SetSdkKey("My_SDK_Key");
        AppLovin.InitializeSdk();

        AppLovin.SetUnityAdListener("ApplovinListener");
    }

Here is ApplovinListener.cs class

public class ApplovinListener : MonoBehaviour {

    void onAppLovinEventReceived(string ev)
    {
        Debug.Log ("\n\nonAppLovinEventReceived\n\n");

        if(ev.Contains("DISPLAYEDINTER")) {
            // An ad was shown.  Pause the game.
        }
        else if(ev.Contains("HIDDENINTER")) {
            // Ad ad was closed.  Resume the game.
            // If you're using PreloadInterstitial/HasPreloadedInterstitial, make a preload call here.
            AppLovin.PreloadInterstitial();
        }
        else if(ev.Contains("LOADEDINTER")) {
            // An interstitial ad was successfully loaded.
        }
        else if(string.Equals(ev, "LOADINTERFAILED")) {
            // An interstitial ad failed to load.
            GameCenter2.ShowAdmobAds ();
            Debug.Log ("\n\n Applovin FAILED\n\n");

        }
    }

 }

When I run, Xcode gives below console log.

SendMessage: object ApplovinListener not found!

How to get onAppLovinEventReceived called ?

UPDATE: I have fixed this problem by creating gameObject

In Unity Manu, Press GameObject->Create Empty

Name it “ApplovinListener”

Now attach script named ApplovinListener to game object. That’s it.


回答1:


Your ApplovinListener script must be attached to the name of the GameObject that is passed into the AppLovin.SetUnityAdListener function in order for the onAppLovinEventReceived function to be called.

You had this:

AppLovin.SetUnityAdListener("ApplovinListener");

Make sure that there is a GameObject actually named "ApplovinListener". Now, make sure that the ApplovinListener script is attached to it. The onAppLovinEventReceived function should be called after you do this.


To make this easier for you, I recommend you do this instead:

AppLovin.SetUnityAdListener(yourGameObject.name);

then attach the ApplovinListener script to that GameObject you referenced above.



来源:https://stackoverflow.com/questions/46484572/applovin-ads-in-unity3d-onapplovineventreceived-not-fired

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!