【发布时间】:2016-08-22 19:28:53
【问题描述】:
在我的项目中插入适用于 Windows Phone 8 的 AdMob SDK,并在 android 项目中进行配置。 Android 项目运行良好,但在广告中运行 Windows Phone 模拟器时没有显示。
我检查了功能,这一切都正确,如下:
ID_CAP_MEDIALIB_AUDIO
ID_CAP_MEDIALIB_PLAYBACK
ID_CAP_NETWORKING
ID_CAP_WEBBROWSERCOMPONENT
按照我的渲染器代码:
[assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobViewRenderer))]
namespace calculotrabalhista.WinPhone
{
public class AdMobViewRenderer : ViewRenderer<AdMobView, AdView>
{
protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var ad = new AdView
{
Format = AdFormats.Banner,
AdUnitID = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxx"
};
var adRequest = new AdRequest();
#if DEBUG
adRequest.ForceTesting = true;
#endif
ad.LoadAd(adRequest);
SetNativeControl(ad);
}
}
}
}
Xamarin(便携式)xaml:
<CustomControls:AdMobView Grid.Row="1" VerticalOptions="FillAndExpand"/>
AdMobView 类:
public class AdMobView : Xamarin.Forms.View
{
// enables data binding for the AdMob ad unit id
[Obsolete]
public static readonly BindableProperty AdUnitIdProperty = BindableProperty.Create<AdMobView, string>(p => p.AdUnitId, "");
// holds the AdMob ad unit id
[Obsolete]
public string AdUnitId
{
get
{
return (string)this.GetValue(AdUnitIdProperty);
}
set
{
this.SetValue(AdUnitIdProperty, value);
}
}
}
注意项目android广告正常显示。运行Windows Phone项目并在正常触发的Renderer部分下断点没有错误,但什么也没有出现。
【问题讨论】:
标签: c# xaml xamarin admob xamarin.forms