【问题标题】:Xamarin Forms iOS Renderer for Facebook Audience NetworkXamarin 为 Facebook Audience Network 构建 iOS 渲染器
【发布时间】:2020-12-16 18:40:54
【问题描述】:

我使用 Xamarin Forms 开发了一个跨平台应用程序,该应用程序运行良好。现在,我想在应用中展示广告,所以我阅读了一些文章并浏览了一些 youtube 视频 https://www.youtube.com/watch?v=fENpVR0rlO8。大多数视频仅向您展示了如何在 Andriod 中为 FAN 实现自定义渲染器,但我没有找到任何可以指导我如何在 iOS 中为 FAN 实现自定义渲染器的文章或视频

谁能建议我该怎么做?

谢谢。

【问题讨论】:

  • 查看this thread 中的代码会有所帮助。
  • @JackHua-MSFT 我已经调查过了,但到目前为止还没有工作:(

标签: c# xamarin xamarin.ios facebook-audience-network


【解决方案1】:

我找到了解决问题的方法。这是我为使其工作所做的工作。也许它可以帮助像我这样的人

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using Facebook.AudienceNetwork;
using CoreGraphics;
using Foundation;
using UIKit;
using VRunTracker;
using VRunTracker.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(FacebookAdsControl), typeof(FacebookAdRenderer))]
namespace VRunTracker.iOS
{
    public class FacebookAdRenderer : ViewRenderer<FacebookAdsControl,UIView>
    {
        public FacebookAdRenderer()
        {

        }

        private FacebookAdsControl AdsControl => (FacebookAdsControl) Element;

        protected override void OnElementChanged(ElementChangedEventArgs<FacebookAdsControl> e)
        {
            base.OnElementChanged(e);
            if (AdsControl == null)
            {
                return;
            }
            var rootVC = UIApplication.SharedApplication.Windows[0].RootViewController;
            AdView adView = new AdView(AdsControl.PlacementId, AdSizes.BannerHeight50, rootVC);
            adView.LoadAd();
            SetNativeControl(adView);


        }
    }
}

希望可以帮助其他人。 里耶

【讨论】:

  • 你可以标记这个答案,这将帮助更多有同样问题的人:)。
猜你喜欢
  • 2016-05-19
  • 1970-01-01
  • 2020-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多