如何多次显示admob interstitals?

我有一个小游戏应用程序,有一个故事板,里面创建场景,如开始菜单 – gamin区域 – 得分我添加了admob横幅视图和interstitals到它。我的横幅视图工作正常,但我的插页式广告只能工作一次。

我在我的viewdidload上加载我的插页式广告并在调用游戏会话结束的函数中激活它,正如我所说它有效,但只有一次当用户启动另一个游戏时失败,这次没有interstital(下面的错误)。那么什么我应该怎么做才能修复它我希望我的游戏可以随时多次显示插页式广告。

错误:请求错误:由于已使用插页式对象,因此无法发送请求。

标题:

#import "GADBannerView.h" #import "GADInterstitial.h" @class GADInterstitial; @class GADRequest; ////////////code UIviewcontroller////////// GADBannerView *bannerView_; GADInterstitial *interstitial_; 

履行

 -(void)viewdidload { //////////////////gaming code/////////// interstitial_ = [[GADInterstitial alloc] init]; interstitial_.delegate = self; interstitial_.adUnitID = @"ca-app-pub-6280395701552972/5217388242"; GADRequest *request = [GADRequest request]; [interstitial_ loadRequest:request]; } 

Implementaion

 -(void)failgame { //////////////////gaming code/////////// [interstitial_ presentFromRootViewController:self]; } 

在googleadmob SDK页面上,它说intertials是一次性使用对象所以我100%肯定这是问题,但没有什么可以解释如何多次调用它们所以只要你指出答案请不要告诉go读它我读过5次。

好吧没有人给出答案,但我确信还有其他一些人有同样的问题,所以对于那些想要多次调用间隙的人来说就是诀窍。

将它放入自己的方法并从main方法调用方法(多次回复)

保持你的viewdidload(或你想先开火)的间隙,因为如果你没有,那么你会错过第一次火,其他人将工作。

完整的代码。

 - (void) callint { int rNumber1 = arc4random() % 45 + 1; int rNumber2 = arc4random() % 45 + 1; if((rNumber1%2==1) && (rNumber1%1==0)) { [interstitial_ presentFromRootViewController:self]; interstitial_ = [[GADInterstitial alloc] init]; interstitial_.delegate = self; interstitial_.adUnitID = @"ca-app-pub-6280395701552972/5217388242"; GADRequest *request = [GADRequest request]; [interstitial_ loadRequest:request]; } } 

我把随机数创建,如果那里因为我不希望用户每次看到那些间隔,甚至调用int每次有4/1的机会它被触发,所以它显示1个插页式4-5火。

 - (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [self createAndLoadInterstitial]; } - (GADInterstitial *)createAndLoadInterstitial { GADInterstitial *interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910"]; interstitial.delegate = self; [interstitial loadRequest:[GADRequest request]]; return interstitial; } - (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial { self.interstitial = [self createAndLoadInterstitial]; } 

GADInterstitial是一次性使用对象。 要请求其他插页式广告,您需要分配新的GADInterstitial对象。

分配另一个插页式广告的最佳位置是在GADInterstitialDelegate上的interstitialDidDismissScreen:方法中,以便下一个插页式广告在上一次插页式广播解除后立即开始加载。 参考:admob网站链接

如果你按照Admob推荐的代码,正如Sonu VR所示,你将没有任何问题。 请注意,虽然使用最佳练习Admob代码会出现记录错误,但这是一个红鲱鱼。 这可能是Admob日志记录中的一个错误,但不是Admob代码中显示广告的错误。 您可以使用非测试手机对此进行测试,并在不同时间投放其他广告。