Banner Ads

Set up a Banner Ad

  1. From the left navigation panel, select Inventory Inventory Settings.
  2. Search for the app or website you would like to create a placement for and click + Add a placement.
  3. Click Select Ad Unit and select Banner.
  4. Click Add a placement to start setting up your banner settings. After you create the banner placement, you can see the placement ID.

Add the Banner Ad to your App

Creating a Banner Ad

The IMBanner is simply a UIView subclass displaying HTML ads. The InMobi SDK provides two mechanisms to implement a banner ad:

Programmatic Instantiation

1. Import the headers and declare a Banner instance in your ViewController.h file or import the frameworks and declare a Banner instance in your ViewController.swift file. Your ViewController header file should look like this:

Objective C

#import <UIKit/UIKit.h> 
@import InMobiSDK; 
@interface ViewController : UIViewController <IMBannerDelegate> 
@property (nonatomic, strong) IMBanner *banner; 
@end

Swift

import UIKit
import InMobiSDK
class ViewController: UIViewController, IMBannerDelegate {
    var banner: IMBanner?
}

2. Instantiate the banner object. Your ViewController.m file should look like this:

Objective C

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.banner = [[IMBanner alloc] initWithFrame: CGRectMake(0, 0, 320, 50) placementId:<placementId>]; 
    self.banner.delegate = self; 
    [self.view addSubview:self.banner]; 
    [self.banner load]; 
}

Swift

override func viewDidLoad() {
        super.viewDidLoad()
        banner = IMBanner.init(frame: CGRect(x: 0, y: 0, width: 320, height:
            50), placementId: <Insert your placement ID here>)
        banner?.delegate = self
        view.addSubview(banner!)
        banner?.load()
        // Use this API to enable or disable auto refresh
        banner?.shouldAutoRefresh(true)
        // Use this API to set a custom refresh interval on the banner
        banner?.refreshInterval = <refresh interval>
    }

By default, IMBanner refreshes after every 60 seconds. You can also set a custom refresh interval or turn off AutoRefresh to manually load ads. For both manual load and Auto Refresh, the minimum time interval between two successive ad loads should be 20 seconds.

Objective-C

// to turn off auto refresh set the below value to NO.
[self.banner shouldAutoRefresh:NO];

//to set custom refresh interval
[self.banner setRefreshInterval:40];

Swift

// to turn off auto refresh set the below value to NO.   banner?.shouldAutoRefresh(false).   //to set custom refresh interval banner?.refreshInterval = 40

3. If at any time you want to release the banner, use the cancel API:

Objective-C

[self.banner cancel];
self.banner.delegate = nil;
self.banner = nil;

Swift

self.banner.cancel();
self.banner.delegate = nil
self.banner = nil

4. For ad status callbacks, implement the delegate methods of IMBannerDelegate. We support the following callbacks:

Objective C

// Notifies that the ad is received with Meta info. 
- (void)banner:(IMBanner*)banner didReceiveWithMetaInfo:(IMAdMetaInfo*)info {
    NSLog(@"Banner Ad is received")
}
- (void)bannerDidFinishLoading:(IMBanner *)banner {
    NSLog(@"bannerDidFinishLoading");
}
- (void)banner:(IMBanner *)banner didFailToLoadWithError:(IMRequestStatus *)error {
    NSLog(@"banner failed to load ad");
    NSLog(@"Error : %@", error.description);
}
- (void)bannerWillPresentScreen:(IMBanner *)banner {
    NSLog(@"bannerWillPresentScreen");
}
- (void)bannerDidPresentScreen:(IMBanner *)banner {
    NSLog(@"bannerDidPresentScreen");
}
- (void)bannerWillDismissScreen:(IMBanner *)banner {
    NSLog(@"bannerWillDismissScreen");
}
- (void)bannerDidDismissScreen:(IMBanner *)banner {
    NSLog(@"bannerDidDismissScreen");
}
- (void)userWillLeaveApplicationFromBanner:(IMBanner *)banner {
    NSLog(@"userWillLeaveApplicationFromBanner");
}
-(void)banner:(IMBanner *)banner didInteractWithParams:(NSDictionary *)params{
    NSLog(@"bannerdidInteractWithParams"); 
}
-(void)banner:(IMBanner*)banner rewardActionCompletedWithRewards:(NSDictionary*)rewards{
    NSLog(@"rewardActionCompletedWithRewards");
}

Swift

public func banner(_ banner: IMBanner, didReceiveWithMetaInfo info: IMAdMetaInfo) {
        print("Banner Ad is received")
    }
    public func bannerDidFinishLoading(_ banner: IMBanner) {
        print("[ViewController %@] \(#function)")
    }
    public func banner(_ banner: IMBanner, didFailToLoadWithError error: IMRequestStatus) {
        print("[ViewController %@] \(#function)")
        print("Banner ad failed to load with error: \(error)")
    }
    public func banner(_ banner: IMBanner, didInteractWithParams params: [String : Any]?) {
        print("[ViewController %@] \(#function)")
    }
    public func userWillLeaveApplicationFromBanner(_ banner: IMBanner) {
        print("[ViewController %@] \(#function)")
    }
    public func bannerWillPresentScreen(_ banner: IMBanner) {
        print("[ViewController %@] \(#function)")
    }
    public func bannerDidPresentScreen(_ banner: IMBanner) {
        print("[ViewController %@] \(#function)")
    }
    public func bannerWillDismissScreen(_ banner: IMBanner) {
        print("[ViewController %@] \(#function)")
    }
    public func bannerDidDismissScreen(_ banner: IMBanner) {
        print("[ViewController %@] \(#function)")
    }
    public func banner(_ banner: IMBanner, rewardActionCompletedWithRewards rewards: [String : Any]) {
        print("[ViewController %@] \(#function)")
    }

You can use the following transitions while refreshing your banner object:

Objective C

  • UIViewAnimationTransitionNone
  • UIViewAnimationTransitionFlipFromLeft
  • UIViewAnimationTransitionFlipFromRight
  • UIViewAnimationTransitionCurlUp
  • UIViewAnimationTransitionCurlDown

Swift

  • none
  • flipFromLeft
  • flipFromRight
  • curlUp
  • curlDown

Objective C

self.banner.transitionAnimation = UIViewAnimationTransitionCurlUp;

Swift

banner?.transitionAnimation = .curlUp

Using Interface Builder

  1. Place the UIView in your ViewController’s view at the position where the ad should be displayed.
  2. Set the banner frame.
  3. Set the Class Identity of the UIView to IMBanner.
  4. In your ViewController header file, declare an IBOutlet instance of IMBanner.
  5. Set this as your outlet in your UIView(Banner) in the ViewController Scene in the Storyboard.
  6. In viewDidLoad(), enter the banner.placementId = <insert placement id>.

On This Page

Last Updated on: 07 Jun, 2023