【问题标题】:Displaying ads on shared WinRT 8.1 page在共享 WinRT 8.1 页面上显示广告
【发布时间】:2017-01-01 00:07:03
【问题描述】:

我的通用应用程序(不是新的 UWP10)几乎在桌面和手机项目之间共享所有页面。这些页面是.Shared 项目的一部分;与平台特定项目相同的命名空间。

现在,将AdControl 控件添加到页面并不难,但我不确定如何处理控件的特定于平台的方面,例如AdIdHeight 或@ 987654325@。由于 DevCenter 中的广告分为两类(平板电脑和 PC/手机),我不知道我应该输入什么作为 ID 参数。我也不确定如何在特定平台上处理宽度/高度调整。

什么是最好的解决方案?

【问题讨论】:

    标签: c# xaml windows-phone-8.1 windows-store-apps windows-8.1-universal


    【解决方案1】:

    由于 DevCenter 中的广告分为两类(平板电脑和 PC/Mobile)我不知道我应该输入什么作为 ID 参数。***

    在仪表板中,您可以创建两类广告,一类用于 PC/平板电脑。另一类用于移动设备,然后分别替换 VS 项目中的单元 ID 和应用 ID。

    我也不确定如何在特定平台上处理宽度/高度调整。***

    先用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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-08
      • 2021-12-12
      • 2016-12-10
      • 1970-01-01
      • 2019-04-11
      相关资源
      最近更新 更多