[RESOLU]Admob ok dans l'editor mais pas en Build

Toutes les questions sur le développement Mobile, y compris la partie script.
Bilu
Messages : 91
Inscription : 20 Nov 2019 09:24

[RESOLU]Admob ok dans l'editor mais pas en Build

Message par Bilu » 16 Déc 2021 15:05

Bonjour,

J'ai une application dans laquelle j'ai un bouton qui appelle une pub
Screenshot 2021-12-16 134451.png
Screenshot 2021-12-16 134451.png (22.36 Kio) Consulté 1247 fois
Quand je test dans l'editor de Unity, pas de soucis et j'ai la pub test de Admob qui s'affiche mais quand je test cela dans le build (en ayant renseigner mon smartphone comme appareil de test ET en utilisant un appID de test) rien ne s'affiche.

Voici le script C# qui appelle la pub :

Code : Tout sélectionner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using System;

public class AdMobAd : MonoBehaviour
{ 
    private InterstitialAd interstitial;
    string adUnitId = "ca-app-pub-XXXXXXXXXX/XXXXXXXX";
    // Start is called before the first frame update
    void Start()
    {
        MobileAds.Initialize(initStatus => { });
        //RequestInterstitial();


    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void RequestInterstitial()
    {
        //#if UNITY_ANDROID
        //string adUnitId = "ca-app-pub-3940256099942544/1033173712";
        //#elif UNITY_IPHONE
        //string adUnitId = "ca-app-pub-3940256099942544/4411468910";
        //#else
        //string adUnitId = "unexpected_platform";
        //#endif
        
        // Clean up interstitial before using it
        if (interstitial != null)
        {
            interstitial.Destroy();
        }

        // Initialize an InterstitialAd.
        this.interstitial = new InterstitialAd(adUnitId);

        // Called when an ad request has successfully loaded.
        this.interstitial.OnAdLoaded += HandleOnAdLoaded;
        // Called when an ad request failed to load.
        this.interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad;
        // Called when an ad is shown.
        this.interstitial.OnAdOpening += HandleOnAdOpened;
        // Called when the ad is closed.
        this.interstitial.OnAdClosed += HandleOnAdClosed;
        // Called when the ad click caused the user to leave the application.
        //this.interstitial.OnAdLeavingApplication += HandleOnAdLeavingApplication;


        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the interstitial with the request.
        this.interstitial.LoadAd(request);

        if (this.interstitial.IsLoaded())
        {
            this.interstitial.Show();
        }
    }

    public void HandleOnAdLoaded(object sender, EventArgs args)
    {
        MonoBehaviour.print("HandleAdLoaded event received");
    }

    public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        MonoBehaviour.print("HandleFailedToReceiveAd event received with message: "
                            /*+ args.Message*/);
        // Handle the ad failed to load event.
    }

    public void HandleOnAdOpened(object sender, EventArgs args)
    {
        MonoBehaviour.print("HandleAdOpened event received");
    }

    public void HandleOnAdClosed(object sender, EventArgs args)
    {
        MonoBehaviour.print("HandleAdClosed event received");
    }

    /*public void HandleOnAdLeavingApplication(object sender, EventArgs args)
    {
        MonoBehaviour.print("HandleAdLeavingApplication event received");
    }
    */
}

Pourriez-vous m'aider à identifier la source de mon problème s'il vous plaît ?

Bien à vous,

Bilu
Dernière édition par Bilu le 17 Déc 2021 17:21, édité 1 fois.

Bilu
Messages : 91
Inscription : 20 Nov 2019 09:24

Re: Admob ok dans l'editor mais pas en Build

Message par Bilu » 16 Déc 2021 16:39

D'après mes test, on dirait qu'il ne rentre pas dans le if

Code : Tout sélectionner

if (this.interstitial.IsLoaded())
        {
            this.interstitial.Show();
        }
"Plus qu'à" découvrir pourquoi ?

Quelqu'un peut m'aider ?

Bilu
Messages : 91
Inscription : 20 Nov 2019 09:24

Re: Admob ok dans l'editor mais pas en Build

Message par Bilu » 17 Déc 2021 17:21

J'ai trouvé la solution.

En effet, c'était bien parce que l'ad n'avait pas eu le temps de load.

Solution sur cette page :
https://answers.unity.com/questions/985 ... -up-1.html

Répondre

Revenir vers « Développement plateformes mobile Iphone et Android »