我已经实施了AdMob框架并使其工作,因此它会显示但我需要每3次显示一个视图,我就会被卡住。
编辑:
@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倍,这意味着广告会显示奇数次。
答案 0 :(得分:1)
也许尝试将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);
}
}