我基本上复制粘贴和轻微修改演示项目广告设置由谷歌移动广告的官方分支和我的横幅广告显示很好,但没有间隙广告出现-无论如何。
以下是我所做的,使用我的AdManager static class
这个InitializeAds()在游戏开始后就被调用了:
public static void InitializeAds()
{
MobileAds.Initialize(appID);
}当然,每个有广告的级别,在他们的Start()方法中都有下面的Start()。
public static void GetSomeAdRequests()
{
AdRequestBANNER = CreateAdRequest();
AdRequestINTERST = CreateAdRequest();
}
public static AdRequest CreateAdRequest()
{
AdRequest request = new AdRequest.Builder().Build();
return request;
}不用说,我使用由Google提供的测试者视频和横幅I。
接下来是我的RequestInterstitial
public static void RequestInterstitial()
{
// These ad units are configured to always serve test ads.
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = videoID;
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up interstitial ad before creating a new one.
if (interstitial != null)
{
interstitial.Destroy();
}
// Create an interstitial.
interstitial = new InterstitialAd(adUnitId);
// Register for ad events.
interstitial.OnAdLoaded += HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
interstitial.OnAdOpening += HandleInterstitialOpened;
interstitial.OnAdClosed += HandleInterstitialClosed;
interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;
// Load an interstitial ad.
interstitial.LoadAd(AdRequestINTERST);
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}最后,AdRequestINTERST是:
private static AdRequest adRequestINTERST;
public static AdRequest AdRequestINTERST
{
get
{
if (adRequestINTERST == null)
{
adRequestINTERST = CreateAdRequest();
}
return adRequestINTERST;
}
set
{
adRequestINTERST = value;
}
}以这种方式实现,以确保request永远不会为空。
现在,我确实给了vid大量的时间来初始化,因为它应该在leve上加载,但是它仍然什么也不做。没有错误,没有冻结。
在编辑器播放中,我使用Debug.Log对其进行了测试,它达到了实际调用广告的代码。它只是没有出现,而横幅广告运作良好。
有什么想法吗?
发布于 2017-08-23 18:55:56
我想我现在明白了。
所以我做这个的方法是:
我在初始化场景时加载广告,或者准确地说,在之前启动请求。然后把它们藏起来。
当我想要广告出现的时候,我只需要调用Show()方法和boom,它们就在那里。
我的问题是,互联网的速度不是这里最好的,我要求,并希望在请求后立即显示,这是不会发生的。
发布于 2022-02-02 19:33:29
只要给出适当的时间来加载广告,就像测试一样,使用延迟10秒的处理程序post给出加载广告的时间,10秒后广告才会加载。
要检查,只需在任何活动中使用相同的代码即可。
var adRequest = AdRequest.Builder().build()
InterstitialAd.load(this,"ca-app-pub-3940256099942544/1033173712", adRequest, object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
Log.d(TAG, adError?.message)
mInterstitialAd = null
}
override fun onAdLoaded(interstitialAd: InterstitialAd) {
Log.d(TAG, "Ad was loaded.")
mInterstitialAd = interstitialAd
}
})
Handler().postDelayed({
if (mInterstitialAd != null) {
println("executed")
mInterstitialAd?.show(this)
} else {
Log.d("TAG", "The interstitial ad wasn't ready yet.")
}
}, 10000)https://stackoverflow.com/questions/45845986
复制相似问题