我有一个小型游戏应用程序,它有一个故事板,里面创建了像开始菜单-游戏区域-分数这样的场景,我在其中添加了 admob 横幅视图和插页式广告。我的横幅视图工作正常,但我的插页式广告只能工作一次。
我在 viewdidload 上加载插页式广告,并在调用游戏会话结束的函数中触发它,正如我所说,它有效,但只有一次,当用户启动另一个游戏并失败时,这次没有插页式广告(下面的错误)。那又怎样呢?我应该修复它吗?我希望我的游戏能够在我需要的时候多次显示插页式广告。
错误 :
请求错误:不会发送请求,因为插页式对象已被使用。
Header:
#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];
}
执行
-(void)failgame
{
//////////////////gaming code///////////
[interstitial_ presentFromRootViewController:self];
}
在 googleadmob SDK 页面上,它说插页式广告是一次性使用对象,所以我 %100 确定这就是问题所在,但没有任何内容可以解释如何多次调用它们,所以只要您指出答案,请不要告诉 go读了它我已经读了5遍了。
好吧,没有人给出答案,但我确信还有其他一些人也遇到了同样的问题,所以对于那些想多次调用插页式广告的人来说,这里就是诀窍。
将其放入其自己的方法中,并从主方法中调用方法(该方法会回复多次)
将插页式广告保持在您的 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];
}
}
我将随机数创建和 if 放在那里,因为我不希望用户每次都看到这些插页式广告,即使每次调用 int 时都有 4/1 的机会触发,因此它会显示 1 个插页式广告,表示 4-5 次触发。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)