【问题标题】:How to determine `isReady` for Firebase/Admob interstitial Ad如何确定 Firebase/Admob 插页式广告的“isReady”
【发布时间】:2018-01-14 06:24:37
【问题描述】:

对于 iOS,admob 带有 isReady 字段以确定广告是否准备好展示。现在我正在将 Admob 集成到我在 cocos2d-x 中的 Android 游戏中,我正在遵循这个官方指南:https://firebase.google.com/docs/admob/cpp/quick-start#set_up_an_interstitial_ad

if (interstitial_ad->LoadAdLastResult().status() ==
    firebase::kFutureStatusComplete &&
    interstitial_ad->LoadAdLastResult().error() ==
    firebase::admob::kAdMobErrorNone) {
  interstitial_ad->Show();
}

条件与 iOS isReady API 略有不同。在广告已经展示后,对于 iOS,isReady 将为 false。但即使在广告展示之后,LoadAdLastResult 仍然是 Complete。我需要类似于isReady 的内容来决定是否需要请求新广告。我怎样才能做到这一点?

【问题讨论】:

    标签: firebase admob cocos2d-x


    【解决方案1】:

    不要使用isReady。最新的 Admob 更新删除了它实际上是一个糟糕的 API(iOS 版 v8.0)。

    原因是 isReady 很容易导致竞态条件,导致状态不佳。更好的方法是仅在广告获取回调成功后保留对广告实例的引用(这是 v8.0 API 中唯一的方法)

    【讨论】:

      【解决方案2】:

      你应该自己实现这个逻辑。例如:一个变量(interstitialAdShown),表示您需要请求一个新广告

        // Set up the show interstitial ad button.
        showInterstitialAdBtn = createButton(false, kShowInterstitialText);
        showInterstitialAdBtn->addTouchEventListener(
            [&](Ref* sender, cocos2d::ui::Widget::TouchEventType type) {
              cocos2d::ui::Button* button = static_cast<cocos2d::ui::Button*>(sender);
              switch (type) {
                case cocos2d::ui::Widget::TouchEventType::ENDED:
                  // The show intersitial button is enabled in the update() method
                  // when the interstial ad has successfully loaded. Here the show
                  // interstitial button has been pressed by the user, so we disable
                  // the button and display the interstitial ad to the user.
                  button->setEnabled(false);
                  logMessage("Showing the interstitial ad.");
                  interstitialAd->Show();
                  // Invalidate all Futures and enable loadInterstitialAdBtn.
                  interstitialAdShown = true;
                  break;
                default:
                  break;
              }
            });
      this->addChild(showInterstitialAdBtn);
      

      您可以在此处查看完整示例 - https://github.com/firebase/cocos2dx-cpp-sample/blob/master/admob/Classes/FirebaseAdMobScene.cpp#L441

      来自 google 的 cocos2d-x 的其他 firebase 示例 - https://github.com/firebase/cocos2dx-cpp-sample

      【讨论】:

        【解决方案3】:

        据我所知,IOS 和 Android 在插页式加载方面的行为非常相似。

        在 Android 中,您可以使用它来检查插页式广告是否准备好显示:

        if (interstitial.isLoaded()) {
                    interstitial.show();
                }
        

        更多关于 Android 的良好做法是在 onAdClosed 事件中请求新的插页式广告

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-09-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-09-21
          • 2018-01-03
          • 1970-01-01
          相关资源
          最近更新 更多