I've searched and searched and searched and searched for clarification on how to do this, but I still don't know how to do this correctly.
My predicament and what I want my result to be:
I have an ADBannerView
added to my storyboard, and the variable name where I implement it is bannerView
. I'm making an option to disable ads in the game. If ads are disabled, then ads shouldn't even load. If I'm correct, then the delegate's bannerViewWillLoadWithAd:
method shouldn't be called, nor should the bannerViewDidLoadAd:
method. I use this code, enclosed in an "if" statement, to remove the ADBannerView
from the view controller:
[bannerView removeFromSuperview];
[self setCanDisplayBannerAds:NO];
And then my delegate methods look like this (my delegate is my game scene, and the view controller is referenced by a property of said scene viewController1
):
-(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
NSLog(@"banner view action will begin.");
self.paused = YES;
return YES;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(@"Ad loaded.");
}
-(void)bannerViewWillLoadAd:(ADBannerView *)banner {
NSLog(@"Ad Banner will load ad.");
if (// ads are disabled) {
viewController1.canDisplayBannerAds = NO;
[banner removeFromSuperview];
NSLog(@"Banner shouldn't load");
}
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
NSLog(@"Ad Banner action did finish");
self.paused = NO;
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"Ad banner view failed to load. Details about the error: %@", error.debugDescription);
banner.hidden = YES;
}
The code works, but I end up getting errors and odd happenings in the logs, which typically include "service session terminated" when ads are supposed to show and ads loading when they're not supposed to. Any idea how to fix this?