我无法在我的Windows Phone 8应用中集成adcontrol。 在Windows Phone 8中,微软广告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 :(得分:5)
解决方案:
我在你的问题中发现的问题是能力问题,请记住,从windows phone-7到windows phone-8的功能有所改变。
您添加的功能是根据Windows Phone-7(如您在链接中提到的那样)。
找到所需的功能样品:
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>
答案 1 :(得分: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);
}
}