此代码是否适合实施插页式广告?
因为当我启动它时,我得到了这个,
<Google> Cannot present interstitial. It is not ready.
此代码是否适合实施插页式广告?
因为当我启动它时,我得到了这个,
<Google> Cannot present interstitial. It is not ready.
您需要等到广告加载成功,然后才能在插页式广告的情况下展示它。否则广告不会出现。
为此,请遵守GADInterstitialDelegate
协议并将您的视图控制器设置为 interstitial_ 的委托。
interstitial_.delegate = self;
然后执行interstitialDidReceiveAd
如下。
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
[interstitial_ presentFromRootViewController:self];
}
如需更多参考,请查看插页式广告
斯威夫特 3.0
在viewDidLoad()
或createAndLoadInterstitial()
interstitial.delegate = self
然后实施
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
interstitial.present(fromRootViewController: self)
}
如果您想在下一页或当前页面上再次加载谷歌插页式广告,请使用以下代码..
//在视图是否加载在您的下一页或当前页面视图控制器上添加以下行
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
}
现在您将能够收到将显示的广告
我认为你不必使用interstitialDidReceiveAd
方法。admob 文档不建议这样做。也许你可以DispatchQueue.main.async
使用viewDidLoad()
if (mInterstitialAd.isReady)
{
DispatchQueue.main.async
{
mInterstitialAd.present(fromRootViewController: self)
}
}
斯威夫特 5.0
在viewDidLoad()
确保通过这样做为您的视图控制器设置委托
interstitial.delegate = self
然后在委托方法中,您可以实现以下
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
interstitial.present(fromRootViewController: self)
}