在共享的 WinRT 8.1 页面上显示广告
Displaying ads on shared WinRT 8.1 page
我的通用应用程序(不是新的 UWP10)几乎所有页面都在桌面和 Phone 项目之间共享。这些页面是 .Shared
项目的一部分;与特定于平台的项目相同的命名空间。
现在,向页面添加 AdControl
控件并不困难,但我不确定如何处理控件的平台特定方面,例如 AdId
, Height
或 Width
。由于 DevCenter 中的广告分为两类(平板电脑和 PC/Mobile),我不知道应该输入什么作为 ID 参数。我也不确定我应该如何处理特定平台上的 Width/Height 调整。
最好的解决方案是什么?
As the ads in DevCenter are split into two categories (Tablet &
PC/Mobile) I don't know what I should enter as the ID parameter.***
在仪表盘中,您可以创建两类广告,一类用于PC/Tablet。另一类用于移动,然后分别替换您的 VS 项目中的单元 ID 和应用程序 ID。
I'm also not sure how I should handle Width/Height adjustment on specific platforms.***
首先请用EasClientDeviceInformation class判断是phone还是PC平台,之后可以在cs代码中编程添加Adcontrol,具体平台如下:
var clientDeviceInformation = new EasClientDeviceInformation();
var operatingSystem = clientDeviceInformation.OperatingSystem;
if (operatingSystem.Equals("WINDOWS"))
{
//add Adcontrol for Windows
// Programatically create an ad control. This must be done from the UI thread.
var adControl = new AdControl();
// Set the application id and ad unit id
// The application id and ad unit id can be obtained from Dev Center.
adControl.ApplicationId = "66ad92bf-3c62-4fa8-ad1c-421a56bf0231";
adControl.AdUnitId = "309519";
// Set the dimensions(windows)
adControl.Width = 160;
adControl.Height = 600;
// Add event handlers if you want
adControl.ErrorOccurred += OnErrorOccurred;
adControl.AdRefreshed += OnAdRefreshed;
}
else
{
//add Adcontrol for Windows phone
var adControl = new AdControl();
// Set the application id and ad unit id
// The application id and ad unit id can be obtained from Dev Center.
// See "Monetize with Ads" at https://msdn.microsoft.com/en-us/library/windows/apps/mt170658.aspx
adControl.ApplicationId = "90b6905b-da20-42fc-bb86-c2b41140fe4e";
adControl.AdUnitId = "311213";
// Set the dimensions(windows)
adControl.Width = 300;
adControl.Height = 50;
// Add event handlers if you want
adControl.ErrorOccurred += OnErrorOccurred;
adControl.AdRefreshed += OnAdRefreshed;
}
更多信息请参考官方示例Scenario2:
此外你需要确保这里的宽度和高度是supported size
我的通用应用程序(不是新的 UWP10)几乎所有页面都在桌面和 Phone 项目之间共享。这些页面是 .Shared
项目的一部分;与特定于平台的项目相同的命名空间。
现在,向页面添加 AdControl
控件并不困难,但我不确定如何处理控件的平台特定方面,例如 AdId
, Height
或 Width
。由于 DevCenter 中的广告分为两类(平板电脑和 PC/Mobile),我不知道应该输入什么作为 ID 参数。我也不确定我应该如何处理特定平台上的 Width/Height 调整。
最好的解决方案是什么?
As the ads in DevCenter are split into two categories (Tablet & PC/Mobile) I don't know what I should enter as the ID parameter.***
在仪表盘中,您可以创建两类广告,一类用于PC/Tablet。另一类用于移动,然后分别替换您的 VS 项目中的单元 ID 和应用程序 ID。
I'm also not sure how I should handle Width/Height adjustment on specific platforms.***
首先请用EasClientDeviceInformation class判断是phone还是PC平台,之后可以在cs代码中编程添加Adcontrol,具体平台如下:
var clientDeviceInformation = new EasClientDeviceInformation();
var operatingSystem = clientDeviceInformation.OperatingSystem;
if (operatingSystem.Equals("WINDOWS"))
{
//add Adcontrol for Windows
// Programatically create an ad control. This must be done from the UI thread.
var adControl = new AdControl();
// Set the application id and ad unit id
// The application id and ad unit id can be obtained from Dev Center.
adControl.ApplicationId = "66ad92bf-3c62-4fa8-ad1c-421a56bf0231";
adControl.AdUnitId = "309519";
// Set the dimensions(windows)
adControl.Width = 160;
adControl.Height = 600;
// Add event handlers if you want
adControl.ErrorOccurred += OnErrorOccurred;
adControl.AdRefreshed += OnAdRefreshed;
}
else
{
//add Adcontrol for Windows phone
var adControl = new AdControl();
// Set the application id and ad unit id
// The application id and ad unit id can be obtained from Dev Center.
// See "Monetize with Ads" at https://msdn.microsoft.com/en-us/library/windows/apps/mt170658.aspx
adControl.ApplicationId = "90b6905b-da20-42fc-bb86-c2b41140fe4e";
adControl.AdUnitId = "311213";
// Set the dimensions(windows)
adControl.Width = 300;
adControl.Height = 50;
// Add event handlers if you want
adControl.ErrorOccurred += OnErrorOccurred;
adControl.AdRefreshed += OnAdRefreshed;
}
更多信息请参考官方示例Scenario2:
此外你需要确保这里的宽度和高度是supported size