0

我无法将 adcontrol 集成到我的 windows phone 8 应用程序中。在 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

但我仍然没有运气......在一个地方我读到你需要有互联网连接才能看到广告控制。是真的吗。。

无论如何,同样需要帮助。

提前致谢!!!...

4

2 回答 2

5

解决方案:

我在您的问题中发现的问题是功能,请记住一件事,从 windows phone-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>
于 2014-06-25T07:44:25.340 回答
0

假设您正确完成了其余所有要求并下载了 Microsoft Ads 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);
            }
        }
于 2014-03-24T05:55:57.963 回答