[英]IOS Admob Interstitial for objective-c
我已经在viewDidLoad上实现了插页式广告,但是我需要与此相关的帮助。 我希望Interstitial不会在每次出现viewDidLoad时都显示,例如,我希望它一次显示一次,一次不显示。
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"a151b7d316a5c1d"];
self.interstitial.delegate = self;
[self.interstitial loadRequest: [GADRequest request]];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
[interstitial presentFromRootViewController:self];
}
我对广告进行相同的一对一的处理。 我只是使用用户默认值来保存计数器。 也许尝试以下方法。 下面的代码写得很清楚,所以有点长,但是一旦知道它在做什么,就可以进入并拧紧它(例如,使用adCount += 1;
而不是adCount = adCount + 1;
等等。希望如此)帮助!
- (void)viewDidLoad
{
[super viewDidLoad];
//Call to your helper method
//Stop viewDidLoad here if the method returns NO
if (![self _shouldShowInterstitial]) return;
self.interstitial = [[GADInterstitial alloc];
initWithAdUnitID:@"a151b7d316a5c1d"];
self.interstitial.delegate = self;
[self.interstitial loadRequest: [GADRequest request]];
}
- (BOOL)_shouldShowInterstitial
{
//1. Recover user default holding a counter
BOOL retVal = NO;
NSString *adKey = @"shouldShowInterstitialOnLoadDefaultKey";
NSInteger adCount = [[NSUserDefaults standardUserDefaults]integerForKey:adKey];
//2. If the counter is 1, return YES for showing an ad and reset the count to 0
if (adCount > 0) {
retVal = YES;
adCount = 0;
//3. If the count is 0, no ad is required, but increment it so next time the ad will show
} else {
retVal = NO;
adCount = adCount + 1;
}
//4. Save your defaults
[[NSUserDefaults standardUserDefaults] setInteger:adCount forKey:adKey];
[[NSUserDefaults standardUserDefaults] synchronize];
//5. Return your bool value
return retVal;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.