2013-05-25 59 views
0

我無法將adcontrol集成到我的Windows Phone 8應用程序中。 在windows phone 8中,microsoft advertising sdk已經在參考文獻中提供,因此沒有下載相同的文件。 下面的代碼片段我用:無法在Windows Phone 8中集成Microsoft廣告SDK

// Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 

     // ApplicationID = "test_client", AdUnitID = "Image480_80", 

     AdControl adControl = new AdControl("test_client", // ApplicationID 
              "Image480_80", // AdUnitID 
              true);   // isAutoRefreshEnabled 
     // Make the AdControl size large enough that it can contain the image 
     adControl.Width = 480; 
     adControl.Height = 80; 

     Grid grid = (Grid)this.LayoutRoot.Children[1]; 
     grid.Children.Add(adControl);    
    } 

在這個環節提到我還添加了多種功能: Windows phone ads not working

但是還是我有沒有運氣...在一個地方,我讀您需要連接互聯網才能看到adcontrol。這是真的嗎?

總之需要幫助。

在此先感謝!!! ...

+0

任何人任何幫助,在同一... – Siddharth

+0

我面對類似的問題,我嘗試了兩種方法,但來自酒吧中心的廣告根本不工作。 – sunder

回答

0

假設你做的東西,要求所有的休息和正確下載的微軟廣告SDK,並在該基準添加它

頂部的主要原因

using Microsoft.Advertising.Mobile.UI; 

頁在MainPage類初始化這些

Grid adGrid = new Grid(); 
StackPanel adStackPanel = new StackPanel(); 
AdControl adControl = new AdControl("test_client", "Image480_80", true); 

在構造函數做到這一點

adControl.Width = 480; 
adControl.Height = 80; 
adStackPanel.Children.Insert(0, adControl); 
adGrid.Children.Insert(0, adStackPanel); 
adGrid.HorizontalAlignment = HorizontalAlignment.Right; 
adGrid.VerticalAlignment = VerticalAlignment.Bottom; 
this.DrawingSurfaceBackground.Children.Insert(0, adGrid); 


//Optional 
adControl.ErrorOccurred += adControl_ErrorOccurred; 
void adControl_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e) 
     { 
      try 
      { 
       AdControl ad = (AdControl)sender; 

       Dispatcher.BeginInvoke(() => 
       { 
        // MessageBox.Show(e.Error.ToString()); 
        Debug.WriteLine(

      "error in ad control '" + ad.Name + "': " + e.Error.Message); 

        Debug.WriteLine("ad control '" + ad.Name + "' visibility = " + ad.Visibility); 
       }); 

      } 

      catch (Exception evnt) 
      { 
       Debug.WriteLine("oh no! " + evnt.Message); 
      } 
     } 
5

解決方案:我在你的問題已經發現的是能力

問題,保持一件事記住,在功能從Windows電話7到Windows Phone的變化-8。

你添加的功能是根據windows phone-7(正如你從鏈接中提到的)。

你能找到所需要的能力:http://msdn.microsoft.com/en-us/library/advertising-mobile-windows-phone-manifest-capabilities(v=msads.20).aspx

樣品:

public MainPage() 
    { 
     InitializeComponent(); 
     AdControl adCntrl = new AdControl(); 
     adCntrl.Height = 80; 
     adCntrl.Width = 480; 
     adCntrl.ApplicationId = "test_client"; 
     adCntrl.AdUnitId = "Image480_80"; 
     ContentPanel.Children.Add(adCntrl); 
    } 

與能力:

<Capabilities> 
    <Capability Name="ID_CAP_IDENTITY_USER"/> 
    <Capability Name="ID_CAP_MEDIALIB_PHOTO"/> 
    <Capability Name="ID_CAP_NETWORKING"/> 
    <Capability Name="ID_CAP_PHONEDIALER"/> 
    <Capability Name="ID_CAP_WEBBROWSERCOMPONENT"/> 
    <Capability Name="ID_CAP_MEDIALIB_AUDIO"/> 
    <Capability Name="ID_CAP_MEDIALIB_PLAYBACK"/> 
    <Capability Name="ID_CAP_SENSORS"/> 
</Capabilities>