4

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

4

2 回答 2

2

我对来自 monotouch-bindings 存储库的AdMob 绑定有一些问题。但后来我切换到AlexTouch.GoogleAdMobAds绑定,它们工作得很好。您可以在 Github 上的 README 中找到使用 AlexTouch.GoogleAdMobAds 的示例。很简单,但如果您需要一些帮助 - 请随时提出更详细的问题。

于 2012-12-17T10:24:07.877 回答
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);
            }
        });
于 2012-12-18T02:39:34.937 回答