Putting iAds in a MonoGame game

An iAd shown in my game

Here is the code you need to add to Main.cs in you game to get iAds working. You don't need to add any unique IDs. The iAd SDK is able to work out what you app is by magic. Everything will work fine as long as your app is registered for iAds in iTunes Connect.

I call the method SetupAdvert at the end of FinishedLaunching in Main.cs:

private object _adBannerView;
private bool _advertPausedGame;

private void SetupAdvert()
    int width, height;
    var view = (game.Services.GetService(typeof(UIViewController)) as UIViewController).View;

    if (view.Bounds.Width <= 320)
        width = 320;
        height = 50;
        width = 768;
        height = 66;

    var adSize = new NSString ("ADBannerContentSizePortrait");
    var advertX = view.Bounds.Height - height;

    _adBannerView = new ADBannerView();
    ADBannerView adBannerView = _adBannerView as ADBannerView;
    NSMutableSet nsM = new NSMutableSet();
    adBannerView.RequiredContentSizeIdentifiers = nsM;
    adBannerView.CurrentContentSizeIdentifier = adSize;

    adBannerView.AdLoaded += new EventHandler(AdvertLoaded);
    adBannerView.FailedToReceiveAd += new EventHandler

This code only deals with a portrait game. If you have any suggestions about how to improve it, then let me know in the comments.