Example #1
0
		public Advertisement() {
	// 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 = "ca-app-pub-8135914038151970/6935695643",
		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");
			UIApplication.SharedApplication.InvokeOnMainThread (delegate { 
				GADRequest r = new GADRequest();

				ad.LoadRequest(r);
			});
			System.Threading.Thread.Sleep(30000);
		}
	});
	}
		public virtual void LoadRequest (GADRequest request)
		{
			if (IsDirectBinding) {
				MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr (this.Handle, selLoadRequest_Handle, request == null ? IntPtr.Zero : request.Handle);
			} else {
				MonoTouch.ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr (this.SuperHandle, selLoadRequest_Handle, request == null ? IntPtr.Zero : request.Handle);
			}
		}
		public virtual void LoadAndDisplayRequest (GADRequest request, global::MonoTouch.UIKit.UIWindow window, global::MonoTouch.UIKit.UIImage image)
		{
			if (request == null)
				throw new ArgumentNullException ("request");
			if (window == null)
				throw new ArgumentNullException ("window");
			if (image == null)
				throw new ArgumentNullException ("image");
			if (IsDirectBinding) {
				MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr_IntPtr (this.Handle, selLoadAndDisplayRequestUsingWindowInitialImage_Handle, request.Handle, window.Handle, image.Handle);
			} else {
				MonoTouch.ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr_IntPtr_IntPtr (this.SuperHandle, selLoadAndDisplayRequestUsingWindowInitialImage_Handle, request.Handle, window.Handle, image.Handle);
			}
		}
		public virtual void LoadRequest (GADRequest request)
		{
			if (request == null)
				throw new ArgumentNullException ("request");
			if (IsDirectBinding) {
				MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr (this.Handle, selLoadRequest_Handle, request.Handle);
			} else {
				MonoTouch.ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr (this.SuperHandle, selLoadRequest_Handle, request.Handle);
			}
		}