GoogleMobileAds Framework Reference

GADBannerView

@interfaceGADBannerView:UIView

The view that displays banner ads. A minimum implementation to get an ad from within aUIViewController class is:

  // Create and setup the ad view, specifying the size and origin at {0, 0}.  GADBannerView *adView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];  adView.rootViewController = self;  adView.adUnitID = @ID created when registering your app;  // Place the ad view onto the screen.  [self.view addSubview:adView];  // Request an ad without any additional targeting information.  [adView loadRequest:[GADRequest request]];

  • Initializes and returns a banner view with the specified ad size and origin relative to thebanner’s superview.

    Declaration

    Objective-C

    -(nonnullinstancetype)initWithAdSize:(GADAdSize)adSizeorigin:(CGPoint)origin;
  • Initializes and returns a banner view with the specified ad size placed at its superview’sorigin.

    Declaration

    Objective-C

    -(nonnullinstancetype)initWithAdSize:(GADAdSize)adSize;
  • Required value created on the AdMob website. Create a new ad unit for every unique placement ofan ad in your application. Set this to the ID assigned for this placement. Ad units areimportant for targeting and statistics.

    Example AdMob ad unit ID: @ca-app-pub-0123456789012345/0123456789

    Declaration

    Objective-C

    @property(readwrite,copy,nonatomic,nullable)NSString*adUnitID;
  • Required reference to a root view controller that is used by the banner to present full screencontent after the user interacts with the ad. The root view controller is most commonly the viewcontroller displaying the banner.

    Declaration

    Objective-C

    @property(readwrite,nonatomic,nullable)UIViewController*rootViewController;
  • Required to set this banner view to a proper size. Never create your own GADAdSize directly.Use one of the predefined standard ad sizes (such as kGADAdSizeBanner), or create one using theGADAdSizeFromCGSize method. If not using mediation, then changing the adSize after an ad hasbeen shown will cause a new request (for an ad of the new size) to be sent. If using mediation,then a new request may not be sent.

    Declaration

    Objective-C

    @property(assign,readwrite,nonatomic)GADAdSizeadSize;
  • Optional delegate object that receives state change notifications from this GADBannerView.Typically this is a UIViewController.

    Declaration

    Objective-C

    @property(readwrite,nonatomic,nullable)id<GADBannerViewDelegate>delegate;
  • Optional delegate that is notified when creatives cause the banner to change size.

    Declaration

    Objective-C

    @property(readwrite,nonatomic,nullable)id<GADAdSizeDelegate>adSizeDelegate;
  • Requests an ad. The request object supplies targeting information.

    Declaration

    Objective-C

    -(void)loadRequest:(nullableGADRequest*)request;
  • A Boolean value that determines whether autoloading of ads in the receiver is enabled. Ifenabled, you do not need to call the loadRequest: method to load ads.

    Declaration

    Objective-C

    @property(getter=isAutoloadEnabled,assign,readwrite,nonatomic)BOOLautoloadEnabled;
  • The ad network class name that fetched the current ad. Returns nil while the latest ad requestis in progress or if the latest ad request failed. For both standard and mediated Google AdMobads, this property returns @GADMAdapterGoogleAdMobAds. For ads fetched via mediation customevents, this property returns @GADMAdapterCustomEvents.

    Declaration

    Objective-C

    @property(readonly,copy,nonatomic,nullable)NSString*adNetworkClassName;
  • Indicates whether the currently displayed ad (or most recent failure) was a result of autorefreshing as specified on server. This property is set to NO after each loadRequest: method.

    Declaration

    Objective-C

    @property(readonly,assign,nonatomic)BOOLhasAutoRefreshed;
  • Deprecated delegate. GADInAppPurchase is deprecated.

    Declaration

    Objective-C

    @property(readwrite,nonatomic,nullable)id<GADInAppPurchaseDelegate>inAppPurchaseDelegate;
  • The mediated ad network’s underlying ad view. You may use this property to read the ad’s actualsize and adjust this banner view’s frame origin. However, modifying the banner view’s frame sizetriggers the Mobile Ads SDK to request a new ad. Only update the banner view’s frame origin.

    Declaration

    Objective-C

    @property(readonly,nonatomic,nullable)UIView*mediatedAdView;

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2021-03-03 UTC.