问题
I'm developing a uwp app, and I finished it and was preparing to submit my app in the store, through the dev center. My application has AdControl
advertising, which is presented in the desktop version (Windows 10) and the mobile version (Windows 10 Mobile) through VisualStateManager
In the Desktop version I have:
<Setter Target="Ad.Height" Value="90"/>
<Setter Target="Ad.Width" Value="728"/>
In the Mobile version I have:
<Setter Target="Ad.Height" Value="50"/>
<Setter Target="Ad.Width" Value="320"/>
That is, the size of the banner adapts to the different screen sizes.
My question is: In Dev Center, in "Microsoft advertising ad units" I have to choose a Device family. How do I do it? Do I have to generate a PC / tablet ID and a mobile ID? And then how do I do this in my code? I only have one ad control that accepts only one ID
回答1:
Do I have to generate a PC / tablet ID and a mobile ID?
Yes.
how do I do this in my code? I only have one ad control that accepts only one ID
You can initialize the AdControl with the devicefamily-dependent Ad Id from your code behind. ( You have not to set with XAML. )
Following url shows the example of MsAdControl and AdDuplex switching, but it may help to understand the adcontrol initializing and detecting device families.
Migrate from AdMediatorControl to AdControl
回答2:
In Dev Center, in "Microsoft advertising ad units" I have to choose a Device family. How do I do it?
You need to select the device type on which you want to show ads and just click "Create ad unit" to generate them. And later you will use these values in your code.
For banner ads:https://docs.microsoft.com/en-us/windows/uwp/monetize/adcontrol-in-xaml-and--net
For interstitial ads(for video):https://docs.microsoft.com/en-us/windows/uwp/monetize/interstitial-ads
Do I have to generate a PC / tablet ID and a mobile ID?
Yes, it's highly recommended to do it.
And then how do I do this in my code? I only have one ad control that accepts only one ID
To create Ad Control to display the ads for both device family type, you can follow the code in the documentation:
// Declare an AdControl.
private AdControl myAdControl = null;
// Application ID and ad unit ID values for Microsoft advertising. By default,
// assign these to non-mobile ad unit info.
private string myAppId = DESKTOPAPPLICATIONID;
private string myAdUnitId = DESKTOPADUNITID;
Add the following code to your Page class constructor, after the call to the InitializeComponent() method.
myAdGrid.Width = AD_WIDTH;
myAdGrid.Height = AD_HEIGHT;
// For mobile device families, use the mobile ad unit info.
if ("Windows.Mobile" == AnalyticsInfo.VersionInfo.DeviceFamily)
{
myAppId = MOBILEAPPLICATIONID;
myAdUnitId = MOBILEADUNITID;
}
// Initialize the AdControl.
myAdControl = new AdControl();
myAdControl.ApplicationId = myAppId;
myAdControl.AdUnitId = myAdUnitId;
myAdControl.Width = AD_WIDTH;
myAdControl.Height = AD_HEIGHT;
myAdControl.IsAutoRefreshEnabled = true;
myAdGrid.Children.Add(myAdControl);
来源:https://stackoverflow.com/questions/43189249/microsoft-advertising-ad-units-device-family