So I tried implementing AdMob to my project but my ad is not showing up and I have no idea why. I was following a guide online which I can't seem to find at this point but when they did it, it worked just fine, and I followed all the steps, I am starting to consider that it might be Xamarin but I am not sure.
I have a AdMobRenderer.cs that looks like this
using Google.MobileAds;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
namespace AdMobTestProject.iOS
{
public class AdMobRenderer : ViewRenderer
{
//hiding the key for this question
private const string adMobId = "ca-app-pub-xxxxxx/xxxxxxx";
private BannerView adView;
private bool viewOnScreen;
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
if (e.NewElement == null)
return;
if (e.OldElement == null)
{
adView = new BannerView(AdSizeCons.SmartBannerPortrait)
{
AdUnitID = adMobId,
RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController
};
adView.AdReceived += (sender, args) =>
{
if (!viewOnScreen)
{
this.AddSubview(adView);
}
viewOnScreen = true;
};
Request request = Request.GetDefaultRequest();
adView.LoadRequest(request);
base.SetNativeControl(adView);
}
}
public AdMobRenderer()
{
}
}
}
And then the XAML aswell
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AdMobTestProject"
x:Class="AdMobTestProject.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<local:AdMobView WidthRequest="320" HeightRequest="50"></local:AdMobView>
</StackLayout>
</ContentPage>
And ofcourse the MainPage.xaml.cs
namespace AdMobTestProject
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
public class AdMobView : ContentView
{
public AdMobView()
{
}
}
}
Am I missing something? Why is it not displaying anything when I deploy the app to my device? iPhone 7. I am using Xamarin.Forms