UIWebView完成加载后iAd插页式广告

时间:2015-02-14 14:09:57

标签: ios ipad iad interstitial

我想在调用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插页式广告。

1 个答案:

答案 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;
    }
}