I’m trying to implement banner ads from Google.MobileAds/Firebase. I’m following this guide: https://components.xamarin.com/gettingstarted/firebaseiosadmob I was able to configure my app and enable firebase analytics but when I try to implement public void AddBanner() into the monogame project I get errors:
Error CS0246: The type or namespace name ‘CGPoint’ could not be found (are you missing a using directive or an assembly reference?) (CS0246) (word_game.iOS)
Error CS0029: Cannot implicitly convert type ‘word_game.Program’ to ‘UIKit.UIViewController’ (CS0029) (word_game.iOS)
Error CS0103: The name ‘View’ does not exist in the current context (CS0103) (word_game.iOS)
Here’s my code:
using Google.MobileAds;
namespace word_game
{
public class Game1 : Game
{
const string bannerId = "ca-app-pub-3940256099942544/6300978111";
BannerView adView;
bool viewOnScreen = false;
public void AddBanner()
{
// Setup your BannerView, review AdSizeCons class for more Ad sizes.
adView = new BannerView(size: AdSizeCons.Banner, origin: new CGPoint(0, 0))
{
AdUnitID = bannerId,
RootViewController = this
};
// Wire AdReceived event to know when the Ad is ready to be displayed
adView.AdReceived += (object sender, EventArgs e) => {
if (!viewOnScreen)
{
View.AddSubview(adView);
viewOnScreen = true;
}
};
var request = Request.GetDefaultRequest();
// Requests test ads on devices you specify. Your test device ID is printed to the console when
// an ad request is made. GADBannerView automatically returns test ads when running on a
// simulator. After you get your device ID, add it here
request.TestDevices = new[] { Request.SimulatorId.ToString() };
// Request an ad
adView.LoadRequest(request);
}
public Game1()
{
graphics = new GraphicsDeviceManager(this);
graphics.IsFullScreen = false;
}
protected override void Initialize()
{
base.Initialize();
screenWidth = GraphicsDevice.Viewport.Width;
screenHeight = GraphicsDevice.Viewport.Height;
tileSize = ((screenWidth - 200) / width);
Console.WriteLine(screenWidth + " " + screenHeight);
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
graphics.GraphicsDevice.Clear(Color.Green);
}
}
}