UIWebView 完成加载后的 iAd 插播

iAd interstitial after UIWebView did finish load

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

这可以简单地通过设置一个 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;
    }
}