我的通用应用程序(不是新的 UWP10)几乎所有页面都在桌面和手机项目之间共享。这些页面是 .Shared
项目的一部分;与特定于平台的项目相同的命名空间。
现在,向页面添加一个 AdControl
控件并不困难,但我不确定如何处理该控件的平台特定方面,例如 AdId
、高度
或 宽度
。由于 DevCenter 中的广告分为两类(平板电脑和 PC/手机),我不知道应该输入什么作为 ID 参数。我也不确定我应该如何处理特定平台上的宽度/高度调整。
最好的解决方案是什么?
最佳答案
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.***
在dashboard中,你可以创建两类广告,一类是PC/Tablet,另一类是Mobile,然后分别替换你VS工程中的unit ID和App ID。
I'm also not sure how I should handle Width/Height adjustment on specific platforms.***
首先请用EasClientDeviceInformation class判断是手机平台还是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
关于c# - 在共享的 WinRT 8.1 页面上显示广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39130356/