在使用monogame的iOS App中集成Admob

时间:2012-12-17 04:07:58

标签: ios xamarin.ios admob monogame

我试图这样做几天,仍然无法做到。我试图找到一些样本,但它们都在Android上。有没有人成功在iOS上集成admob?

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分: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);
            }
        });