【发布时间】:2020-06-07 06:29:24
【问题描述】:
测试广告正常工作,但当我在 Play 商店发布时,广告无法正常工作。 游戏链接https://play.google.com/store/apps/details?id=com.GreyMacleno.FruitChop。 这是我的 AdManager 的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using GoogleMobileAds.Api;
public class AdManager : MonoBehaviour
{
public static AdManager Instance{get;set;}
private BannerView bannerAd;
private InterstitialAd interstitialAd;
private RewardBasedVideoAd rewardVideoAd;
void Awake()
{
if (Instance == null)
{
DontDestroyOnLoad(this.gameObject);
Instance = this;
}
else if (Instance != this)
{
Destroy(this.gameObject);
return;
}
}
void Start()
{
MobileAds.Initialize(initStatus => { });
RequestBanner();
RequestInterstitial();
}
void RequestBanner(){
// for real
string banner_ID = "not showing but correctly entered";
// for testing
// string banner_ID = "ca-app-pub-3940256099942544/6300978111";
bannerAd = new BannerView(banner_ID, AdSize.Banner, AdPosition.Bottom);
// for real
AdRequest adRequest = new AdRequest.Builder().Build();
// For testing
// AdRequest adRequest = new AdRequest.Builder().AddTestDevice("2077ef9a63d2b398840261c8221a0c9b").Build();
bannerAd.LoadAd(adRequest);
}
void RequestInterstitial(){
if(interstitialAd != null)
interstitialAd.Destroy();
// for real
string interstitial_ID = "not showing but correctly entered";
// for testing
// string interstitial_ID = "ca-app-pub-3940256099942544/1033173712";
interstitialAd = new InterstitialAd(interstitial_ID);
// Called when an ad request has successfully loaded.
interstitialAd.OnAdLoaded += HandleOnAdLoaded;
// for real
AdRequest adRequest = new AdRequest.Builder().Build();
// For testing
// AdRequest adRequest = new AdRequest.Builder().AddTestDevice("2077ef9a63d2b398840261c8221a0c9b").Build();
interstitialAd.LoadAd(adRequest);
}
public void DisplayBanner(){
bannerAd.Show();
}
public void DisplayInterstitialAd(){
if(interstitialAd.IsLoaded()){
interstitialAd.Show();
}
else{
RequestInterstitial();
interstitialAd.Show();
}
}
public void HandleOnAdLoaded(object sender, EventArgs args)
{
DisplayBanner();
}
public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
RequestBanner();
}
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");
}
void HandleBannerADEvents(bool subscribe){
if(subscribe){
// Called when an ad request has successfully loaded.
this.bannerAd.OnAdLoaded += this.HandleOnAdLoaded;
// Called when an ad request failed to load.
this.bannerAd.OnAdFailedToLoad += this.HandleOnAdFailedToLoad;
// Called when an ad is clicked.
this.bannerAd.OnAdOpening += this.HandleOnAdOpened;
// Called when the user returned from the app after an ad click.
this.bannerAd.OnAdClosed += this.HandleOnAdClosed;
// Called when the ad click caused the user to leave the application.
this.bannerAd.OnAdLeavingApplication += this.HandleOnAdLeavingApplication;
}
else{
// Called when an ad request has successfully loaded.
this.bannerAd.OnAdLoaded -= this.HandleOnAdLoaded;
// Called when an ad request failed to load.
this.bannerAd.OnAdFailedToLoad -= this.HandleOnAdFailedToLoad;
// Called when an ad is clicked.
this.bannerAd.OnAdOpening -= this.HandleOnAdOpened;
// Called when the user returned from the app after an ad click.
this.bannerAd.OnAdClosed -= this.HandleOnAdClosed;
// Called when the ad click caused the user to leave the application.
this.bannerAd.OnAdLeavingApplication -= this.HandleOnAdLeavingApplication;
}
}
void OnEnable(){
HandleBannerADEvents(true);
}
void OnDisable(){
HandleBannerADEvents(false);
}
}
我正在调用要在其中运行插页式广告的 DisplayInterstitialAd()。很少有人说我应该等待,但已经 3 天了,我仍在等待广告出现。 我已将该应用程序与 Admob 相关联。 Unity的版本是2019.3.13f1。
【问题讨论】: