0
将Windows Phone 8的AdMob SDK插入到我的项目中,并在Android项目中进行配置。 Android项目工作完美,但在广告中运行Windows Phone模拟器时未显示。Xamarin表单跨平台AdMob未呈现
我检查的能力和这一切正确,方法如下:
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项目并在其正常触发的渲染器部分放置断点时没有错误,但不显示任何内容。