Adding admob to Monogame in Xamarin Studio (on Mac)

Hello,

I’m not sure if I am missing anything, but I have searched all over the web, and been trying for a couple days to solve adding Admob to my monogame project. I’m using the component ‘Google Mobile Ads for iOS’. I’ve tried adding the AppDelegate.cs file to my project, but the ad doesn’t show up even though the project runs on iOS.

Here is the AppDelegate.cs file I have…

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Foundation;
using UIKit;
using CoreGraphics;

using Google.MobileAds;

namespace MyProject.iOS
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register (“AppDelegate”)]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
UINavigationController navController;

    BannerView adViewTableView;
    BannerView adViewWindow;
    Interstitial adInterstitial;
    bool adOnWindow = false;
    bool interstitialRequested = false;
    // Get you own AdmobId from: http://www.google.com/ads/admob/
    // These IDs are provided by Google
    const string bannerId = "ca-app-pub-3940256099942544/2934735716";
    const string intersitialId = "ca-app-pub-3940256099942544/4411468910";
    //
    // This method is invoked when the application has loaded and is ready to run. In this
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //
    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        window = new UIWindow (UIScreen.MainScreen.Bounds);
        window.RootViewController = navController;
        window.MakeKeyAndVisible ();
        AddToWindow();
        return true;
    }
    void AddToWindow ()
    {
        if (adViewWindow == null) {
            // Setup your GADBannerView, review AdSizeCons class for more Ad sizes. 
            adViewWindow = new BannerView (size: AdSizeCons.Banner, 
                origin: new CGPoint (0, window.Bounds.Size.Height - AdSizeCons.Banner.Size.Height)) {
                AdUnitID = bannerId,
                RootViewController = navController
            };
            // Wire AdReceived event to know when the Ad is ready to be displayed
            adViewWindow.AdReceived += (object sender, EventArgs e) => {
                if (!adOnWindow) {
                    navController.View.Subviews.First ().Frame = new CGRect (0, 0, 320, UIScreen.MainScreen.Bounds.Height - 50);
                    navController.View.AddSubview (adViewWindow);
                    adOnWindow = true;
                }
            };
        }
        adViewWindow.LoadRequest (Request.GetDefaultRequest ());
    }
    void RemoveAdFromWindow ()
    {
        if (adViewWindow != null) {
            if (adOnWindow) {
                navController.View.Subviews.First ().Frame = new CGRect (0, 0, 320, UIScreen.MainScreen.Bounds.Height);
                adViewWindow.RemoveFromSuperview ();
            }
            adOnWindow = false;
            // You need to explicitly Dispose BannerView when you dont need it anymore
            // to avoid crashes if pending request are in progress
            adViewWindow.Dispose ();
            adViewWindow = null;
        }
    }
    void AddToView ()
    {
        if (interstitialRequested)
            return;
        if (adInterstitial == null) {
            adInterstitial = new Interstitial (intersitialId);
            adInterstitial.ScreenDismissed += (sender, e) => { 
                interstitialRequested = false;
                // You need to explicitly Dispose Interstitial when you dont need it anymore
                // to avoid crashes if pending request are in progress
                adInterstitial.Dispose ();
                adInterstitial = null;
            };
        }
        interstitialRequested = true;
        adInterstitial.LoadRequest (Request.GetDefaultRequest ());
        ShowInterstitial ();
    }
    async void ShowInterstitial ()
    {
        // We need to wait until the Intersitial is ready to show
        do {
            await Task.Delay (100);
        } while (!adInterstitial.IsReady);
        // Once is ready, show it
        InvokeOnMainThread (() => adInterstitial.PresentFromRootViewController (navController));
    }
}

}