I have done a fair bit of reading around on have found a few SO questions below: using shared instance of ADBannerView across app with UITableViews How to make a single shared instance of iAd banner throughout many view controllers? AdBannerView shared across multiple views, including the rootviewcontroller, how?
I would like to have a single ADBannerView that is loaded in my AppDelegate class in the didFinishLoading method. The hope is that this ADBannerView can then be retrieved by all of the relevant ViewControllers (by importing the AppDelegate.h) and then just displayed accordingly when the user moves between VC's.
The code that I have implemented is the following:
AppDelegate.h @interface AppDelegate : UIResponder
@property (strong, nonatomic) IBOutlet ADBannerView *adView;
@property (nonatomic, assign) BOOL bannerIsVisible;
- (ADBannerView *)sharedAdBannerView;
AppDelegate.m
ADBannerView *adView;
BOOL bannerIsVisible;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions(NSDictionary *)launchOptions
{
// create the iAdBannerView
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
adView.delegate=self;
self.bannerIsVisible=NO;
// Override point for customization after application launch.
return YES;
}
#pragma begin of iAdBannerView Delegate Methods
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (ADBannerView *)sharedAdBannerView
{
return adView;
}
I have also tried a variation using the [NSNotificationCenter defaultCenter] postNotificationName: methods but in the end I am faced with the same issue:
Problem: In the ViewController I want to display the ADBannerView how do I retrieve it from the AppDelegate?
I have currently:
ADBannerView *banner = [[UIApplication sharedApplication] sharedAdBannerView];
[self.view addSubview:banner];
But I am getting a multitude of errors and cannot seem to get around it.
Error: No visible @interface for UIApplication declares the sector sharedAdBannerView.
I'm sure I'm missing something pretty fundamental.
Any help would be greatly appreciated... Thanks, James