Admob InterstitialAd事件处理程序无法调用

时间:2015-08-07 09:55:44

标签: c# unity3d admob

我正在内撰写广告控制器。我发现与interstital广告相关的事件处理程序存在奇怪的问题。

我用来请求插页式广告的方法:

private void GoogleRequestInterstitial(string gameID)
{
    if (string.IsNullOrEmpty(gameID))
    {
        Debug.LogErrorFormat("GoogleAds - Game ID can't be NULL or EMPTY!");
        if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Game ID can't be NULL or EMPTY!");
    }

    var interstitial = new InterstitialAd(gameID);
    AdRequest request = null;

    if (CallbackMethod != null)
    {
        interstitial.AdFailedToLoad += InterstitialOnAdFailedToLoad;
        interstitial.AdClosed += InterstitialOnAdClosed;
        interstitial.AdClosing += InterstitialOnAdClosing;
        interstitial.AdLeftApplication += InterstitialOnAdLeftApplication;
        interstitial.AdLoaded += InterstitialOnAdLoaded;
        interstitial.AdOpened += InterstitialOnAdOpened;
    }
    else
    {
        Debug.LogWarningFormat("GoogleAds - Don't forget to register callback!");
        if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Don't forget to register callback!");
    }

    if (DebugMode)
    {
        request = new AdRequest.Builder()
            .AddTestDevice(AdRequest.TestDeviceSimulator) // Simulator.
            .AddTestDevice("2077ef9a63d2b398840261c8221a0c9b") // My test device.
            .Build();
    }
    else
    {
        request = new AdRequest.Builder().Build();
    }

    interstitial.LoadAd(request);

    controller.StartCoroutine(GoogleShowAdWhenReady(interstitial));
}

Corutine:

private IEnumerator GoogleShowAdWhenReady(InterstitialAd interstitial)
{
    while (!interstitial.IsLoaded())
        yield return null;

    interstitial.Show();
    if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial : SHOW");
}

以下是整个事件处理程序区域:

#region EventHandlers - INTERSTITIAL

private void InterstitialOnAdClosed(object sender, EventArgs args)
{
    CallbackMethod(WinzebraAdsController.WinzebraShowResult.Finished);
    if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "FINISHED");

    var obj = sender as InterstitialAd;
    obj.Destroy();
}

private void InterstitialOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
    CallbackMethod(WinzebraAdsController.WinzebraShowResult.Failed);
    if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "FAILED !");

    var obj = sender as InterstitialAd;
    obj.Destroy();
}

private void InterstitialOnAdClosing(object sender, EventArgs eventArgs)
{
    if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Closing");
}

private void InterstitialOnAdOpened(object sender, EventArgs eventArgs)
{
    if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Opened");
}

private void InterstitialOnAdLoaded(object sender, EventArgs eventArgs)
{
    if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Loaded");
}

private void InterstitialOnAdLeftApplication(object sender, EventArgs eventArgs)
{
    if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Left Application");
}

#endregion

信息:

  • WinzebraAdsConsole是自编的" console"基于文本组件。

  • CallbackMethod是自定义"全球"回调,这总是NOT NULL(之前检查过)。

首次运行时,我可以在自编的控制台中看到InterstitialOnAdLoaded和InterstitialOnAdOpened方法正常运行。但是当我关闭插页式广告并且事件InterstitialOnAdClosed没有被调用时,问题就开始了。 此外,在第二轮插页式广告中,我获得了InterstitialOnAdClosing事件,但仍然没有" OnClosed"。

我的代码有问题吗?以前有人看到过那种问题吗?

Screenshoots:

  1. 第一次插页后:
  2. enter image description here

    1. 第二次插页后:
    2. enter image description here

1 个答案:

答案 0 :(得分:0)

我认为没有必要定义另一个Co-routine来等待广告被阅读以显示,而不是尝试这可能会解决您的问题:

private void InterstitialOnAdLoaded(object sender, EventArgs eventArgs)
{
    if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Loaded");

    if (interstitial.IsLoaded())
    {    
        interstitial.Show();
        if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial : SHOW");
    }

}