5

此代码是否适合实施插页式广告?

在此处输入图像描述

因为当我启动它时,我得到了这个,

<Google> Cannot present interstitial.  It is not ready.
4

5 回答 5

23

您需要等到广告加载成功,然后才能在插页式广告的情况下展示它。否则广告不会出现。

为此,请遵守GADInterstitialDelegate协议并将您的视图控制器设置为 interstitial_ 的委托。

interstitial_.delegate = self;

然后执行interstitialDidReceiveAd如下。

- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
    [interstitial_ presentFromRootViewController:self];
}

如需更多参考,请查看插页式广告

于 2014-04-16T07:08:50.440 回答
4

斯威夫特 3.0

viewDidLoad()createAndLoadInterstitial()

interstitial.delegate = self

然后实施

func interstitialDidReceiveAd(_ ad: GADInterstitial) {
    interstitial.present(fromRootViewController: self)
}
于 2017-09-14T00:19:50.410 回答
1

如果您想在下一页或当前页面上再次加载谷歌插页式广告,请使用以下代码..

//在视图是否加载在您的下一页或当前页面视图控制器上添加以下行

self.interstitial = [self createAndLoadInterstitial];

//在您的下一页或当前页面视图上创建以下方法 controller.m

- (GADInterstitial *)createAndLoadInterstitial {
    GADInterstitial *interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910"];
    interstitial.delegate = self;
    [interstitial loadRequest:[GADRequest request]];
    return interstitial;
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
    [self.interstitial presentFromRootViewController:self];
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial 
{
//leave this method as empty    
}

现在您将能够收到将显示的广告

于 2015-11-26T07:26:42.133 回答
1

我认为你不必使用interstitialDidReceiveAd方法。admob 文档不建议这样做。也许你可以DispatchQueue.main.async使用viewDidLoad()

if (mInterstitialAd.isReady)
{
    DispatchQueue.main.async
    {
        mInterstitialAd.present(fromRootViewController: self)
    }
}
于 2018-05-26T15:57:55.997 回答
0

斯威夫特 5.0

viewDidLoad()

确保通过这样做为您的视图控制器设置委托

interstitial.delegate = self

然后在委托方法中,您可以实现以下

func interstitialDidReceiveAd(_ ad: GADInterstitial) {
    interstitial.present(fromRootViewController: self)
}
于 2020-05-11T19:57:22.210 回答