【发布时间】:2014-04-16 02:21:17
【问题描述】:
此代码对于实施插页式广告是否正确?
因为当我启动它时,我得到了这个,
<Google> Cannot present interstitial. It is not ready.
【问题讨论】:
标签: ios admob ads interstitial
此代码对于实施插页式广告是否正确?
因为当我启动它时,我得到了这个,
<Google> Cannot present interstitial. It is not ready.
【问题讨论】:
标签: ios admob ads interstitial
您需要等到广告加载成功,然后才在插页式广告的情况下展示它。否则广告不会显示。
为此,请遵守GADInterstitialDelegate 协议并将您的视图控制器设置为 interstitial_ 的委托。
interstitial_.delegate = self;
然后如下实现interstitialDidReceiveAd。
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
[interstitial_ presentFromRootViewController:self];
}
更多参考,请查看Interstitials ads
【讨论】:
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial;
<GADInterstitialDelegate> 协议? (即为将成为委托的视图控制器写@interface ViewController : UIViewController <GADInterstitialDelegate>?)
斯威夫特 3.0
在viewDidLoad() 或createAndLoadInterstitial()
interstitial.delegate = self
然后实施
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
interstitial.present(fromRootViewController: self)
}
【讨论】:
如果您想在下一页或当前页面再次加载谷歌插页式广告,请使用以下代码..
//在视图中是否加载在您的下一页或当前页面视图控制器上添加以下行。m
self.interstitial = [self createAndLoadInterstitial];
//在您的下一页或当前页面视图控制器上创建以下方法.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 文档不建议这样做。也许你可以在viewDidLoad()中使用DispatchQueue.main.async
if (mInterstitialAd.isReady)
{
DispatchQueue.main.async
{
mInterstitialAd.present(fromRootViewController: self)
}
}
【讨论】:
斯威夫特 5.0
在viewDidLoad()
确保通过这样做为您的视图控制器设置委托
interstitial.delegate = self
然后在委托方法中你可以实现以下
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
interstitial.present(fromRootViewController: self)
}
【讨论】: