ios-guidelines | Banner Ads

Banner Ads are graphical ad, typically including a combination of static/animated images and text designed to convey a marketing message and/or cause the user to take an action. All types of apps can leverage banner ads for monetization.

Follow these steps to start monetizing with Banner ads:

Setting up a Banner Ad

After adding your app, select BANNER AD to create a placement for ad type Banner.

Once you create the banner placement, you will have the placement id.

Creating a Banner Ad

The IMBanner is simply a UIView subclass displaying HTML5 ads that respond to user touch.

The InMobi SDK provides two mechanisms to implement a banner ad:

a. Programmatic Instantiation

  1. Import the headers and declare a Banner instance in your ViewController.h file. Your ViewController header file should look like this:
    #import <UIKit/UIKit.h>
    @import InMobiSDK;
    @interface ViewController : UIViewController <IMBannerDelegate>
    @property (nonatomic, strong) IMBanner *banner;
    @end
    		
  2. Instantiate the banner object. Your ViewController.m file should look like this:
    - (void)viewDidLoad {
     [super viewDidLoad];
    self.banner = [[IMBanner alloc] initWithFrame:CGRectMake(0, 0, 320, 50)
    placementId:@"Insert your placement ID here"];
    self.banner.delegate = self;
    [self.view addSubview:self.banner];
    [self.banner load];
    //[self.banner shouldAutoRefresh:YES];
    //[self.banner setRefreshInterval:90];
    }
    		

    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.

  3. Set the delegate to nil in the dealloc method of your UIViewController, or at any time when you are releasing the banner.
    -(void)dealloc {
    self.banner.delegate = nil;
    }
    		
  4. For ad status callbacks, implement the delegate property of IMBanner. The following callbacks are supported:
    /*Indicates that the banner has received an ad. */
    - (void)bannerDidFinishLoading:(IMBanner *)banner {
        NSLog(@"bannerDidFinishLoading");
    }
    /* Indicates that the banner has failed to receive an ad */
    - (void)banner:(IMBanner *)banner didFailToLoadWithError:(IMRequestStatus *)error {
        NSLog(@"banner failed to load ad");
        NSLog(@"Error : %@", error.description);
    }
     /* Indicates that the banner is going to present a screen. */
    - (void)bannerWillPresentScreen:(IMBanner *)banner {
        NSLog(@"bannerWillPresentScreen");
    }
    /* Indicates that the banner has presented a screen. */
    - (void)bannerDidPresentScreen:(IMBanner *)banner {
        NSLog(@"bannerDidPresentScreen");
    }
    /* Indicates that the banner is going to dismiss the presented screen. */
    - (void)bannerWillDismissScreen:(IMBanner *)banner {
        NSLog(@"bannerWillDismissScreen");
    }
    /* Indicates that the banner has dismissed a screen. */
    - (void)bannerDidDismissScreen:(IMBanner *)banner {
        NSLog(@"bannerDidDismissScreen");
    }
    /* Indicates that the user will leave the app. */
    - (void)userWillLeaveApplicationFromBanner:(IMBanner *)banner {
        NSLog(@"userWillLeaveApplicationFromBanner");
    }
    /*  Indicates that the banner was interacted with. */
    -(void)banner:(IMBanner *)banner didInteractWithParams:(NSDictionary *)params{
        NSLog(@"bannerdidInteractWithParams");
    }
    /*Indicates that the user has completed the action to be incentivised with .*/
    -(void)banner:(IMBanner*)banner rewardActionCompletedWithRewards:(NSDictionary*)rewards{
        NSLog(@"rewardActionCompletedWithRewards");
    }
    		
  5. You can use the following transitions while refreshing your banner object:
    • UIViewAnimationTransitionNone
    • UIViewAnimationTransitionFlipFromLeft
    • UIViewAnimationTransitionFlipFromRight
    • UIViewAnimationTransitionCurlUp
    • UIViewAnimationTransitionCurlDown
    self.banner.transitionAnimation = UIViewAnimationTransitionCurlUp;
    		

b. Creating a Banner Instance through 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.

Retrieving CreativeID

At times, there are rogue advertisers who escape all the ad quality checks and end up compromising the user experience on the app by showcasing either an irrelevant, distasteful or disrupting creative to the user. To combat such situations, you can retrieve the creativeID of the ad instance and report back to your InMobi point of contact with the encrypted creativeID.

mBannerAd.creativeId // mBannerAd is an example instance.

Testing the Integration

  1. Configure the test mode on InMobi portal.

    Go to Tools - Diagnostics and switch Test Mode to either Global ON or Selective ON.

    If you are integrating an ad unit for the first time Set Test Mode to Global ON.
    If you want to selectively turn on test traffic for a set of devices·

    You already have a prior version of the SDK integrated for this particular ad unit and therefore you should restrict your testing to only few devices
    Set Test Mode to Selective ON.

    In the device section:

    1. In the Device ID box, type the device ID.
    2. In the Device Name box, set any name.
    3. Click Add Device to add the test device.

    If you already have a device configured, you can select the device and test mode would be enabled.

    Note: You MUST turn off the test mode before going live or else your app will fail to monetize.

    Now you are all set to get test ads.

    Getting the Device ID

    The device id is basically the IDFA or IFA (Identifier for Advertising). To get device ID, the easiest approach is to set the log level of the SDK to “debug”. To enable debug logs, add this to didFinishLaunchingWithOptions method within the AppDelegate.m file, as shown below:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {    
    	//Initialize InMobi SDK with your account ID
    [IMSdk initWithAccountID:@"Insert InMobi account ID here"];
    //Set log level to Debug
    [IMSdk setLogLevel:kIMSDKLogLevelDebug]; 
    	// Do your stuff.
    	return YES;
    }
    		

    In the debug mode, the device ID will be logged on XCode developer console as: “Publisher device ID is <device-id>”

    You can enter this device id in the Device ID box.

  2. You will also get feedback on the diagnostics tab on the ad unit and ad request and this can be particularly helpful during integration.

  3. You should also see these key InMobi SDK logs in console when a banner ad is successfully loaded:

    [InMobi] InMobi SDK initialized with account id: <your account id here>

    [InMobi] Fetching Banner ad for placement id: <your placement id here>

    [InMobi] Publisher device id is <device id here>

    [InMobi] Banner ad successfully fetched for placement id: <your placement id here>

  4. Now you would also see the InMobi test ads on your application.
  5. If the SDK is not initialised correctly before creating an ad, you would typically see these logs :

    ** ERROR ** [InMobi] ___ Please initialize the SDK before creating a <ad format> ad.

    ** ERROR ** [InMobi] ___ Account id cannot be null or empty. Please provide a valid Account id.

    [InMobi] Invalid account id passed to init. Please provide a valid account id.

The complete set of key logs are documented in the following tables.

SDK Initialization

Scenario Log Level Logs
Publisher passed null or empty account id Error Account id cannot be null or empty. Please provide a valid Account id.
Publisher passed a valid account id Debug InMobi SDK initialized with account id: <account id>
Publisher passed an invalid account Id Error Invalid account id passed to init. Please provide a valid account id.
Newer version of SDK is available Debug A newer version (ver. 6.0.0) of the InMobi SDK is available! You are currently on an older version (ver. 5.3.1). Download the latest InMobi SDK from http://www.inmobi.com/products/sdk/#downloads

Ads Common

Scenario Log Level Logs
Ad requested when no network available Error Network not reachable currently. Please try again.
Ad requested when ad state is loading or available Error An ad load is already in progress. Please wait for the load to complete before requesting for another ad (Placement id :<placement id> ).
Ad requested when ad is viewed by user Error An ad is currently being viewed by the user. Please wait for the user to close the ad before requesting for another ad (Placement id : <placement id> ).
Publisher device Id Debug Publisher device id is <Device Id>

Banner Ads

Scenario Log Level Logs
Publisher created a banner without initializing the SDK Error Please initialize the SDK before creating a Banner ad
Publisher created a banner with an invalid/null placement id Error Please provide a valid placement id to create a Banner ad
Publisher called load on a banner from IB/xml with improper placement id Error Please provide a valid placement id to create a Banner ad
Publisher called load on a banner Debug Fetching a Banner ad for placement id: <placement id>
Successfully fetched ad Debug Banner ad successfully fetched for placement id: <Placement id>
Failed to fetch the ad Debug Failed to fetch Banner ad for placement id:<Placement id> with error: <Status code / message>
Started loading the banner in a webview Debug Started loading Banner ad markup in the webview for placement id: <Placement id>
Banner successfully loaded in the webview Debug Successfully loaded Banner ad markup in the webview for placement id: <placement id>
Failed to load banner in the webview Debug Failed to load the Banner markup in the webview for placement id: <placement id>
Banner refresh is initiated Debug Initiating Banner refresh for placement id: <placement id>