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

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

问题描述

我发现对类似问题(主要是Windows Phone 7)有一些分散的答案,但我想发布一个包含Windows Phone 8 Ads所有要求的答案。



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



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

  Microsoft.Advertising.Mobile.DLL中发生了类型'Microsoft.Advertising.Shared.AdException'的异常,在托管/本地边界

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

解决方案

我想出了如何捕获异常并查看问题的根源(Manifest文件中有很多缺少的功能)。为了尝试从AdControl中捕获异常并获取所需的数据,我在页面中添加了以下内容。



捕获广告控制错误

  public MainPage()
{
InitializeComponent();

AdUnit.ErrorOccurred + = AdUnit_ErrorOccurred;
}

void AdUnit_ErrorOccurred(对象发送者,Microsoft.Advertising.AdErrorEventArgs e)
{
throw new NotImplementedException();
}

哪个告诉我我缺少MEDIALIB权限和PHONEDIALER权限。我进行了一些测试,确定所有运行广告的应用都将需要以下权限:



所需权限

  ID_CAP_IDENTIFY_USER 
ID_CAP_MEDIALIB_PHOTO
ID_CAP_NETWORKING
ID_CAP_PHONEDIALER
ID_CAP_WEBBROWSERCOMPONENT


设置参数



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



确保要在模拟器中查看它,您只能使用测试ApplicationId和AdUnitId 。 PubCenter凭据仅在已发布的应用程序中起作用。

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

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



如果您的AdControl失败,则会在广告中留出很大的空白。您可以隐藏它,也可以将其与其他网络中的广告交换。为此,请捕获上面显示的异常( AdUnit_ErrorOccurred )并添加以下内容:



To隐藏:

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

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



交换广告:



除了显示AdControl,您还可以显示

$ b $,例如 http://www.adduplex.com 之类的服务中的备用广告栏。


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.

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.

解决方案

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.

Catch Ad Control Errors

    public MainPage()
    {
        InitializeComponent();

        AdUnit.ErrorOccurred += AdUnit_ErrorOccurred;
    }

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

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:

Required Permissions

ID_CAP_IDENTIFY_USER
ID_CAP_MEDIALIB_PHOTO
ID_CAP_NETWORKING
ID_CAP_PHONEDIALER
ID_CAP_WEBBROWSERCOMPONENT

Set Parameters

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.

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" />

Hide or Swap Failed/Empty Ad Controls

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:

To Hide:

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

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

Swap Ad:

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天全站免登陆