当我在Unity中初始化Google Admob并发送横幅广告请求时,大多数情况下都不会显示任何内容。当我在3秒内提出要求时,我就有更多机会。我在想这可能是因为初始化需要时间吗?因此,现在我想知道如何知道何时初始化Admob,或者如何才能最成功地请求横幅广告。这是当前代码:
private BannerView bannerView;
void Start()
{
#if UNITY_ANDROID
string appId = ".............REAL ID................."; //ADMOB
#elif UNITY_IPHONE
string appId = ".............REAL ID.................";
#else
string appId = "unexpected_platform";
#endif
MobileAds.Initialize(appId);
HandleAds();
}
private void HandleAds()
{
if(....) // some conditions in which to show ads, not relevant
Invoke("RequestInterstitial",3f); //also not relevant and works very well
Invoke("RequestBanner",3f); // not works very well
}
public void RequestBanner()
{
#if UNITY_ANDROID
string adUnitId = "......Real Id.......";
#elif UNITY_IPHONE
string adUnitId = "......Real Id.......";
#else
string appId = "unexpected_platform";
#endif
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
bannerView.OnAdLoaded += HandleOnAdLoaded;
AdRequest request = new AdRequest.Builder().Build();
bannerView.LoadAd(request);
}
public void HandleOnAdLoaded(object sender, EventArgs args)
{
bannerView.Show();
}