Windows手机广告无效

时间:2012-03-17 02:02:16

标签: windows-phone-7

我正在尝试将广告整合到已经成功部署的应用中。但无论我做什么,我似乎无法让广告正常运作。我尝试过使用代码版本和drag n'drop gui版本。我都不能开始工作。

这就是我所看到的:当它启动时,它可能会闪烁一瞬间白色,广告本应该是,但不过没有,没有添加。它识别它放在我放置的位置,当我将它放在按钮上时,按钮变得不可点击。总而言之,没有默认的“微软广告”图像弹出。我已经安装了广告SDK,并且已经成功地轻松地在其他项目中展示广告。

是什么给出的?这是非常简单的页面,我无法弄清楚出了什么问题。我似乎也无法在任何其他页面上放置广告......我确实拥有Microsoft.Advertising.Mobile和Microsoft.Advertising。 Mobile.UI包含在项目中,我的互联网正在运行(我有一个项目同时打开广告并且有效)

<phone:PhoneApplicationPage 
    x:Class="AppName.AdPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True"
    xmlns:my="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Margin="12,17,12,28">
            <TextBlock x:Name="PageTitle" Text="Thank You!" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Width="334" />
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0" Height="569" VerticalAlignment="Top">

            <Button Content="Ok" Height="72" HorizontalAlignment="Center" Margin="0,428,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
            <my:AdControl AdUnitId="Image480_80" ApplicationId="test_client" Height="80" HorizontalAlignment="Left" Margin="-12,458,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" />
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Advertising.Mobile.UI;
using Microsoft.Advertising.Mobile;
namespace Stickey_Note_v._1
{
    public partial class AdPage : PhoneApplicationPage
    {
        public AdPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }
    }
}

3 个答案:

答案 0 :(得分:20)

我遇到了同样的问题并写了blog post。这是重要的事情:

SDK的AdControl问题的症状似乎非常一致:页面加载,控件短暂闪烁,显示1像素帧的提示,然后, poof 。它崩溃成虚无,只留下一个绝望的黑洞。

理论上,设置AdControl很简单。 documentation from Microsoft概述了基础知识:

  • 下载并安装Microsoft Advertising SDK
  • 添加对Microsoft.Advertising.Mobile.UI
  • 的引用
  • 将控件拖到Visual Studio设计器中的页面上。
  • AdUnitIdApplicationId属性设置为测试值或实际实时值,您可以从Microsoft pubCenter获取这些值。

但它不是那么容易。我仔细地按照文档,但没有任何工作。我甚至无法展示测试广告,这看起来很奇怪。我甚至还原到我的应用程序的旧版本(yay source control!)并放入新的.dll中。故障。

最后,我在obscure forum post找到了线索。

Microsoft文档忽略了几个重要细节。如果您将现有项目升级到Mango广告SDK,则需要特别注意以下事项:

  • 您必须为AdControl指定高度和宽度。如果未指定HeightWidth属性,或将其设置为auto,则会导致沮丧的泪水。我推荐80像素高,480像素宽,因为这是微软提供的广告的原始尺寸。
  • 您似乎不能在同一页面上拥有两个AdControls,或者至少不能在同一个父元素中。第二个将崩溃。可能有一种解决方法,但我在构建我的演示应用程序时发现它并不关心寻求解决方案。
  • 您必须必须在WMAppManifest.xml文件中指定某些功能。由于我正在升级我的应用程序,因此我没有声明一些较新的功能。导致所有麻烦的是ID_CAP_IDENTITY_USER。控件正常运行需要以下功能:
<Capabilities>
    <Capability Name="ID_CAP_IDENTITY_USER"/>
    <Capability Name="ID_CAP_MEDIALIB"/>
    <Capability Name="ID_CAP_NETWORKING"/>
    <Capability Name="ID_CAP_PHONEDIALER"/>
    <Capability Name="ID_CAP_WEBBROWSERCOMPONENT"/>
</Capabilities>

希望有所帮助!

答案 1 :(得分:2)

我认为您的问题可能来自(如果您没有将其删除以便在此处发布):

 <my:AdControl AdUnitId="Image480_80" ApplicationId="test_client" Height="80" HorizontalAlignment="Left" Margin="-12,458,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" />
        </Grid>

您必须使用从pubCenter获得的AdUnitId和ApplicationId。

答案 2 :(得分:0)

还有一点需要注意那些仍在努力的人

  xmlns:ads="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI"

 <ads:AdControl Height="80"
                           Width="480"
                           AdUnitId="Image480_80"
                           ApplicationId="test_client" />

如例子中所示。声明广告和命名空间非常重要。 在我的项目中,我刚刚插入了adcontrol部分alt + enter for resharper来完成他没有做的其余工作。他用UI替换广告,并且没有错误编译,广告也不会显示。当我自己宣布广告并更改adcontrol名称空间时。一切都很好。