ios | iOS SDK Integration Guide

What is the InMobi iOS SDK?

The InMobi iOS SDK allows you to monetize your iOS app with a wide range of ad formats. From banner ads to full-screen native interstitial ads, video ads, and native content ads, to our newly introduced rewarded video and playable ads, you can deliver ads from the InMobi Network in any shape and form for a better user experience. All with one unified SDK.

Note: The InMobi iOS SDK 5.1 has been designed to support iOS 7 and above only.

Also, this version of the InMobi SDK requires XCode 7.0 and above.

Important:
InMobi strongly recommends that users still on InMobi SDK 4.5, and below, upgrade to SDK 5.0 immediately as it contains substantial performance and stability improvements.

Getting Started

To get started with the integration, complete the following steps:

  1. Create your account. See here for instructions.
  2. Register your property.
    You require a valid iTunes App Store (app/site) URL to monetize with InMobi, enter the app URL to get your app approved and see live ads. If your app is not yet live, you can still continue to integrate, however, you will see only test ads from InMobi and the dashboard will show your property in a Pending state until you verify your property.
  3. Go to the Properties tab and click the spanner icon next to your property. Your Placement ID is displayed. Copy this value and use it in the integration code.
  4. Download the InMobi Ad Network SDK for iOS. This bundle also contains a sample app.

Adding the SDK to your Project

Copy the following header files and binary from the downloaded SDK bundle to your project.

  • libInMobi-5.x.x.a
  • IMSdk.h
  • IMBanner.h
  • IMBannerDelegate.h
  • IMInterstitial.h
  • IMInterstitialDelegate.h
  • IMNative.h
  • IMNativeDelegate.h
  • IMCustomNative.h
  • IMRequestStatus.h
  • IMCommonConstants.h

Adding Frameworks

Add the following frameworks to your Xcode project:

  • AdSupport.framework
  • AudioToolbox.framework
  • AVFoundation.framework
  • CoreLocation.framework
  • CoreTelephony.framework
  • CoreGraphics.framework
  • EventKit.framework
  • EventKitUI.framework
  • Foundation.framework
  • MediaPlayer.framework
  • MessageUI.framework
  • Security.framework
  • Social.framework
  • StoreKit.framework
  • SystemConfiguration.framework
  • UIKit.framework
  • SafariServices.framework
  • libsqlite3.0.tbd
  • libc++.tbd
  • libz.tbd

Note: Set NSLocationWhenInUseUsageDescription flag to YES in your info.plist file.

Note:

  • InMobi does not use information regarding wifi access points for inferring a user's location in the United States, Europe, Australia and Singapore, unless the user has explicitly provided consent to the app developer for accessing their location.
  • In other markets, InMobi may utilise information regarding wifi access points for inferring a user’s location, to the extent such inference is not limited or restricted by applicable local privacy laws. Inferred location information from devices obtained shall be used for serving ads considering the location context of the device (postcode, city and so on) and building aggregate user segments based on device location history.
  • Notwithstanding the above, InMobi may use names of WIFI Access Points that the user has connected to for creating segments of users such as "Coffee Shop Regulars", "Frequent Flyers" and so on.
  • Please note that we would be compliant with all relevant privacy guidelines as InMobi does not collect any personal identifiable information such as name, email id, mobile number and so on.

Adding Additional Build Settings

Add the -ObjC flag to the Other Linker Flags to load all the classes when using Categories. To do so, complete the following steps:

  1. Open your project in Xcode.
  2. Select Application Target > Build Settings.
  3. In the Search field, search for 'Other Linker Flags'.
  4. Add the -ObjC flag.

Targeting your App for iOS 9

A key feature in iOS9, Application Transport Security (ATS) is a new default setting that mandates apps to make network connections only over TLS ver. 1.2 and above. Though InMobi is committed towards the adoption of HTTPS, the current setup requires our demand partners to support this change and be 100% compliant with all the requirements of ATS.

While we work with our partners progressing towards a secure environment, to ensure ads serve on iOS 9 and above devices, we would need you to follow these steps as a near-term fix:

  • Disable ATS (Recommended) to ensure non-secure content from the partners works correctly in your updated apps. To disable ATS flag, please add the following code snippet to your app's Info.plist.

    <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    </dict>
  • Disable ATS with exceptions (Not Recommended), in case you plan to migrate towards ATS compliance. You can achieve so by allowing secure content from your domains by adding them on the exception list. You can read more here.
    Note: Refrain from using InMobi domains and CDN in the exception list as it will result in errors during the runtime.

Integrating with the InMobi SDK

Adding Imports

Import the "InMobi.h" and "IMCommonConstants.h" in the AppDelegate header file, as shown below:

#import "IMSdk.h"#import "IMCommonConstants.h"
		

Initializing the SDK

In the first step to integrate with InMobi, you need to initialize the InMobi SDK. The InMobi SDK requires your InMobi Account ID (Publisher ID) for initialization. Use this ID while integrating the InMobi SDK. It is mandatory to initialize the SDK during app launch. Your account ID is available in your InMobi account as illustrated in the screenshot below:

Initialize the SDK in the didFinishLaunchingWithOptions method within the app delegate's .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"];
// Do your stuff.
return YES;
}
		

Creating a Banner Ad

Banner ads are the most common ad format. They consist of an image with a hypertext link that takes the user to the website. These ads display either statically on the page, or sometimes with an incorporated animation. Banners are small ads that, when clicked, typically take the user to some form of a full screen, in-app browsing experience.

To add a banner to your application create an instance of IMBanner and implement IMBannerDelegate. The IMBanner class takes care of fetching an ad and passing it to the application, while IMBannerDelegate gives ad status callbacks.

iOS apps are composed of UIView objects, Objective-C instances seen by the user as text areas, buttons, and other controls. The IMBanner is simply a UIView subclass displaying small HTML5 ads that respond to user touch. It is easy to create IMBanner in code.

To get a banner ad, complete the following steps:

Step 1: Creating a Banner Instance

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

  • Option A: Programmatic instantiation
  • Option B: Through the interface builder

Both the above methods result in the same outcome - a banner ad displayed within your app. The two methods are detailed below:

Option A: Creating IMBanner Programatically

To display a banner ad, you will need a banner placement ID. To create a new placement ID, please refer to the Getting Started section of this document. If you have already created a placement, please follow the steps outlined here to obtain the placement ID.

Initialize the banner with the placement ID. And complete the below steps:

  1. Import the IMBanner.h and IMBannerDelegate.h files. Then, declare a banner instance in the header file. Your header file should look like:
    #import <UIKit/UIKit.h>
    #import “IMBanner.h”
    #import “IMBannerDelegate.h”
    #import “IMRequestStatus.h”@interface ViewController : UIViewController <IMBannerDelegate>
    @property (nonatomic, strong) IMBanner *banner;
    @end
    			
  2. Create an instance of IMBanner in your ViewController. We recommend you to do this is viewDidLoad method of your ViewController:
    -(void)viewDidLoad {
    self.banner = [[IMBanner alloc] initWithFrame:CGRectMake(0, 0, 320, 50) 
    placementId:<Insert InMobi placement ID here>];
    }
    			
  3. Set the delegate property of IMBanner as your view controller before loading the ad. This is so that you will be notified about success or failure. self.banner.delegate = self;
  4. Add your adview to the main view before loading the ad.
    [self.view addSubview:self.banner];
    Next, load the banner ad using:
    [self.banner load];
    The minimum time between two successive loads must be at least 20 seconds.
    Your viewcontroller class should look like:
  5. - (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 loadBanner];
    }
    			
  6. We recommend that you 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;
    }
    			
  7. Getting Callbacks. If you need ad status callbacks, implement the delegate property of the IMBanner. See IMBannerDelegate.h for the list of available callbacks. The user can perform necessary action on receiving callback.
    Implement the required delegate for banner ad success and failure methods, as shown below.
    /*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");
    }
    /* banner:didInteractWithParams: Indicates that the interstitial was interacted with. */
    -(void)banner:(IMBanner *)banner didInteractWithParams:(NSDictionary *)params{
    NSLog(@"bannerdidInteractWithParams");
    }
    			

Option B: Creating the Banner Instance through the Interface Builder

You can also add an IMBanner to your UIViewController using the Storyboard by completing the following steps:

  1. Place the UIView in your ViewController’s view at the position where the ad must be displayed.
  2. Set the frame as per the InMobi ad request.
  3. Set the Class Identity of the UIView to IMBanner.
  4. In your ViewController.h file, declare an IBOutlet instance of IMBanner.
  5. Set this as your outlet in your UIView(Banner) in the ViewController Scene in the Storyboard.

Testing the Integration

Set your property in test mode as described here.

Advanced Settings

Setting Auto Refresh

After you create an IMBanner and set a refresh interval, the ad will refresh automatically. The default refresh interval set is 60 seconds.

To switch off the auto refresh feature, use the method shown below before loading the ad.

[self.banner shouldAutoRefresh:NO];
		

To set a custom refresh interval, set the same property:

[self.banner setRefreshInterval:90];
		

Manually Loading Ads

To manually load a new ad, use the below method:

[self.banner load];
		

Setting keywords and extra information

NSArray *arrKeys = [[NSArray alloc] initWithObjects:@"tp",nil];
NSArray *arrValues = [[NSArray alloc] initWithObjects:@"admob", nil];
NSDictionary *dict = [[NSDictionary alloc] initWithObjects: arrValues forKeys:arrKeys];
self.banner.extras = dict;
self.banner.keywords = @”news";
		

Setting banner refresh transition animation

self.bannerView.transitionAnimation = UIViewAnimationTransitionCurlUp;
		

Creating an Interstitial or Native Interstitial Ad

Interstitial ads are full screen ads (either static image or video) that are modal in nature. They appear to users either before the launch of an application or at transition points, such as between game levels, or between the homepage and a unique content page. The richer nature of these ads makes them more expensive and subject to impression constraints.
InMobi serves both landscape and portrait type of interstitial ads. The InMobi SDK will automatically ensure that it serves appropriate ads as per the application orientation.

Note:

  • By default, InMobi serves a mix of video or static ads based on your app. If you would like to serve only videos on this slot, please edit the ad controls appropriately.
  • In order to implement a native frame for your interstitial property, please refer to our help article on Native Interstitials.

While configuring the SDK, you have already initialized the InMobi SDK with the appropriate account ID. For interstitial integration use the placement id configured for interstitial ads. If you have missed this configuration step, InMobi will fail to load the interstitial ad.

Interstitial Interface To add an Interstitital to your application create an instance of IMInterstitial and implement IMInterstitialDelegate. The IMInterstitial class takes care of fetching an ad and passing it to user, while IMInterstitialDelegate gives ad status callbacks.

Step 1: Implementing an Interstitial Ad

The configuration steps for interstitial ads are similar to those for banner ads. To get an interstitial ad, perform the following steps:

  1. Import IMInterstitial.h and IMInterstitialDelegate.h. Declare an interstitial instance in the header file. Your header file should look like this:
    #import <UIKit/UIKit.h>
    #import "IMInterstitial.h"
    #import "IMInterstitialDelegate.h"
    #import "IMRequestStatus.h"
    @interface ViewController : UIViewController <IMInterstitialDelegate>
    @property (nonatomic, strong) IMInterstitial *adInterstitial;
    @end
    			
  2. Create an Interstitial ad instance using below method: self.adInterstitial = [[IMInterstitial alloc] initWithPlacementId:<Insert your placement ID here>];
  3. After creating an interstitial instance, set the delegate property of IMInterstitial as your view controller before loading the ad. This is so that you will be notified about the ad receiving success or failure. self.adInterstitial.delegate = self;
  4. Load the ad using the following method:

    [self.adInterstitial load];

    Your viewcontroller class should look like the following:

    - (void)viewDidLoad {
    [super viewDidLoad];
    self.adInterstitial = [[IMInterstitial alloc] initWithPlacementId:@"Insert your placement ID here"];
    self.adInterstitial.delegate = self;
    [self.adInterstitial load];
    }
    			

    The minimum time between two successive loads must be at least 20 seconds.

  5. Next, call the below to show the ad, preferably in interstitialDidFinishLoading: callback.
    if ([self.adInterstitial isReady]) {
    [self.adInterstitial showFromViewController:self];
    }
    			
  6. Set the delegate to nil in the dealloc method, or at any other time when you are releasing the interstitial.
    - (void)dealloc {
    self.adInterstitial.delegate = nil;
    }
    			
  7. Getting callbacks. If you want ad status callbacks, implement the delegate property of the IMInterstitial. See IMInterstitialDelegate.h for the list of available callbacks. The user can perform necessary actions on callbacks relieved. These are the list of callbacks:
    /*Indicates that the interstitial has received an ad. */
    - (void)interstitialDidFinishLoading:(IMInterstitial *)interstitial {
    NSLog(@"interstitialDidFinishLoading");
    }
    /* Indicates that the interstitial has failed to receive an ad */
    - (void)interstitial:(IMInterstitial *)interstitial didFailToLoadWithError:(IMRequestStatus *)error {
    NSLog(@"Interstitial failed to load ad");
    NSLog(@"Error : %@",error.description);
    }
    /* Indicates that the interstitial has failed to present itself. */
    - (void)interstitial:(IMInterstitial *)interstitial didFailToPresentWithError:(IMRequestStatus *)error {
    NSLog(@"Interstitial didFailToPresentWithError");
    NSLog(@"Error : %@",error.description);
    }
    /* indicates that the interstitial is going to present itself. */
    - (void)interstitialWillPresent:(IMInterstitial *)interstitial {
    NSLog(@"interstitialWillPresent");
    }
    /* Indicates that the interstitial has presented itself */
    - (void)interstitialDidPresent:(IMInterstitial *)interstitial {
    NSLog(@"interstitialDidPresent");
    }
    /* Indicates that the interstitial is going to dismiss itself. */
    - (void)interstitialWillDismiss:(IMInterstitial *)interstitial {
    NSLog(@"interstitialWillDismiss");
    }
    /* Indicates that the interstitial has dismissed itself. */
    - (void)interstitialDidDismiss:(IMInterstitial *)interstitial {
    NSLog(@"interstitialDidDismiss");
    }
    /* Indicates that the user will leave the app. */
    - (void)userWillLeaveApplicationFromInterstitial:(IMInterstitial *)interstitial {
    NSLog(@"userWillLeaveApplicationFromInterstitial");
    }
    /* Indicates that a reward action is completed */
    - (void)interstitial:(IMInterstitial *)interstitial rewardActionCompletedWithRewards:(NSDictionary *)rewards {
    NSLog(@"IncentActionCompleted Publisher Callback successfully received");
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"incentivisedAd - params" message:[NSString stringWithFormat:@"%@",rewards] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
    [alert show];
    }
    /* interstitial:didInteractWithParams: Indicates that the interstitial was interacted with. */
    - (void)interstitial:(IMInterstitial *)interstitial didInteractWithParams:(NSDictionary *)params {
    NSLog(@"InterstitialDidInteractWithParams");
    }
    			

    Notes:

    • Check that the current state of the interstitial ad is ready before making the call to showFromViewController. Otherwise, the error callback interstitial:didFailToPresentScreenWithError: will be given. For a better user experience, keep listening to the interstitial states so that you can show ads to the user only when interstitial has been loaded completely.
    • After an interstitial ad has been dismissed, you will need to invoke the load method, again, before making a call to showFromViewController:

Testing the Integration

Set your property in test mode as described here.

Video Ads

InMobi video ads are designed to work on properties that have been set up to show interstitial ads. By default, video ads are enabled on all interstitial-integrated properties. However, if you want you property to display video ads exclusively, please change the ad controls of your interstitial placement and choose the option - Video Ads only.

Configuring a Video Ad

To configure a video ad, follow the same steps as for interstitial ads.

Rewarded Ads

Reward ads are full screen ads that provide a reward to the user upon the completion of a certain action. The reward is provided by the publisher after the user completes the action on the ad. The actions currently supported are Watching a Video.

Reward ads are great because of the following reasons:

  1. They are a strong retention hook for your users, keeping them engaged with your game/app for a longer time.
  2. They have a clear, opted-in user experience.
  3. They are an important source of monetization apart from in-app purchases and ads, and hence increase your overall revenues.

Integrating a Rewarded Ad

If you want to provide a reward to the user for watching a video, please see here for integration. Rewarded ads don’t require any additional integration steps. To be notified about the status of the reward ad, implement the interstitial:rewardActionCompletedWithRewards: method of IMInterstitialDelegate.

- (void)interstitial:(IMInterstitial *)interstitial rewardActionCompletedWithRewards:(NSDictionary *)rewards {
NSLog(@"IncentActionCompleted Publisher Callback successfully received");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"incentivisedAd - params" message:[NSString stringWithFormat:@"%@",rewards] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
[alert show];
}
		

This is called when the user has completed the action for which he should be rewarded. For example, if the incentive should be awarded when the user watches a video, the delegate will be called when the user has finished watching the video. The rewards are a set of parameters decided by the publisher, for this particular placement ID, to be sent when the user completes the required action to be rewarded.

Important:
Make video ad requests well before when the ad needs to be displayed. This is to cache the ad, providing a smooth and uninterrupted user experience. For example, if you want to show the rewarded video ad at the end of a level (in a gaming app), request for the ad when the level begins.

Creating a Native Ad

Native ads are ads that are rendered by the publisher, allowing publishers to give their users a unique experience. A native ad consists of ad assets in a publisher-specified format. Common assets include the image URL associated with the ad, icon URLs of the ad, if any, and texts like title, subtitle, and description.

For creating specific templates for your app layout, please see our help article.

Step 1: Creating a Native Ad Instance

Follow the below steps to implement a Native Content Ad:

To add a native ad to your application create an instance of IMNative and implement IMNativeDelegate.

To get native ads, perform the following steps:

  1. Import the IMNative.h and IMNativeDelegate.h files. Declare an instance of class IMNative in your UIViewController header file. Your header file should look like this:
    #import <UIKit/UIKit.h>
    #import "IMNativeDelegate.h"
    #import "IMNative.h"
    #import "IMRequestStatus.h"
    @interface ViewController : UIViewController <IMNativeDelegate>
    @property (nonatomic, strong) IMNative* nativeAd;
    @property (nonatomic, strong) NSString* nativeContent;
    @end
    			
  2. Create a native ad instance using the method:
    self.nativeAd = [[IMNative alloc] initWithPlacementId:<Insert native Placement ID Here>];
    			
  3. After creating an adview instance, set the delegate property of IMNative as your UIViewController before loading the ad. This is so that you will be notified about the ad receiving success or failure.
    self.nativeAd.delegate = self;
    			
  4. Use the following method to load native content ads:
    [self.nativeAd load];
    			

    Now, the viewcontroller class should look like this:

    - (void)viewDidLoad {
    [super viewDidLoad];
    self.nativeAd = [[IMNative alloc] initWithPlacementId:@"Insert native Placement ID Here"];
    self.nativeAd.delegate = self;
    [self.nativeAd load];
    }
    			
  5. Getting callbacks. To get ad status callbacks, Implement the IMNativeDelegate methods in your ViewController. IMNativeDelegate provides seven methods that require implementation. All methods will be called on the main thread.
    /*The native ad notifies its delegate that it is ready.Fetching publisher-specific ad asset content from native.adContent. The publisher will specify the format. If the publisher does not provide a format, no ad will be loaded.*/
    -(void)nativeDidFinishLoading:(IMNative*)native{
    NSLog(@"Native Ad loaded %@", native.adContent);
    }
    /*The native ad notifies its delegate that an error has been encountered while trying to load the ad.Check IMRequestStatus.h for all possible errors.Try loading the ad again, later.*/
    -(void)native:(IMNative*)native didFailToLoadWithError:(IMRequestStatus*)error{
    NSLog(@"Native Ad load Failed");
    }
    /* Indicates that the native ad is going to present a screen. */ -(void)nativeWillPresentScreen:(IMNative*)native{
    NSLog(@"Native Ad will present screen");
    }
    /* Indicates that the native ad has presented a screen. */
    -(void)nativeDidPresentScreen:(IMNative*)native{
    NSLog(@"Native Ad did present screen");
    }
    /* Indicates that the native ad is going to dismiss the presented screen. */
    -(void)nativeWillDismissScreen:(IMNative*)native{
    NSLog(@"Native Ad will dismiss screen");
    }
    /* Indicates that the native ad has dismissed the presented screen. */
    -(void)nativeDidDismissScreen:(IMNative*)native{
    NSLog(@"Native Ad did dismiss screen");
    }
    /* Indicates that the user will leave the app. */
    -(void)userWillLeaveApplicationFromNative:(IMNative*)native{
    NSLog(@"User leave");
    }
    			

    Please refer to IMNativeDelegate.h for a list of available callbacks.

  6. Rendering Native Ads and Impression Tracking. You have received a native ad when you receive the callback nativeAdDidFinishLoading, . The self.nativeAd.adContent object provides native ad content and it can be displayed in any new or existing UIView. The native ad content has a set of assets depending on the format you have chosen on the publisher UI.For example, for a news view flow, content will have assets as below:
    • Title - Title of the ad, String
    • Content - Description of the ad, String
    • Landing url - URL to be opened upon ad click
    • Icon - Icon details. That is, the url, height, width in JSON format

    These assets can be used in various components of your view, as shown below:

    if (self.adContent!=nil) {
    NSData* data = [self.adContent dataUsingEncoding:NSUTF8StringEncoding];
    NSError* error = nil;
    NSDictionary* jsonDict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    NSMutableDictionary* nativeJsonDict = [NSMutableDictionary dictionaryWithDictionary:jsonDict];
    /*The above lines of code convert the native JSON content to NSDictionary.*/
    if (error == nil && nativeJsonDict != nil) { // The native JSON is parsed and can be used.
    [nativeJsonDict setValue:[NSNumber numberWithBool:YES] forKey:@"isAd"]; // To differentiate the native JSON dictionary from other data.
    /* Examples of fetching the image and title are listed below*/
    /*Fetch the image url from the dictionary in the following way.*/
    NSDictionary* imageDict = [nativeJsonDict valueForKey:@"icon"];
    NSString* url = [imageDict valueForKey:@"url"];
    /*Fetch the tile from the dictionary*/
    NSString* title = [imageDict valueForKey:@"title"];
    }
    }
    			

    Create the required views using these values. For example if you are making a table view, and the ad is a cell in the table view then render the views in the tableview’s tableView:cellForRowAtIndexPath: method. An example is shown below:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString* cellIdentifier = @"someIdentifier";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell==nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
    }
    // If this is the row where the ad should be displayed,
    if([dict valueForKey:@"isAd"]) {
    UILabel* titleLabel = [[UILabel alloc] initWithFrame:<FRAME_FOR_YOUR_LABEL>];
    title.text = title; //This title is from the native JSON dictionary
    UIImage* image = [UIImage imageWithData:<DATA_FROM_THE_IMAGE_URL>];
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:<FRAME_FOR_YOUR_IMAGE>];
    imageView.image = image;
    //Add subviews to the cell
    [cell addSubView:titleLabel];
    [cell addSubView:imageView];
    //Bind the cell to the native ad as it has rendered the ad.
    [IMNative bindNative:self.nativeView toView:cell];
    }
    else { // This is a content item
    // UnBind the cell as it might be a reused cell from a native ad.
    [IMNative unBindView:cell];
    }
    			

    This is just an example on how to access native ad content and render it for a news flow. Content assets may vary for other flows, depending on the view you chose. Please look through your content structure first, and accordingly use the assets for your view flow.

    When the ad content is rendered, report this by calling the bindNative:(IMNative*)native toView:(UIView*) method on the IMNative class [IMNative bindNative:nativeAd toView:renderedUIViewInstance];

    Here, 'renderedUIViewInstance' is the view that is the rendered native ad. That is, for table view, if you are rendering native ad in one of the cells, you must pass the cell to this method once you render the ad. Call unBindView:(UIView*)view method IMNative class method when this cell is being reused by other content or other native ad instances.

    Both methods will fail if the ad is not yet loaded.

7. Tracking Clicks and The Landing Page

When the view that was rendered from the content of the ad gets clicked, report this click to the native ad instance by calling the reportAdClick:(NSDictionary*) params. This gives the publisher a convenient way to report gestures that are considered clicks. The params dictionary can contain any additional information that the publisher wants to provide to the native instance.

To report a click and handle opening of landing page on your own, call ; [nativeAd reportAdClick:paramsDictionary];

If the native ad content returns the publisher content with a landing page field, you must handle the landing page of the native ad after calling reportAdClick method.

The landing page will be present with the key 'landingURL' in the native ad content. Also, the landing page URL will be opened externally. These are default keys generated by the system. You can customize the key names (by logging into your InMobi account) as per your requirements.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary* dict = [self.items objectAtIndex:[indexPath row]];
url = [dict valueForKey:@"link"];
if ([dict valueForKey:@"isAd"]) {
NSString* landingUrl = [dict valueForKey:@"landingURL"];
[self.native reportAdClick:nil];
if (landingUrl != nil){
NSURL* landingPageURL = [NSURL URLWithString:landingUrl];
[[UIApplication sharedApplication] openURL:landingPageURL];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
To report a click and allow InMobi to open the landing page, call ;[nativeAd reportAdClickAndOpenLandingURL:paramsDictionary];
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary* dict = [self.items objectAtIndex:[indexPath row]];
if ([dict valueForKey:@"isAd"]) {
[self.native reportAdClickAndOpenLandingURL:nil];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
		

8. Tracking Custom Impressions and Clicks

To report a custom impression tracker or click use the IMCustomNative class.

#import “IMCust

To track impressions using custom impression tracker script use the following method. Pass the renderedUIViewInstance and a custom tracker script as parameters.
+(void)bindNative:toView:withImpressionTrackerScript:

To track impressions using custom impression tracker url use the following method. Pass the renderedUIViewInstance and a custom tracker url as parameters.
+(void)bindNative:toView:withImpressionTrackerURL:

Handle opening of landing page on your own as described in the section above

  • To report click using custom click tracker script use the following method. Pass the click parameters and a custom click tracking script as parameters.
    -(void)reportAdClick: withCustomClickTrackerScript:
  • To report click using custom click tracker url use the following method. Pass the click parameters and a custom click tracking URL as parameters.
    reportAdClick: withCustomClickTrackerURL:

If you do not want to handle opening of the landing page use the methods below. InMobi will open the landing page for you.

  • To report click using custom click tracker script use the following method. Pass the click parameters and a custom click tracking script as parameters.
    -(void)reportAdClickAndOpenLandingURL:(NSDictionary*)extras withCustomClickTrackerScript:
  • To report click using custom click tracker url use the following method. Pass the click parameters and a custom click tracking URL as parameters.
    -(void)reportAdClickAndOpenLandingURL:(NSDictionary*)extras withCustomClickTrackerURL:

The viewcontroller class should look like this:

- (void)viewDidLoad {
[super viewDidLoad];
self.nativeAd = [[IMCustomNative alloc] initWithPlacementId:@"Insert native Placement ID Here"];
self.nativeAd.delegate = self;
[self.nativeAd load];
}
//Track impressions using custom script
[IMCustomNative bindNative:self.nativeAd toView:UIRenderedView withImpressionTrackerScript:@"custom script here"];
//Track impressions using custom URL
[IMCustomNative bindNative:self.nativeAd toView:UIRenderedView withImpressionTrackerURL:"custom impression tracking URL here"]
//Track clicks using custom script. (Note: Landing page needs to be opened by you)
[self.nativeAd reportAdClick:"clicks params" withCustomClickTrackerScript
:"custom script here"];
//Track clicks using custom URL. (Note: Landing page needs to be opened by you)
[self.nativeAd reportAdClick:"clicks params" withCustomClickTrackerURL
:"custom click tracking URL here"];
//Track clicks using custom script and let InMobi open the Landing Page
[self.nativeAd reportAdClickAndOpenLandingURL:"clicks params" withCustomClickTrackerScript
:"custom script here"];
//Track impressions using custom URL and let InMobi open the Landing Page
[self.nativeAd reportAdClickAndOpenLandingURL:"clicks params" withCustomClickTrackerURL
:"custom impression tracking URL here"];
		

9. InMobi strongly recommends setting the delegate to nil in the dealloc method, or at any other time of native ad release.

-(void)dealloc {
nativeAd.delegate = nil;
}
		

Passing User Location

Passing the location object allows for better targeting, and potentially higher eCPMs.

Note: If the location object is passed, the app will ask the user for permission to access their location info.

Method 1 (Preferred): Using Geographic location:

Use //Using CoreLocation to fetch the coordinate.

#import “CoreLocation/CoreLocation.h”
CLLocationManager *mgr = [[CLLocationManager alloc] init];
CLLocation *loc = mgr.location;
[IMSdk setLocation:loc];
[locationMgr startUpdatingLocation];
		

Method 2: Using City State Country:

//when using custom values
[IMSdk setLocationWithCity:@"San Francisco" state:@"California" country:@"USA"];
		

Advanced Settings

Debugging the Integration

Turn on debugging by importing the IMSDK class and use it to set different log levels in the SDK: #import "IMSdk.h" The available values are:

  • IMLogLevelNone : InMobi SDK will not log anything on the console. We recommended that you set the log level to none once you’re distributing the app to the App Store.
  • IMLogLevelError : InMobi SDK will log only the error information, which can be used by the publisher for debugging.
  • IMLogLevelDebug : In this mode, InMobi SDK will log everything. Please use this log level strictly in case you experience any issues. Keeping the debug mode turned on might impact performance.

Example: Before you load the ad, set the log level to debug as follows:

[IMSdk setLogLevel:IMLogLevelTypeDebug];

Data Security

The InMobi SDK does not expose any data out of the scope of an application. Any SDK-related data that is persisted is done within the application scope only, without any access to other third-party applications.

Providing Demographics Data

All non-context specific parameters can be passed to InMobi for richer ad targeting. Please ensure that you pass on the values for the fields which you collect, and have user consent to share this data. Class "IMSDK" provides static methods to set demographic information about the user.

InMobi supports the following parameters:

Gender

Description

Gender of the user

  • Male
  • Female

Parameter Type

enum GenderType

API

setGender

Valid Values

  • kIMSDKGenderMale
  • kIMSDKGenderFemale

Examples

  • [IMSdk setGender:kIMSDKGenderMale];
  • [IMSdk setGender:kIMSDKGenderFemale];

Education

Description

The education level

  • High School Or Less
  • College or Graduate
  • Post Graduate or Above

Parameter Type

enum Education

API

setEducation

Valid Values

  • kIMSDKEducationHighSchoolOrLess
  • kIMSDKEducationCollegeOrGraduate
  • kIMEducationPostGraduateOrAbove

Examples

[IMSdk setEducation: kIMSDKEducationHighSchoolOrLess];

Ethnicity

Description

Ethnic group of the user

  • Hispanic
  • Caucasian
  • Asian
  • AfricanAmerican
  • Other

Parameter Type

enum Ethnicity

API

setEthnicity

Valid Values

  • kIMSDKEthnicityHispanic
  • kIMSDKEthnicityCaucasian
  • kIMEthnicityAsian
  • kIMEthnicityAfricanAmerican
  • kIMEthnicityOther

Examples

[IMSdk setEthnicity: kIMSDKEthnicityHispanic];

Date Of Birth

Description

The date of birth of the user

Parameter Type

Calendar

API

setYearOfBirth

Valid Values

NSInteger

Examples

  • // Ex date of Birth Jan 2, 2001
  • [IMSdk setYearOfBirth:2001];

Income

Description

Approximate annual household income (in US Dollars)

Parameter Type

int, to be specified in $

API

setIncome

Valid Values

  • integer
  • greater than zero

Examples

  • // Income in USD: $120,000
  • [IMSdk setIncome: 120000];

Age

Description

The age of the user

Parameter Type

int

API

setAge

Valid Values

  • integer,
  • greater than zero

Examples

[IMSdk setAge: 22];

Postal Code

Description

The postal code (Usually a 5 digit number).

Parameter Type

string

API

setPostalCode

Valid Values

@"12345" - Please enter appropriate postal code, as applicable.

Examples

[IMSdk setPostalCode:@"12345"];

Area Code

Description

The area code (part of the telephone number).

Parameter Type

string

API

setAreaCode

Valid Values

@"123" - Please enter appropriate area code, as applicable.

Examples

[IMSdk setPostalCode:@"123"];

Interests

Description

Any additional relevant description of the user, or their preferences, separated by commas. Valid acceptable values are mentioned below.

Parameter Type

String

API

setInterests

Valid Values

  • Business
  • Tech
  • Travel
  • Shopping
  • Entertainment
  • Fashion
  • Fitness
  • Foodie
  • Gamer
  • Jobs
  • Sports

Examples

[IMSdk setInterests: @"Foodie,Gamer,Sports"];

ID Type

Description

Indicates a login ID and session ID in the publisher's domain

  • Login ID
  • Session ID

Parameter Type

enum IMIdType , String value

API

addIDType or removeIDType

Valid Values

  • kIMSDKIdTypeLogin
  • kIMSDKIdTypeSession

Examples

  • [IMSdk addId:@"John.doe@facebook.com" forType:kIMSDKIdTypeLogin]
  • [IMSdk addId:@"John.doe@facebook.com" forType:kIMSDKIdTypeSession]
  • [IMSdk removeIdType:kIMSDKIdTypeSession]

Language

Description

The native language of the user (if known)

Parameter Type

String

API

setLanguage

Valid Values

@"ang" - Values are expected in 3 letter codes from ISO 639-2/5. See here for details.

Examples

[IMSdk setLanguage:@"ang"];

Household Income

Description

The house hold income of user in US Dollars

Parameter Type

enum HouseHoldIncome

API

setHouseholdIncome

Valid Values

  • kIMSDKHouseholdIncomeBelow5kUSD
  • kIMSDKHouseholdIncomeBetweek5kAnd10kUSD
  • kIMSDKHouseholdIncomeBetween10kAnd15kUSD
  • kIMSDKHouseholdIncomeBetween15kAnd20kUSD
  • kIMSDKHouseholdIncomeBetween20kAnd25kUSD
  • kIMSDKHouseholdIncomeBetween25kAnd50kUSD
  • kIMSDKHouseholdIncomeBetween50kAnd75kUSD
  • kIMSDKHouseholdIncomeBetween75kAnd100kUSD
  • kIMSDKHouseholdIncomeBetween100kAnd150kUSD
  • kIMSDKHouseholdIncomeAbove150kUSD

Examples

[IMSdk setHouseholdIncome:kIMSDKHouseholdIncomeBelow5kUSD];

Age Group

Description

The age group of the user

Parameter Type

enum AgeGroup

API

setAgeGroup

Valid Values

  • kIMSDKAgeGroupBelow18
  • kIMSDKAgeGroupBetween18And20
  • kIMSDKAgeGroupBetween21And24
  • kIMSDKAgeGroupBetween25And34
  • kIMSDKAgeGroupBetween35And54
  • kIMSDKAgeGroupAbove55

Examples

[IMSdk setAgeGroup:kIMSDKAgeGroupBelow18];

Nationality

Description

The nationality of the user

Parameter Type

String

API

setNationality

Valid Values

Nationality according to the list here.

Examples

[IMSdk setNationality:@”Indian”];

Note: Please refer to the SDK bundle to view the change logs for this document.