我想在调用webViewdidFinishLoad
后只显示一次iAd插页式广告。
-(void)viewWillAppear:(BOOL)animated {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self cycleInterstitial];
[self performSelector:@selector(presentInterlude) withObject:nil afterDelay:300];
}
}
-(void)cycleInterstitial {
// Clean up the old interstitial...
interstitial.delegate = nil;
// and create a new interstitial. We set the delegate so that we can be notified of when
interstitial = [[ADInterstitialAd alloc] init];
interstitial.delegate = self;
}
-(void)presentInterlude {
// If the interstitial managed to load, then we'll present it now.
if (interstitial.loaded) {
NSLog(@"Loaded inter");
[interstitial presentFromViewController:self];
} else {
NSLog(@"Not Loaded inter");
}
}
-(void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd {
[self cycleInterstitial];
}
-(void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error {
NSLog(@"interstitialAd error: %@",error.description);
}
这有效,但我想在webViewdidfinishload
之后只展示一个iAd插页式广告。
答案 0 :(得分:0)
这可以通过设置BOOL
来检查是否已显示ADInterstitialAd
来完成。
@implementation ViewController {
BOOL doNotShowAd;
}
-(void)viewWillAppear:(BOOL)animated {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && doNotShowAd == NO) {
[self cycleInterstitial];
[self performSelector:@selector(presentInterlude) withObject:nil afterDelay:300];
doNotShowAd = YES;
}
}