Banner Integration for Xamarin iOS

Before You Start

Make sure you have correctly integrated the ironSource Plugin into your application. Integration is outlined here.

Step 1. Create Banner Layout 

First, you’ll need to create a Banner view to configure the Banner.

  • Initiate the Banner view by calling this method (in this example it’s the BANNER banner size):
    var instance = new ISBannerSize("BANNER");
          UIViewController bannerViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
    IronSource.LoadBannerWithViewController(bannerViewController, instance);
    

    See table below for details about our supported standard banner sizes:

    ISBannerSize Description Dimensions in points (WxH)
    BANNER Standard Banner 320 x 50
    LARGE Large Banner 320 x 90
    RECTANGLE Medium Rectangular Banner 300 x 250
    SMART
    Smart Banner
    (Adjusted for both iPhone and iPad)
    If (iPhone ≤ 720) 320 x 50
    If (iPad > 720) 728 x 90

Create and load a banner ad:

Here’s an example that initiates and loads a banner in the onCreate() method of an Activity:

	
    public override void ViewDidLoad() {
        base.ViewDidLoad();
 
        // YOUR OTHER CODE //
        // YOUR OTHER CODE //
        // YOUR OTHER CODE //
        IronSource.InitWithAppKey("YOUR_APP_KEY");
        BannerWrapper bnDelegate = new BannerWrapper(this);
        IronSource.SetBannerDelegate((ISBannerDelegate)bnDelegate);
    }
 
        public class BannerWrapper : ISBannerDelegate
    {
       readonly UIViewController parent;
       public BannerWrapper(UIViewController parent)
       {
            this.parent = parent;
       }
       public override void BannerAdLoaded()
       {
            InvokeOnMainThread(() =>
           {
               bannerView = bnView;
               nfloat y = this.parent.View.Frame.Size.Height - (bannerView.Frame.Size.Height / 2);
               if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
               {
                   y -= this.parent.View.SafeAreaInsets.Bottom;
               }
               bannerView.Center = new CGPoint(this.parent.View.Frame.Size.Width / 2, y);
               this.parent.View.AddSubview(bannerView);
           });
       }
       public override void BannerAdLoadFailed(IronSourceError error)
       {
       }
       public override void BannerAdClicked()
       {
       }
   
       public override void BannerAdScreenPresented()
       {
       }
       public override void RewardedVideoDidStart()
       {
       }
       public override void BannerAdScreenDismissed()
       {
       }
       public override void BannerAdLeftApplication()
       {
       }
   }

 

Step 2. Implement the Delegate

Next, the ironSource SDK fires several delegate methods to inform you of Banner activity. The SDK will notify your delegate methods of all possible events listed below:

public class BNDelegate : ISBannerDelegate
 {
           /*
            * Called after a banner ad has been successfully loaded
           */
            public void OnBannerAdLoaded() {
                InvokeOnMainThread(() =>
           {
               bannerView = bnView;
               nfloat y = this.parent.View.Frame.Size.Height - (bannerView.Frame.Size.Height / 2);
               if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
               {
                   y -= this.parent.View.SafeAreaInsets.Bottom;
               }
               bannerView.Center = new CGPoint(this.parent.View.Frame.Size.Width / 2, y);
               this.parent.View.AddSubview(bannerView);
           });
            }
           /*
           * Called after a banner has attempted to load an ad but failed.
           * @param error The reason for the error
           */
            public void OnBannerAdLoadFailed(IronSourceError error) {
               
            }
            /*
            * Called after a banner has been clicked.
            */
            public void OnBannerAdClicked() {
                
            }
            /*
            * Called when a banner is about to present a full screen content.
            */
            public void OnBannerAdScreenPresented() {
                
            }
            /*
            * Called after a full screen content has been dismissed.
            */
            public void OnBannerAdScreenDismissed() {
                
            }
           /*
            * Called when a user would be taken out of the application context.
            */
            public void OnBannerAdLeftApplication() {
                
            }
        }
 Note: Do not assume the delegate methods are invoked on the main thread.

Step 3. Load Banner Ad Settings

To load a Banner ad with the default settings, call the following method:

var instance = new ISBannerSize("BANNER");
      UIViewController bannerViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
IronSource.LoadBannerWithViewController(bannerViewController, instance);

 Note: SDK will not show more than one banner at a time.

Step 4. Destroy the Banner Ad

To destroy a banner, call the following method:

InvokeOnMainThread(() =>
            {
                if (this.bnDelegate.DestroyBanner())
                {
                    bannerViewController = null;
                }
            });

A destroyed banner can no longer be loaded. If you want to serve it again, you must initiate it again.

Step 5.  Integrate a Banner Provider

Next, integrate the ad network adapters to serve Banners through ironSource Mediation. We currently support ironSource, Admob, AppLovin and Facebook Banners.

For better understanding of bannerSize’s behaviour per network, please follow table:

BANNER LARGE RECTANGLE SMART
ironSource Banner Large Banner / Leaderboard
AdMob Banner Large Banner IAM Medium Rectangle Banner / Leaderboard
AppLovin Banner Banner Medium Rectangle Banner / Leader
Facebook Standard Banner Large Banner Medium Rectangle Banner / Leader

Done!
You are now all set up to serve Banners in your application. Verify your integration with our Integration Helper.