2012-03-17 89 views
12

我正在嘗試將廣告整合到已成功部署的應用程序中。然而,無論我做什麼,我似乎都無法讓廣告運作。我已經嘗試使用代碼版本和拖放n'放gui版本。我都無法工作。Windows手機廣告無法正常工作

這就是我看到的:當它啓動時,它可能會閃爍一秒白色,廣告應該在哪裏,但是沒有更多,沒有增加。它承認它是我放置它的地方,當我把它放在一個按鈕上時,按鈕變得不可點擊。所有人都說,沒有默認的「微軟廣告」圖像彈出。我已經安裝了廣告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)); 
     } 
    } 
} 

回答

20

我有同樣的問題,並寫了一個blog post關於它。這裏是最重要的東西:

有問題的症狀SDK的AdControl似乎是相當一致的:該頁面加載,控制閃爍短暫,呈現出1個像素幀的提示,然後,。它陷入虛無,只留下一片失望的黑洞。

理論上,設置AdControl很簡單。 documentation from Microsoft概述了基本知識:

  • 下載並安裝Microsoft Advertising SDK
  • 添加對Microsoft.Advertising.Mobile.UI的引用。
  • 將控件拖放到Visual Studio設計器中的頁面上。
  • AdUnitIdApplicationId屬性設置爲可以從Microsoft pubCenter獲取的測試值或實際活動值。

但它不可能那麼容易。我仔細地跟蹤了文檔,但沒有任何工作。我甚至無法看到測試廣告,這看起來很奇怪。我甚至還原了我的應用程序的老版本(yay源代碼控制!),並放入新的.dll。失敗。

最後,我在obscure forum post中發現了一條線索。

Microsoft文檔忽略了幾個重要的細節。你需要特別注意以下,如果你升級現有項目的芒果廣告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

您的先生,不僅僅是特別有用的:)原來我沒有包括<能力名稱=「ID_CAP_NETWORKING」/>大聲笑去圖 – 2012-03-17 02:18:57

+1

哈,很好。 :)很高興成爲服務。 – 2012-03-17 02:22:44

+0

如果你想要綁定數據。 https://gist.github.com/1927879 – 2012-03-17 06:30:00

2

我認爲你的問題可能來自(如果你沒」 t取出它在這裏張貼):

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

你必須使用adUnitId設置和的applicationID你從pubCenter得到。

+1

是的,我已經得到了憑據,但爲了測試,那裏的憑據將(應該)顯示一個默認圖像來代替實際的廣告 – 2012-03-17 02:11:08

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

作爲示例所示。聲明廣告和名稱空間是非常重要的。 在我的項目中,我只是插入了廣告控制​​部分alt +輸入resharper來完成他沒有做的其餘工作。他用UI取代了廣告,並且沒有錯誤編輯,但廣告仍然沒有顯示。當我自己宣佈廣告並更改adcontrol命名空間時。一切正常。