Gor*_*ger 7 c# windows-store-apps
是否可以AdControl在具有多个AdUnitIds 的Windows 8.1应用程序中使用一个?我从网上的不同来源跟踪方法得到了AdControl一些工作,但现在我已经发现(在向AdControls ErrorOccurred事件添加事件处理程序之后)错误代码NoAdAvailable,意味着对于所选类别没有广告正在送达(我在德国).我的代码AdControl看起来像这样:
AdControl adControl = new AdControl
{
ApplicationId = "a1b2c3d4-1a2a-1234-1a2a-1a2b3c4d5e6f",
AdUnitId = "123456",
HorizontalAlignment = HorizontalAlignment.Left,
Height = 250,
VerticalAlignment = VerticalAlignment.Top,
Width = 250
};
adControl.ErrorOccurred += adControl_ErrorOccurred;
Run Code Online (Sandbox Code Playgroud)
根据Microsoft pubCenter中显示的信息,当我为广告添加多个类别时,ApplicationId保持不变(如预期),但AdUnitId会发生变化.如何使用来自多个类别的广告,是否有简单的解决方案?或者我是否必须尝试实例化一段AdControl时间更改类别(因此AdUnitId直到我不再获得异常然后使用那个?最好的方法是什么?
更新
AdUnitId一旦设置,您就不能更改它,所以这不起作用.
更新2
我仍然不确定是否所有设置都正确 - 当我启动我的应用程序(从Windows App Store安装)时,我总是收到"NoAdsAvailable"错误.应显示广告的类别是"游戏",因此错误消息表明(对于我的区域),该类别中没有广告.当我使用不同的广告应用时,他们会展示必须来自游戏类别的广告,所以我担心我可能没有正确设置所有内容.
有没有人有想法?
You will need to use logic to decide which AdUnitId to use at any given moment. This includes picking different values for different categories for the live application, but also picking one of the Test Mode Values for both AdUnitId and ApplicationId, seen here, for the development version. This is to prevent click fraud.
This page shows how to use a compiler pre-processor directive to ensure you only use test mode values in the debug version of your application.
Be warned! If you try and use live ad ID's in a debug app too often, especially if you click/press the adverts, your advertising id could be suspended.
For a website:
If your site involves people clicking links regularly, I'd probably just settle on generating a different AdUnitId each time the page loaded.
However if you have a page which is expected to be viewed statically for a long time, I'd use AJAX to pull in a 'page' that just has the AdControl on, and randomly select or rotate the AdUnitId, ensuring a new advert is served up every couple of minutes.
Just be careful that this is not done at an excessive rate, and that the ads are shown clearly to the user, to avoid any impression of click fraud attempts.
For a store app: (apologies, my brain misfired :)
对于商店应用程序,只需在长计时器上重新创建一个新AdControl的AdUnitId,然后添加控件.隐藏旧控件,然后正确处理它.