在使用Monogame的iOS应用中集成Admob

4

我已经试了几天,但仍然无法完成。我尝试找一些样例,但它们都是关于Android的。有人成功地将Admob集成到iOS上吗?

2个回答

2
我在 monotouch-bindings 存储库中使用 AdMob 绑定 遇到了一些问题。但是后来我转而使用 AlexTouch.GoogleAdMobAds 绑定,它们运行得非常好。您可以在 Github 上的 README 中找到使用 AlexTouch.GoogleAdMobAds 的示例。它很简单,但如果您需要帮助,请随时提出更详细的问题。

非常感谢,我是用AlexTouch.GoogleAdMobAds制作的,稍后我会在这里粘贴我的代码。 - user1908944
一切运作良好,直到我点击一个指向某个网站而非App Store的广告时,横幅只是转动并消失,没有任何显示。你有遇到过这种情况吗?我正在研究它。 - user1908944

0
        // code for admob "using AlexTouch.GoogleAdMobAds"
        UIViewController vc = new UIViewController ();
        UIViewController controller = UIApplication.SharedApplication.Windows [0].RootViewController;

        var ad = new GADBannerView (GADAdSizeCons.SmartBannerLandscape, new PointF (0, 0))
        {
            AdUnitID = "ADMOB_ID",
            RootViewController = vc
        };
        ad.Hidden = false;

        ad.DidReceiveAd += delegate {
            ad.Hidden = false;
            ad.Frame = new System.Drawing.RectangleF (0, (int) 0, (int) (ad.Bounds.Width), (int) (ad.Bounds.Height));
            Console.WriteLine ("AD Received");
        };

        ad.DidFailToReceiveAdWithError += delegate(object sender, GADBannerViewDidFailWithErrorEventArgs e) {
            ad.Hidden = true;
            Console.WriteLine (e.Error);

        };

        ad.WillPresentScreen += delegate {
            Console.WriteLine ("showing new screen");
        };

        ad.WillLeaveApplication += delegate {
            Console.WriteLine ("I will leave application");
        };

        ad.WillDismissScreen += delegate {
            Console.WriteLine ("Dismissing opened screen");
        };
        ad.UserInteractionEnabled = true;

        vc.View.AddSubview(ad);
        vc.View.Frame = new System.Drawing.RectangleF(0f,  0f,  (int)(ad.Bounds.Width), (int)(ad.Bounds.Height));
        controller.View.AddSubview(vc.View);

        Task.Factory.StartNew(() => {
            while (true)
            {
                Console.WriteLine("Requesting Ad");
                InvokeOnMainThread (delegate { 
                    GADRequest r = new GADRequest();

                    ad.LoadRequest(r);
                });
                System.Threading.Thread.Sleep(30000);
            }
        });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接