【问题标题】:Admob Interstitial isReady is FalseAdmob 插页式 isReady 为 False
【发布时间】:2014-03-28 21:57:59
【问题描述】:

我正在尝试在 ios 上实施 Admob 插页式广告。

这是我目前所拥有的,这是我第一次接触objective-c,所以请善待。

// Simple Admob Interstitial support for Monkey - IOS

// admobInterstitial.ios.h

#import "GADInterstitial.h"


class AdmobInterstitial {

    // the kind of "singleton"
    static AdmobInterstitial *_admob;
    // the ad
    GADInterstitial *_interstitialAd;
    // ad Unit ID
    NSString *adUnitId;

public:
    AdmobInterstitial();

    // creates an instance of the object and start the thread
    static AdmobInterstitial *GetAdmobInterstitial(String adUnitId);

    // displays the ad to the user if it is ready
    void ShowAd();
};


// admobInterstitial.ios.cpp

AdmobInterstitial *AdmobInterstitial::_admob;

AdmobInterstitial::AdmobInterstitial():_interstitialAd(0) {

}

AdmobInterstitial *AdmobInterstitial::GetAdmobInterstitial(String adUnitId) {
    if( !_admob ) _admob=new AdmobInterstitial();
    _admob->adUnitId = adUnitId.ToNSString();
    return _admob;
}

void AdmobInterstitial::ShowAd() {
    // create ad (should this go here or earlier?)
    _interstitialAd = [[GADInterstitial alloc] init];

    if (_interstitialAd) {
        _interstitialAd.adUnitID = adUnitId;
        [_interstitialAd loadRequest:[GADRequest request]];

        if (_interstitialAd.isReady) {
            BBMonkeyAppDelegate *appDelegate=(BBMonkeyAppDelegate*)[[UIApplication sharedApplication] delegate];
            UIViewController *rootViewController = appDelegate->viewController;
            [_interstitialAd presentFromRootViewController:rootViewController];
        }
    }
}

在玩家死亡并单击重新启动按钮后,我在我的游戏中调用 ShowAd()。 目前,_interstitialAd.isReady 并没有回归真实。

这是我开始使用的文档 https://developers.google.com/mobile-ads-sdk/docs/admob/advanced#ios

它说“您可以随时调用 loadRequest:,但是,您必须等待 GADInterstitialDelegate 的 interstitialDidReceiveAd: 被调用,然后才能显示广告。”

我认为这是我遇到的问题。我想我在 interstitialDidReceiveAd 之前调用 loadRequest。但是,该文档没有显示我将如何等待调用此方法的示例。

有人可以帮忙吗?

编辑:现在可以在我第一次调用 ShowAd() 时显示广告,但是在第一次调用此函数后的任何时候都不会显示广告

// Simple Admob Interstitial support for Monkey - IOS

// admobInterstitial.ios.h

#import "GADInterstitial.h"


class AdmobInterstitial {

    // the kind of "singleton"
    static AdmobInterstitial *_admob;
    // the ad
    GADInterstitial *_interstitialAd;
    // ad Unit ID
    NSString *adUnitId;

    void loadAd();

public:
    AdmobInterstitial();

    // creates an instance of the object and start the thread
    static AdmobInterstitial *GetAdmobInterstitial(String adUnitId);

    // displays the ad to the user if it is ready
    void ShowAd();
};


// admobInterstitial.ios.cpp

AdmobInterstitial *AdmobInterstitial::_admob;

AdmobInterstitial::AdmobInterstitial():_interstitialAd(0) {

}

AdmobInterstitial *AdmobInterstitial::GetAdmobInterstitial(String adUnitId) {
    if( !_admob ) _admob=new AdmobInterstitial();
    _admob->adUnitId = adUnitId.ToNSString();
    _admob->loadAd();
    return _admob;
}

void AdmobInterstitial::loadAd() {

    // testing
    _interstitialAd = [[GADInterstitial alloc] init];

    if (_interstitialAd) {
        _interstitialAd.adUnitID = adUnitId;
        [_interstitialAd loadRequest:[GADRequest request]];
    }
    // end testing

}

void AdmobInterstitial::ShowAd() {
    // create ad (should this go here or earlier?)
    //_interstitialAd = [[GADInterstitial alloc] init];

    if (_interstitialAd) {
        //_interstitialAd.adUnitID = adUnitId;
        //[_interstitialAd loadRequest:[GADRequest request]];

        if (_interstitialAd.isReady) {
            BBMonkeyAppDelegate *appDelegate=(BBMonkeyAppDelegate*)[[UIApplication sharedApplication] delegate];
            UIViewController *rootViewController = appDelegate->viewController;
            [_interstitialAd presentFromRootViewController:rootViewController];
        }
    }
}

【问题讨论】:

    标签: ios objective-c asynchronous admob interstitial


    【解决方案1】:

    好的。首先 isAdReady==false 将在没有可显示的广告时发生。即这是一个自然条件。您可以通过使用中介来缓解它。

    但在您的情况下,很可能没有可展示的广告,因为在提出该问题之前没有足够的时间发送广告请求并收到回复。

    您需要做的是尽早调用 loadAd。即当你第一次开始游戏时。然后在游戏的自然中断点(玩家死亡后)检查 isAdReady 是否为真,如果是则显示广告。

    当您展示广告或游戏再次启动时,再次调用 loadAd 以便您下次想要展示广告时再次准备好广告。

    【讨论】:

    • 谢谢,这有帮助。请看我的编辑。广告现在显示我第一次调用 ShowAd() 的时间,但此后不再显示。例如,当我第二次调用它时。
    • 我假设我需要监听 interstitialDidDismissScreen,但是我真的不知道如何在我当前的代码中执行此操作。对此的任何帮助将不胜感激。
    • 见我上面的修改。本质上,您希望在展示广告后再次调用 loadAd。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多