在XNA中使用
1. 程序ID和广告布局
private static readonly string ApplicationId = "test_client";
private static readonly string AdUnitId = "Image480_80"; //other test values: Image480_80, Image300_50, TextAd
2. Initialize中
{
AdGameComponent.Initialize(this, ApplicationId);
Components.Add(AdGameComponent.Current);
DrawableAd bannerAd = AdGameComponent.Current.CreateAd(AdUnitId, new Rectangle(x, y, 480, 80), true);
bannerAd.ErrorOccurred += new EventHandler<Microsoft.Advertising.AdErrorEventArgs>(bannerAd_ErrorOccurred);
bannerAd.AdRefreshed += new EventHandler(bannerAd_AdRefreshed);
AdGameComponent.Current.Enabled = false;
//在取到地理位置信息后将地理位置设置给AD,然后AdGameComponent.Current.Enabled 置为true。
//如果gps状态为GeoPositionStatus.Disabled或GeoPositionStatus.NoData, 也置为true
}
在SilverLight中使用
下面是写在cs中间中的方式。写在xaml中类似
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;
adControl.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
ContentPanel.Children.Add(adControl);