SDK Initialization

Introduction

Before accessing Miracle Games SDK, need to initialize SDK first. After the initialization, you can use all functions of SDK with background system. In general, SDK initialization is performed after entering game.

The MGSDK requires network permissions to request the MG server. The MG server domain is https://api.mguwp.net.

CMP

If the app integrates the advertising module, the CMP interface must be called first upon app launch, followed immediately by the SDK initialization interface.

SDK Initialization

Open App.xaml.cs file and add the following method code to the class.

UWPCPP

Public Mainpage()
{
	try
	{
		This.InitializeComponent();
		Load + =(sender,args)=>
		{      
			 //The "YOUR_APP_KEY" parameter needs to be applied for and created in the MG backend.
			 ApplicationManager.OpenCmpAsync("YOUR_APP_KEY");//If the app integrates the advertising module of MGSDK, the CMP interface must be called first upon app launch.
			 
			 var result = await MiracleGames.ApplicationManager.SetupAsync("YOUR_APP_KEY");//Initialization Interface Call
			 if (!result.ReturnValue)//Call the initialization callback interface to check whether initialization is complete. Only after initialization is completed can other functions of MGSDK be called.
				 return;
		};
	}
	catch (Exception){}//Implement exception handling to prevent game crashes.
}

MainPage :: MainPage()
{
	InitializeComponent();    
	try
	{
		Loaded += ref new RoutedEventHandler([this](Object^, RoutedEventArgs^)
		{
			 //The "YOUR_APP_KEY" parameter needs to be applied for and created in the MG backend.
			 ApplicationManager.OpenCmpAsync("YOUR_APP_KEY");//If the app integrates the advertising module of MGSDK, the CMP interface must be called first upon app launch.
			 
			concurrency::create_task(MiracleGames::ApplicationManager::SetupAsync(L"YOUR_APP_KEY")).then([this](MiracleGames::Services::Core::Common::AsyncProcessResult^ result)//Initialization Interface Call
			{
				if (!result->ReturnValue)
					return;               
			  
			});
		});
	}
	catch (...){}//Implement exception handling to prevent game crashes.
}

Or declare the initialization method in the mainPage () method in MainPage.xaml.cpp


if (!MiracleGames::ApplicationManager::SetupCompletedSuccessfully)
{    
	try
	{
		//The "YOUR_APP_KEY" parameter needs to be applied for and created in the MG backend.
		ApplicationManager.OpenCmpAsync("YOUR_APP_KEY");//If the app integrates the advertising module of MGSDK, the CMP interface must be called first upon app launch.
		
		auto initTask = Concurrency::create_task(MiracleGames::ApplicationManager::SetupAsync("YOUR_APP_KEY"));
		initTask.then([](MiracleGames::Services::Core::Common::AsyncProcessResult^ result)
		{	
		if (!result->ReturnValue)
			  return;             
		});
	}
	catch (...){}//Implement exception handling to prevent game crashes.
}

	

MG Message push

In the old version the message push had to be pushed manually, but in the new version it has been automatically merged so no calls are needed.

Errors that initialize failed may be as follows

Video Demonstration - Initialization