跳到主要内容

集成指南

简介

      在接入广告之前,首先需要完成SDK的初始化。

      MG Ads 支持【开屏1920*1080】【退屏】【横幅728*90】【插屏1024*768】【对联300*600】【激励视频1024*768】【信息流】【嵌入式】

开屏广告

开屏广告位一般在页面的load方法中,在SDK初始化完成事件中实现。


Platform::String^ MainPage::SpreadnAd()//MG FullScreenAd
{
try
{
//“XXXXXXXX”参数需要传入广告key,广告key 来自MG广告后台创建。
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd("XXXXXXXX", MiracleGamesAd::Models::AdType::FullScreen));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
if (result->ReturnValue)//关闭广告时触发广告关闭事件
{

}
});
}
catch (...){}//添加异常处理机制,预防游戏崩溃.
return "";
}

退屏广告

      退屏广告是在退出游戏时触发,为了保证退出游戏时广告的弹出率,MG建议在初始化完成后首先将退屏广告的信息加载到内存中,在退出游戏时,SDK会自动直接打开退屏广告


//“XXXXXXXX”参数需要传入广告key,广告key来自MG广告后台创建。
try
{
MiracleGamesAd::AdvertisingManager::ShowExitAdBlocking(“XXXXXXXX”);
}
catch (...){}//添加异常处理机制,预防游戏崩溃.

接入退屏广告代码之后,还需要进行以下设置。

1.首先将主工程的Properties->Application页签中Target version改为19041(或者高于此版本)

2.右键Package.appxmanifest,选择Xml编辑器打开编辑

3.在Package标签中增加xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities",并在IgnorableNamespaces中补充rescap

4.在Capabilities节点下,增加这一行配置代码 <rescap:Capability Name="confirmAppClose"/>

5.保存即可

横幅广告


Platform::String ^MainPage::MainScreen_Binner()
{
try
{
auto opt = ref new MiracleGamesAd::Models::BannerAdSettingOptions();//设置广告的一些配置参数,未设置时使用默认状态
opt->MediaType = "image";//设置广告类型图片="image",网页="web"
//控制展示广告的位置
opt->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Center;
opt->VerticalAlignment = Windows::UI::Xaml::VerticalAlignment::Bottom;
//“XXXXXXXX”参数需要传入广告key,广告key 来自MG后台创建。
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd(“XXXXXXXX”, MiracleGamesAd::Models::AdType::Banner, opt));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
if (result->ReturnValue)//关闭广告时触发广告关闭事件
{

}
});
}
catch (...){}//添加异常处理机制,预防游戏崩溃.
return "";
}

插屏广告


Platform::String^ MainPage::MainScreen_TableAD()
{
try
{
auto opt = ref new MiracleGamesAd::Models::InterstitialAdSettingOptions();//设置广告的一些配置参数,未设置时使用默认状态
opt->MediaType = "image";//设置广告类型图片="image",网页="web",视频="video"
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd(“XXXXXXXX”, MiracleGamesAd::Models::AdType::Interstitial, opt));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
if (result->ReturnValue)//关闭广告时触发广告关闭事件
{

}
});
}
catch (...){}//添加异常处理机制,预防游戏崩溃.
return "";
}

对联广告


Platform::String ^ ::MainPage::MainScreen_Couplet()
{
try
{
auto opt = ref new MiracleGamesAd::Models::CoupletAdSettingOptions();//设置广告的一些配置参数,未设置时使用默认状态
opt->MediaType = "image";//设置广告类型图片="image",网页="web"
//“XXXXXXXX”参数需要传入广告key,广告key 来自MG后台创建。
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd(“XXXXXXXX”, MiracleGamesAd::Models::AdType::Couplet, opt));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
if (result->ReturnValue)//关闭广告时触发广告关闭事件
{

}
});
}
catch (...){}//添加异常处理机制,预防游戏崩溃.
return "";
}

激励视频

void ShowAdReword() {
auto opt = ref new MiracleGamesAd::Models::RewardAdSettingOptions();
opt->MediaType = "image";//设置广告类型图片="image",网页="web",视频="video"
opt->Comment = "{\"coin\":100}";//开发者自定义参数
//“XXXXXXXX”参数需要传入广告key,广告key 来自MG后台创建。
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd("XXXXXXXX", MiracleGamesAd::Models::AdType::Reward, opt));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
auto completeState = dynamic_cast<MiracleGamesAd::Models::RewardAdCompleteState^>(result->Tag);
if (completeState != nullptr)
{
if (completeState->IsCompleted)
{
auto comment = completeState->Comment;//开发者自定义参数
MiracleGamesAd::AdvertisingManager::ReportAdRewardFulfillment(completeState->RewardId);
}
}
});
}