Unity Admobs在Android设备上不起作用

时间:2018-08-18 08:15:41

标签: android ios unity3d admob

所以我已经在iOS设备上测试了广告,它的运行情况绝对不错!

但是当apk在Android设备上构建并安装时,Admobs广告甚至都不会显示!

我用于集成广告的Adcontroller脚本!

任何人都可以解释导致此问题的原因。不胜感激!

谢谢

公共类AdController:MonoBehaviour {

public static AdController instance;

private BannerView bannerView;
private InterstitialAd interstitial;


void Awake (){
    MakeSingleton ();
}



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


    MakeSingleton ();


    RequestBanner ();
    RequestInterstitial ();

    #if UNITY_ANDROID
    string appId = "ca-app-pub-3454534660788114~3231414565";
    #elif UNITY_IPHONE
    string appId = "ca-app-pub-3454534660788114~6021229439";
    #else
    string appId = "unexpected_platform";
    #endif

    MobileAds.SetiOSAppPauseOnBackground(true);

    // Initialize the Google Mobile Ads SDK.
    MobileAds.Initialize(appId);

}

void MakeSingleton() {
    if (instance != null) {
        Destroy (gameObject);
    } else {
        instance = this;
        DontDestroyOnLoad (gameObject);

    }

}





private void RequestBanner()
{
    // These ad units are configured to always serve test ads.
    #if UNITY_EDITOR
    string adUnitId = "unused";
    #elif UNITY_ANDROID
    string adUnitId = "ca-app-pub-3454534660788114/6674059459";
    #elif UNITY_IPHONE
    string adUnitId = "ca-app-pub-3454534660788114/5829657741";
    #else
    string adUnitId = "unexpected_platform";
    #endif

    // Clean up banner ad before creating a new one.
    if (this.bannerView != null)
    {
    this.bannerView.Destroy();
    }

    // Create a 320x50 banner at the top of the screen.
    this.bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);

    // Register for ad events.
    RegisterDelegateForBanner ();

    // Load a banner ad.
    this.bannerView.LoadAd(this.CreateAdRequest());
    }


    private void RequestInterstitial()
    {
    // These ad units are configured to always serve test ads.
    #if UNITY_EDITOR
    string adUnitId = "unused";
    #elif UNITY_ANDROID
    string adUnitId = "ca-app-pub-3454534660788114/1152046133";
    #elif UNITY_IPHONE
    string adUnitId = "ca-app-pub-3454534660788114/5254942671";
    #else
    string adUnitId = "unexpected_platform";
    #endif

    // Clean up interstitial ad before creating a new one.
    if (this.interstitial != null)
    {
    this.interstitial.Destroy();
    }

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

    // Register for ad events.
    RegisterDelegateForInterstitial ();


    // Load an interstitial ad.
    this.interstitial.LoadAd(this.CreateAdRequest());
    }

    private AdRequest CreateAdRequest()
    {
    return new AdRequest.Builder()
    .AddTestDevice(AdRequest.TestDeviceSimulator)
    .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
    .AddKeyword("game")
    .SetGender(Gender.Male)
    .SetBirthday(new DateTime(1985, 1, 1))
    .TagForChildDirectedTreatment(false)
    .AddExtra("color_bg", "9B30FF")
    .Build();
    }

    void RegisterDelegateForBanner(){

    this.bannerView.OnAdLoaded += this.HandleAdLoaded;
    this.bannerView.OnAdFailedToLoad += this.HandleAdFailedToLoad;
    this.bannerView.OnAdOpening += this.HandleAdOpened;
    this.bannerView.OnAdClosed += this.HandleAdClosed;
    this.bannerView.OnAdLeavingApplication += this.HandleAdLeftApplication;

    }

    void UnregisterDelegateForBanner(){

    this.bannerView.OnAdLoaded -= this.HandleAdLoaded;
    this.bannerView.OnAdFailedToLoad -= this.HandleAdFailedToLoad;
    this.bannerView.OnAdOpening -= this.HandleAdOpened;
    this.bannerView.OnAdClosed -= this.HandleAdClosed;
    this.bannerView.OnAdLeavingApplication -= this.HandleAdLeftApplication;

    }

    void RegisterDelegateForInterstitial(){

    this.interstitial.OnAdLoaded += this.HandleInterstitialLoaded;
    this.interstitial.OnAdFailedToLoad += this.HandleInterstitialFailedToLoad;
    this.interstitial.OnAdOpening += this.HandleInterstitialOpened;
    this.interstitial.OnAdClosed += this.HandleInterstitialClosed;
    this.interstitial.OnAdLeavingApplication += this.HandleInterstitialLeftApplication;

    }


    void UnRegisterDelegateForInterstitial(){

    this.interstitial.OnAdLoaded -= this.HandleInterstitialLoaded;
    this.interstitial.OnAdFailedToLoad -= this.HandleInterstitialFailedToLoad;
    this.interstitial.OnAdOpening -= this.HandleInterstitialOpened;
    this.interstitial.OnAdClosed -= this.HandleInterstitialClosed;
    this.interstitial.OnAdLeavingApplication -= this.HandleInterstitialLeftApplication;

    }
    public void ShowBanner(){
    bannerView.Show ();
    }


    public void ShowInterstitial(){
    if (interstitial.IsLoaded ()) {

        interstitial.Show ();

    } else {
        RequestInterstitial ();
    }

    }



    public void HandleAdLoaded(object sender, EventArgs args)
    {
    ShowBanner ();
    }

    public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
    UnregisterDelegateForBanner ();
    RequestBanner ();
    }

    public void HandleAdOpened(object sender, EventArgs args)
    {

    }

    public void HandleAdClosed(object sender, EventArgs args)
    {
    UnregisterDelegateForBanner ();
    RequestBanner ();

    }

    public void HandleAdLeftApplication(object sender, EventArgs args)
    {
    }






    public void HandleInterstitialLoaded(object sender, EventArgs args)
    {

    }

    public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
    UnRegisterDelegateForInterstitial ();
    RequestInterstitial ();

    }

    public void HandleInterstitialOpened(object sender, EventArgs args)
    {
    }

    public void HandleInterstitialClosed(object sender, EventArgs args)
    {

    UnregisterDelegateForBanner ();
    RequestBanner ();

    }

    public void HandleInterstitialLeftApplication(object sender, EventArgs args)
    {
    }

}

1 个答案:

答案 0 :(得分:0)

您能告诉我们这个结果吗?

还要检查您是否在ADMOB个人资料中填写了帐单信息,除非您填写,否则似乎无法正常工作。

似乎您也没有打电话给ShowInterstitial()吗?