iOS

In order to start setting up, you’ve to ensure that the steps mentioned in the (available InMobi Integration) have already been incorporated.

Initialise the SDK

Step1: Initialise the SDK, after the completion of Initialisation process, completion handler will be called.

void (^completionBlock)(NSError*) = ^( NSError* _Nullable error) {
    if (error) {
        NSLog(@"SDK Initialization Error - %@", error.description);
    }
    else {
        NSLog(@"IM Media SDK successfully initialized");
    }
};
[IMSdk initWithAccountID:kIMAccountID consentDictionary:@{IM_GDPR_CONSENT_AVAILABLE: @"true"} andCompletionHandler:completionBlock];

Note

Kindly refer to the integration document for details about creating the gdpr consent dictionary.

Once you have added the SDK for iOS successfully, please follow the steps below to load the following ad units using Audience Bidding.

  1. Banner Ads
  2. Interstital Ads 

Banner Ads

Step 1: Setting up a Banner Ad and add it to your app.

Create an Instance of IMBanner.

IMBanner* bannerAd = [[IMBanner alloc] initWithFrame:frame placementId:<placementid>]; 

 

Notes

  • A banner instance must be created on the main thread.
  • Similarly, all methods on this instance must be called on the main thread. Not doing so will lead to unpredictable behaviour and may affect your ability to monetize with InMobi.
  • Creating an IMBanner object before SDK initialization results in a nil being returned.
Set delegate of IMBanner

To set the delegate of the IMBanner, call:

bannerAd.delegate = self;

Step 2: Requesting for Bid

Requesting a bid requires IMBanner Instance,. After setting delegate of IMBanner, call preload on IMBannerPreloadManager. IMBanner has an instance of IMBannerPreloadManager as its property.

For requesting bid, call following line.

[bannerAd.preloadManager preload];

Implement the following IMBannerDelegates:

/**
* Notifies the delegate that the banner has recieved the ad with the meta/transaction info.
*/ 
-(void)banner:(IMBanner*)banner didReceiveWithMetaInfo:(IMAdMetaInfo*)info {
   NSLog(@”bid fetched:%@”, info.getBid());
}
/**
* Notifies the delegate that the banner has failed to preload with some error.
* It will only be recieved when preload is called.
*/
-(void)banner:(IMBanner*)banner didFailToReceiveWithError:(IMRequestStatus*)error {
NSLog(@”bid failed to be fetched”);
}

Note

Please do not destroy this instance of IMBanner, as this will be needed if InMobi wins the auction.

Step 3: Loading the Banner Ad

In case InMobi has won the auction, then you can call the load method on the preloadManager property on the IMBanner instance to load the ad.

For loading the banner ad, call following line.

[bannerAd.preloadManager load];

Implement the following IMBannerDelegates:

/**
* Notifies the delegate that the banner has finished loading
*/
-(void)bannerDidFinishLoading:(IMBanner*)banner {
    NSLog(@”Banner ad did finish loading”);
}
**
* Notifies the delegate that the banner has failed to load with some error.
*/
-(void)banner:(IMBanner*)banner didFailToLoadWithError:(IMRequestStatus*)error {
    NSLog(@”banner ad failed to load”);
}

Interstitial Ads

Step 1: Setting up an Interstitial Ad and add it to your app.

Create an Instance of IMInterstitial.

IMInterstitial* interstitialAd = [[IMInterstitial alloc] initWithPlacementId:<placementid> delegate:<delegate>];

Notes

  • An Interstitial instance must be created on the main thread.
  • Similarly, all methods on this instance must be called on the main thread. Not doing so will lead to unpredictable behaviour and may affect your ability to monetize with InMobi.
  • Creating an IMInterstitial object before SDK initialization results in a nil being returned.

Step 2: Requesting for Bid

Requesting a bid requires IMInterstitial Instance,. Invoke the preload method on IMInterstitialPreloadManager. IMInterstitial has an instance of IMInterstitialPreloadManager as its property.

For requesting bid, call following line.

[interstitialAd.preloadManager preload];

Implement the following IMInterstitialDelegate:

/**
* Notifies the delegate that the ad server has returned an ad. Assets are not yet available.
* Please use interstitialDidFinishLoading: to receive a callback when assets are also available.
*/
-(void)interstitial:(IMInterstitial*)interstitial didReceiveWithMetaInfo:(IMAdMetaInfo*)metaInfo {
    NSLog(@”bid fetched:%@”, info.getBid());
}
/**
* Notifies the delegate that the interstitial has failed to recieve an Ad(failed to preload an ad) with some error.
* This callback will only be recieved when Preload is called.
*/
-(void)interstitial:(IMInterstitial*)interstitial didFailToReceiveWithError:(NSError*)error {
    NSLog(@”bid failed to be fetched”);
}

Note

Please do not destroy this instance of IMInterstitial, as this will be needed if InMobi wins the auction

Step 3: Loading the Interstitial Ad

In case InMobi has won the auction, then you can call the load method on the preloadManager property of the IMInterstitial instance to load the ad.

For loading the interstitial ad, call following line.

[interstitialAd.preloadManager load];

Implement the following IMInterstitialDelegate:

/**
* Notifies the delegate that the interstitial has finished loading and can be shown instantly.
*/
-(void)interstitialDidFinishLoading:(IMInterstitial*)interstitial {
    NSLog(@”Interstitial ad did finish loading”);
}
/**
* Notifies the delegate that the interstitial has failed to load with some error.
*/
-(void)interstitial:(IMInterstitial*)interstitial didFailToLoadWithError:(IMRequestStatus *)error {
    NSLog(@”Interstitial ad failed to load”);
}

Step 4: Show the Interstitial Ad

As Interstitial ad is already loaded, to show the interstitial ad call the following:

[interstitialAd showFromViewController:<viewcontroller>];

Implement the following IMInterstitialDelegate:

/**
* Notifies the delegate that the interstitial would be presented.
*/
-(void)interstitialWillPresent:(IMInterstitial*)interstitial {
    NSLog(@”interstitialWillPresent”);
} 
/**
* Notifies the delegate that the interstitial has been presented.
*/
-(void)interstitialDidPresent:(IMInterstitial*)interstitial {
    NSLog(@” interstitialDidPresent”);
}
/**
* Notifies the delegate that the interstitial has failed to present with some error.
*/
-(void)interstitial:(IMInterstitial*)interstitial didFailToPresentWithError:(IMRequestStatus*)error {
    NSLog(@” interstitial didFailToPresentWithError”);
}
 

このページは役に立ちましたか?

このページ

最終更新日: 17 Jan, 2022