I created a new MonoGame iOS solution in Xamarin Studio. After that, I added to following code to Game1.cs:
bool IsiOS = false;
if (Device.RuntimePlatform == Device.iOS)
IsiOS = true;
But I get an error message when I build the project.
if (Device.RuntimePlatform == Device.iOS)
System.InvalidOperationException You MUST call Xamarin.Forms.Init(); prior to using it.
What is wrong with my code? I don't know what I should add or change.
code(Game1.cs):
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Xamarin.Forms;
namespace NewTest.iOS
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
bool IsiOS = false;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.IsFullScreen = true;
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
if (Device.RuntimePlatform == Device.iOS)
IsiOS = true;
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.CornflowerBlue);
base.Draw(gameTime);
}
}
}
code(Program.cs):
using System;
using Foundation;
using UIKit;
namespace NewTest.iOS
{
[Register("AppDelegate")]
class Program : UIApplicationDelegate
{
private static Game1 game;
internal static void RunGame()
{
game = new Game1();
game.Run();
}
static void Main(string[] args)
{
UIApplication.Main(args, null, "AppDelegate");
}
public override void FinishedLaunching(UIApplication app)
{
RunGame();
}
}
}
The Device
class is part of Xamarin Forms. If you are using Xamarin Forms, then you must initialize it first. That is exactly what the error message is telling you.