我正在努力在我的 Xamarin.Forms 应用程序中实施 Facebook Audience Network。 可用的 nuget 包很旧并且具有过时的方法。
我能够自己实现广告,测试插页式广告是否正确显示,但当其他用户使用我的应用程序时,广告根本不显示。我在日志中看到 FAN 返回错误代码 1001 并显示“未填充”消息。
我做了什么:
public partial class AdView
{
internal partial class IAdViewLoadConfigBuilderInvoker
{
IAdLoadAdConfig IAdLoadConfigBuilder.Build()
{
return Build();
}
IAdLoadConfigBuilder IAdLoadConfigBuilder.WithBid(string p0)
{
return WithBid(p0);
}
}
}
public partial class InterstitialAd
{
IAdLoadConfigBuilder IFullScreenAd.BuildLoadAdConfig()
{
return BuildLoadAdConfig();
}
IFullScreenAdShowConfigBuilder IFullScreenAd.BuildShowAdConfig()
{
return BuildShowAdConfig();
}
internal partial class IInterstitialAdLoadConfigBuilderInvoker
{
IAdLoadAdConfig IAdLoadConfigBuilder.Build()
{
return Build();
}
IAdLoadConfigBuilder IAdLoadConfigBuilder.WithBid(string p0)
{
return WithBid(p0);
}
}
internal partial class IInterstitialAdShowConfigBuilderInvoker
{
IFullScreenAdShowAdConfig IFullScreenAdShowConfigBuilder.Build()
{
return Build();
}
}
}
public abstract partial class NativeAdBase
{
internal partial class INativeAdLoadConfigBuilderInvoker
{
IAdLoadAdConfig IAdLoadConfigBuilder.Build()
{
return Build();
}
IAdLoadConfigBuilder IAdLoadConfigBuilder.WithBid(string p0)
{
return WithBid(p0);
}
}
}
public partial class RewardedVideoAd
{
IAdLoadConfigBuilder IFullScreenAd.BuildLoadAdConfig()
{
return BuildLoadAdConfig();
}
IFullScreenAdShowConfigBuilder IFullScreenAd.BuildShowAdConfig()
{
return BuildShowAdConfig();
}
internal partial class IRewardedVideoAdLoadConfigBuilderInvoker
{
IAdLoadAdConfig IAdLoadConfigBuilder.Build()
{
return Build();
}
IAdLoadConfigBuilder IAdLoadConfigBuilder.WithBid(string p0)
{
return WithBid(p0);
}
}
internal partial class IRewardedVideoAdShowConfigBuilderInvoker
{
IFullScreenAdShowAdConfig IFullScreenAdShowConfigBuilder.Build()
{
return Build();
}
}
}
public abstract partial class AdComponentFrameLayout
{
public void SetLayoutParams(ViewGroup.LayoutParams p0)
{
SetLayoutParams(p0);
}
}
public abstract partial class AdNativeComponentView
{
public void SetLayoutParams(ViewGroup.LayoutParams p0)
{
SetLayoutParams(p0);
}
}
internal partial class IInterstitialAdApiInvoker
{
IAdLoadConfigBuilder IFullScreenAd.BuildLoadAdConfig()
{
return BuildLoadAdConfig();
}
IFullScreenAdShowConfigBuilder IFullScreenAd.BuildShowAdConfig()
{
return BuildShowAdConfig();
}
}
public partial class InitSettingsBuilder
{
AudienceNetworkAds.IInitSettingsBuilder AudienceNetworkAds.IInitSettingsBuilder.WithInitListener(AudienceNetworkAds.IInitListener p0)
{
return WithInitListener(p0);
}
AudienceNetworkAds.IInitSettingsBuilder AudienceNetworkAds.IInitSettingsBuilder.WithMediationService(string p0)
{
return WithMediationService(p0);
}
AudienceNetworkAds.IInitSettingsBuilder AudienceNetworkAds.IInitSettingsBuilder.WithPlacementIds(IList<string> p0)
{
return WithPlacementIds(p0);
}
}
internal partial class IRewardedVideoAdApiInvoker
{
IAdLoadConfigBuilder IFullScreenAd.BuildLoadAdConfig()
{
return BuildLoadAdConfig();
}
IFullScreenAdShowConfigBuilder IFullScreenAd.BuildShowAdConfig()
{
return BuildShowAdConfig();
}
}
AudienceNetworkAds.Initialize(this);
public class InterstitalAdsRenderer : IInterstitalAdsService
{
InterstitialAd _interstitial;
public void Show(string adsId)
{
//AdSettings.AddTestDevice("fe9823bf-946e-4a43-b38c-f958d0bfaa31");
_interstitial = new InterstitialAd(Application.Context, adsId);
var loadAdConfig = _interstitial.BuildLoadAdConfig()
.WithAdListener(new InterstitialAdListener(_interstitial))
.Build();
_interstitial.LoadAd(loadAdConfig);
}
}
internal class InterstitialAdListener : Java.Lang.Object, IInterstitialAdListener
{
private readonly InterstitialAd _interstitial;
public InterstitialAdListener(InterstitialAd interstitial)
{
}
public void OnAdClicked(IAd p0)
{
}
public void OnAdLoaded(IAd p0)
{
_interstitial.Show();
}
public void OnError(IAd p0, AdError p1)
{
Console.WriteLine("OnError: " + p1.ErrorMessage);
}
public void OnLoggingImpression(IAd p0)
{
}
public void OnInterstitialDismissed(IAd p0)
{
}
public void OnInterstitialDisplayed(IAd p0)
{
}
}
正如我之前所说,测试设备中的测试广告(添加到测试设备的模拟器)正确显示广告,但在生产中没有广告:/
有人在 Xamarin.Forms 项目中实现了 Facebook 广告,并且可以告诉我如何正确执行此操作?
此错误通常意味着您尚未登录 Facebook 应用程序或 Facebook 应用程序在您运行应用程序的设备中不可用
我正在尝试在 Xamarin 表单中实现 Facebook 横幅和插页式广告,然后在 MAUI 中实现,但我找不到任何文档或示例,您成功了吗?您能指出或提供示例代码或任何文档吗?非常感谢!!