在 Windows Phone 8 中设置广告 [英] Set up ads in Windows Phone 8

查看:18
本文介绍了在 Windows Phone 8 中设置广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些对类似问题(主要是 Windows Phone 7)的零散回复,但想发布一个包含 Windows Phone 8 广告所有要求的答案.

I found a few scattered responses to similar problems (mostly with Windows Phone 7) but wanted to post an answer that contained all requirements for Windows Phone 8 Ads.

我在 Windows Phone 8 中设置广告时遇到了一些问题.每次运行模拟器时,我都会遇到应用程序可以运行但广告不显示的问题.

I've been having some issues setting an ad up in Windows Phone 8. Every time I ran the emulator I ran into an issue where the app would run but the ad would not show up.

应用程序运行正常,但我在输出控制台中注意到记录了以下异常:

The app ran properly but I noticed in the output console that the following exception was logged:

An exception of type 'Microsoft.Advertising.Shared.AdException' occurred in Microsoft.Advertising.Mobile.DLL and wasn't handled before a managed/native boundary

广告在我正在开发的一个应用程序中正常显示,但在另一个应用程序中没有显示,并且异常没有显示任何有用的信息.

Ads show up fine in one app I am developing but not another and the exception does not show any helpful information.

推荐答案

我想出了如何捕获异常并查看实际问题所在(这是我的清单文件中大量缺失的功能).为了尝试从 AdControl 中捕获异常并获取我需要的数据,我在我的页面中添加了以下内容.

I figured out how to catch the exception and see what the issue actually was (which was a large amount of missing capabilities in my Manifest file). In order to try and catch the exception from the AdControl and get the data I needed, I added the following to my page.

捕捉广告控制错误

    public MainPage()
    {
        InitializeComponent();

        AdUnit.ErrorOccurred += AdUnit_ErrorOccurred;
    }

    void AdUnit_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e)
    {
        throw new NotImplementedException();
    }

这表明我缺少 MEDIALIB 权限和 PHONEDIALER 权限.我进行了一些测试并确定任何运行广告的应用都需要以下权限:

Which showed me that I was missing the MEDIALIB permission and the PHONEDIALER permission. I ran some testing and determined that any app that runs ads will require the following permissions:

所需权限

ID_CAP_IDENTIFY_USER
ID_CAP_MEDIALIB_PHOTO
ID_CAP_NETWORKING
ID_CAP_PHONEDIALER
ID_CAP_WEBBROWSERCOMPONENT

设置参数

从我读过的其他帖子中,确保将广告单元的宽度/高度正确设置为 480/80 也很重要,如果它是自动的并且没有最小尺寸,那么广告将不会展示.

From other posts I've read it is also important to make sure you set your ad units width/height properly to 480/80, if it is auto and doesn't have the minimum demensions then the ad will not show.

确保在模拟器中查看它你只能使用 测试 ApplicationId 和 AdUnitId.PubCenter 凭据仅适用于已发布的应用程序.

Make sure that to view it in the emulator you can only use test ApplicationId and AdUnitId. PubCenter credentials will only work in a published application.

<UI:AdControl x:Name="AdUnit" Height="80" Width="480"
    AdUnitId="Image480_80" ApplicationId="test_client" />

隐藏或交换失败/空的广告控件

如果您的 AdControl 失败,它会在您的广告中留下一个很大的空白空间.您可以隐藏它,也可以将其替换为来自其他网络的广告.为此,请捕获如上所示的异常 (AdUnit_ErrorOccurred) 并添加以下内容:

If your AdControl fails it leaves a big empty space in your ad. You can either hide it or swap it with an ad from another network. To do this, catch the exception as shown above (AdUnit_ErrorOccurred) and added the following:

隐藏:

AdUnit.Height = 0;
AdUnit.Visibility = System.Windows.Visibility.Collapsed;

单独设置可见性不起作用,高度也必须设置为 0.

Setting the visibility didn't work on its own, the height has to be set to 0 as well.

交换广告:

您可以显示来自诸如 http://www.adduplex.com 之类的服务的替代广告栏,而不是隐藏 AdControl.

Instead of hiding the AdControl, you could show an alternate ad bar from a service like http://www.adduplex.com.

这篇关于在 Windows Phone 8 中设置广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆