Thursday, July 21, 2011

iAdd sample for Monotouch app.

This sample shows how to display a banner Add on a montouch app.
I'm using a simple example to show the use of AdBannerView control.
Create a sample Iphone Navigation-based project from Monodevelop.
In Main.cs/AppDelegate class/FinishedLaunching() method add the following code.

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        ADBannerView banner = new ADBannerView(); 
        banner.CurrentContentSizeIdentifier = "ADBannerContentSizePortrait";
        banner.AdLoaded += delegate(object sender, EventArgs e) {
        banner.Hidden = false;
        banner.FailedToReceiveAd += delegate(object sender, AdErrorEventArgs e) {
        banner.Hidden = true;
        banner.Frame = new System.Drawing.RectangleF(0, 30, 320, 50);
        window.AddSubview (navigationController.View);
        window.MakeKeyAndVisible ();
        return true;

The banner must be set to "ADBannerContentSizePortrait" or "ADBannerContentSizeLandscape" using CurrentContentSizeIdentifier property. In this example I'm only targeting portrait layout.
There are two delegates associated with the banner.
FailedToReceiveAd - This is when there is no connection between the app and the iAdd server, the banner is hidden in this case.
AdLoaded - When the iAdd server sends the Add content to display, this is then showed on the Add.

No comments:

Post a Comment