AdMob in all my controllers?

I implemented AdMob and everything seems to work,
But I wonder how can I put a banner on all my controllers? So far I have a banner only on RootViewController.
I have only 4 controllers. Thank.

+5
source share
2 answers

What you want here is one of the tags GADBannerView. You can probably create a packaging class that will act as a singleton for your adView, so something like:

@interface GADMasterViewController : UIViewController {
  GADBannerView *adBanner_;
  BOOL didCloseWebsiteView_;
  BOOL isLoaded_;
  id currentDelegate_;
}

And just be sure to GADMasterViewControlleralways return singleton:

+(GADMasterViewController *)singleton {
  static dispatch_once_t pred;
  static GADMasterViewController *shared;
  // Will only be run once, the first time this is called
  dispatch_once(&pred, ^{
    shared = [[GADMasterViewController alloc] init];
  });
  return shared;
}

Have a method that flushes the current view controller that holds the adView ad:

-(void)resetAdView:(UIViewController *)rootViewController {
  // Always keep track of currentDelegate for notification forwarding
  currentDelegate_ = rootViewController;

  // Ad already requested, simply add it into the view
  if (isLoaded_) {
    [rootViewController.view addSubview:adBanner_];
  } else {

    adBanner_.delegate = self;
    adBanner_.rootViewController = rootViewController;
    adBanner_.adUnitID = kSampleAdUnitID;

    GADRequest *request = [GADRequest request];
    [adBanner_ loadRequest:request];
    [rootViewController.view addSubview:adBanner_];
    isLoaded_ = YES;
  }
}

- :

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    shared = [GADMasterViewController singleton];
    [shared resetAdView:self];
}

, , SDK AdMob , .

.

+5

, adMob, , , BaseViewController, adMob ( viewDidLoad), viewControllers BaseViewController. [super viewDidLoad]; viewDidLoad viewControllers, ...

, ...:)

+1

All Articles