gpt4 book ai didi

ios - Xcode - 每出现 x 次 View 就显示广告

转载 作者:行者123 更新时间:2023-11-29 12:17:34 25 4
gpt4 key购买 nike

我已经实现了 AdMob 框架并使其正常工作以便显示,但我需要每 3 次 View 显示一次广告,但我卡住了。

编辑:
@property (nonatomic, strong) GADInterstitial *interstitial;

到目前为止我有什么:

- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];


static long int counter = 1;



NSLog(@"Before: %ld", counter);

if ([self.interstitial isReady] && !(counter++ % 3)) {
[self.interstitial presentFromRootViewController:self];

counter = 1;
NSLog(@"After increase : %ld", counter);
}

}

问题是每次显示广告时,计数器都会增加 2 倍,这意味着广告显示奇数次。

最佳答案

也许尝试将 counter 声明为全局变量:

int counter;

然后做一些事情,例如:

- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];

if ([self.interstitial isReady] && counter >= 3) {
[self.interstitial presentFromRootViewController:self];
counter = 0;
} else {
counter++;
NSLog(@"After increase : %d", counter);
}
}

关于ios - Xcode - 每出现 x 次 View 就显示广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31631177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com