Banner Integration
Banner ads usually appears at the top or bottom of your app’s screen. Adding one to your app takes just a few lines of code.
Prerequisites:
Before integrating banner ads in your app, you’ll need to go through the steps in our Getting Started Guide to integrate the SDK into your project.
Basic integration
Adding a banner to your application takes only a few, easy steps:
- In your view controller's header file:
- Import the
INAdView.hheader file and declare anINAdView *adViewproperty. - Declare that your view controller implements the
INAdViewDelegateprotocol.
- Import the
- In your view controller's implementation file, instantiate an INAdView, passing in your ad unit ID. This is typically done in
-viewDidLoad. - Register your view controller as the
adView's delegate. - Implement the
-viewControllerForPresentingModalViewINAdViewDelegatemethod. TheadViewwill use the view controller returned by this method to present modals when tapped. Typically your controller can simply return self. - Finally, load an ad by sending adView the
-loadAdmessage.
Sample Code
- (void)viewDidLoad {
[super viewDidLoad];
self.adView = [[INAdView alloc] initWithAdUnitId:@"YOUR_ADUNIT_ID"];
self.adView.delegate = self;
[self.bannerContainer addSubview:self.adView];
[self.adView loadAd];
}
Implement non optional INAdViewDelegate protocol
#pragma mark - <INAdViewDelegate>
- (UIViewController *)viewControllerForPresentingModalView {
return self;
}
Delegates
Detecting When a Banner Ad is Loaded
- (void)adViewDidLoadAd:(INAdView *)view;
- (void)adViewDidFailToLoadAd:(INAdView *)view;
Detecting When a User Interacts With the Ad View */
- (void)willPresentModalViewForAd:(INAdView *)view;
- (void)didDismissModalViewForAd:(INAdView *)view;
- (void)willLeaveApplicationFromAd:(INAdView *)view;
A complete ViewController is available in sample app.