iosiphonexcodeunity-game-engineapplovin

AppLovin Ads in Unity3D : onAppLovinEventReceived not fired


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.


Solution

  • 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.