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項目並在其正常觸發的渲染器部分放置斷點時沒有錯誤,但不顯示任何內容。