MonoTouch Binding for AdMob

Update 10/11/09: Fixed code display.
Update 01/05/2010: Download a MonoDevelop project sample at http://www.sabonrai.com/downloads/MT_SampleAdMob.zip. This includes fixes for the problems pointed out in the comments by Rory.

It’s not complete yet, but the basics work, so here’s my effort at building a MonoTouch binding for AdMob. This is my first attempt at making a MonoTouch binding to an Objective-C type, so please make suggestions.

Follow these MonoTouch-specific instructions adapted from AdMob’s wiki page. The paragraph numbers correspond to their instructions.

(1) Copy the 3.0 libraries (.a files) found in the AdMob SDK extras directory into your MonoTouch project.

(2) Add these to your additional mtouch arguments:

-gcc_flags “-framework QuartzCore -Lpath-to-the-admob-library -lAdMobSimulator3_0 -ObjC”

(3) “Get a publisher id from http://www.admob.com.”;

(4) “Integrate AdMob ads with your app.” I chose this technique:

(b) “Add an ad to a view programmatically.”

        // Create and customize the delegate
        AdMobDelegate adMobDelegate = new AdMobDelegate();
        adMobDelegate.PublisherId = new NSString(myPublisherID);
        adMobDelegate.AdReceived += delegate (AdMobView adView)
        {
            this.View.AddSubview(advertView);
            Thread thread = new Thread(new ThreadStart(RequestFreshAd));
            thread.Start();
        };
        // Example of changing the background color
        adMobDelegate.AdBackgroundColor = new UIColor(0, 0, 0, 1);

        // Create the AdMobView referencing the delegate you just created
        AdMobView advertView =
            AdMobView.RequestAdWithDelegate(adMobDelegate);

        // In this example, the AdMobView is placed just above a UIToolBar
        float advertHeight = 48;
        advertView.Frame = new RectangleF (
            0,
            this.View.Frame.Height - advertHeight - toolbar.Frame.Height,
            this.View.Frame.Width,
            advertHeight);

Departing from AdMob’s instructions (numbers don’t correspond):

(5) Sample code for requesting a fresh ad:

    private void RequestFreshAd()
    {
        while (true)
        {
            Thread.Sleep(60000); // Request fresh ad once per minute
            this.InvokeOnMainThread(advertView.RequestFreshAd);
        }
    }

(6) The AdMobView class works except for the Version property. I don’t know why it’s sending the message to the AdMobViewInternal class and so getting an unrecognized selector.

using System;
using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;

namespace AdMob
{
    [Register ("AdMobView")]
    public class AdMobView : UIView
    {
        static Selector selInit = new Selector("init");
        static Selector selRequestAdWithDelegate =
            new Selector("requestAdWithDelegate:");
        static Selector selRequestFreshAd =
            new Selector("requestFreshAd");
        static Selector selVersion = new Selector("version");

        [Export ("init")]
        public AdMobView()
            : base(NSObjectFlag.Empty)
        {
            Handle = Messaging.IntPtr_objc_msgSend(
                this.Handle, selInit.Handle);
        }

        // This constructor must be present so that
        // MonoTouch can create instances of this type
        // from Objective-C code.
        public AdMobView (IntPtr handle)
            : base(handle)
        {
        }

        /**
         * Initiates an ad request and returns a view that will
         * contain the results; the delegate is alerted when the
         * ad is ready to display (or has failed to load); this is
         * a good opportunity to attach the view to your
         * hierarchy. If you already have a AdMobView with an
         * ad loaded, and simply want to show a new ad in the
         * same location, you may use -requestFreshAd instead
         * (see below).
         *
         * This method should only be called from a run loop in
         * default run loop mode. If you don't know what that
         * means, you're probably ok. If in doubt, check whether
         * ([[NSRunLoop currentRunLoop] currentMode] ==
         * NSDefaultRunLoopMode).
         */
        public static AdMobView RequestAdWithDelegate(
            AdMobDelegate Delegate)
        {
            // Get class type
            Class adMobViewClass = new Class("AdMobView");

            return (AdMobView) Runtime.GetNSObject(
                Messaging.IntPtr_objc_msgSend_IntPtr(
                    adMobViewClass.Handle,
                    selRequestAdWithDelegate.Handle,
                    Delegate.Handle));
        }

        /**
         * Causes an existing AdMobView to display a fresh ad.
         * If an ad successfully loads, it is animated in with a
         * flip; if not, this call fails silently and the old ad
         * remains onscreen.
         *
         * Note that, during the flip, views under the AdMobView
         * will be exposed.
         *
         * To preserve the user experience, we recommend loading
         * fresh ads no more frequently than once per minute.
         */
        public virtual void RequestFreshAd()
        {
            Messaging.void_objc_msgSend(
                this.Handle, selRequestFreshAd.Handle);
        }

        /**
         * Returns the version of the current SDK.
         */
        public virtual string Version
        {
            get
            {
                return ((NSString) Runtime.GetNSObject(
                    Messaging.IntPtr_objc_msgSend(
                        this.Handle,
                        selVersion.Handle))).ToString();
            }
        }
    }
}

(7) This AdMobDelegate class is unfinished:

using System;
using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;

namespace AdMob
{
    [Register("AdMobDelegate")]
    public class AdMobDelegate : NSObject
    {
        public delegate void AdReceivedDelegate (AdMobView adView);
        public event AdReceivedDelegate AdReceived;

        public delegate void AdReceiveFailedDelegate (AdMobView adView);
        public event AdReceivedDelegate AdReceiveFailed;

        private static Selector selInit = new Selector("init");

        [Export ("init")]
        public AdMobDelegate()
            : base(NSObjectFlag.Empty)
        {
            Handle = Messaging.IntPtr_objc_msgSend(this.Handle, selInit.Handle);
        }

        // This constructor must be present so that MonoTouch
        // can create instances of this type from Objective-C code.
        public AdMobDelegate (IntPtr handle)
            : base(handle)
        {
        }

        // Use this to provide a publisher id for an ad request. Get a publisher id
        // from http://www.admob.com
        private NSString myPublisherID;
        public virtual NSString PublisherId
        {
            [Export ("publisherId")]
            get { return myPublisherID; }
            set { myPublisherID = value; }
        }

        // Sent when an ad request loaded an ad; this is a good opportunity to add
        // this view to the hierachy, if it has not yet been added.
        // Note that this will only ever be sent once per AdMobView, regardless of whether
        // new ads are subsequently requested in the same AdMobView.
        [Export ("didReceiveAd:")]
        public virtual void DidReceiveAd (AdMobView adView)
        {
            if (AdReceived != null)
                AdReceived (adView);
        }

        // Sent when an ad request failed to load an ad.
        // Note that this will only ever be sent once per AdMobView, regardless of whether
        // new ads are subsequently requested in the same AdMobView.
        [Export ("didFailToReceiveAd:")]
        public virtual void DidFailToReceiveAd (AdMobView adView)
        {
            if (AdReceiveFailed != null)
                AdReceiveFailed (adView);
        }

        // Specifies the ad background color, for tile+text ads.
        // Defaults to [UIColor colorWithRed:0.443 green:0.514 blue:0.631 alpha:1], which is a chrome-y color.
        // Note that the alpha channel in the provided color will be ignored and treated as 1.
        // We recommend against using a white or very light color as the background color, but
        // if you do, be sure to implement adTextColor and useGraySpinner.
        // Grayscale colors won't function correctly here. Use e.g. [UIColor colorWithRed:0 green:0 blue:0 alpha:1]
        // instead of [UIColor colorWithWhite:0 alpha:1] or [UIColor blackColor].
        private UIColor adBackgroundColor;
        public virtual UIColor AdBackgroundColor
        {
            [Export ("adBackgroundColor")]
            get { return adBackgroundColor; }
            set { adBackgroundColor = value; }
        }

        // Specifies the primary text color for ads.
        // Defaults to [UIColor whiteColor].
        private UIColor primaryTextColor;
        public virtual UIColor PrimaryTextColor
        {
            [Export ("primaryTextColor")]
            get { return primaryTextColor; }
            set { primaryTextColor = value; }
        }

        // Specifies the secondary text color for ads.
        // Defaults to [UIColor whiteColor].
        private UIColor secondaryTextColor;
        public virtual UIColor SecondaryTextColor
        {
            [Export ("secondaryTextColor")]
            get { return secondaryTextColor; }
            set { secondaryTextColor = value; }
        }

        // When a spinner is shown over the adBackgroundColor (e.g. on clicks), it is by default
        // a white spinner. If this returns YES, a gray spinner will be used instead,
        // which looks better when the adBackgroundColor is white or very light in color.
/*        - (BOOL)useGraySpinner;

        // Whether AdMob may use location information. Defaults to NO.
        // We ask that you respect your users' privacy and only enable location requests
        // if your app already uses location information.
        // Note that even if this is set to no, you will still need to include the CoreLocation
        // framework to compile your app; it will simply not get used. (It is a dynamic
        // framework, so including it will not increase the size of your app.)
        - (BOOL)mayAskForLocation;

        // If you have location information available for the user at the time that you
        // make the ad request, you may provide it here (and it is recommended that you do
        // so, to improve user experience and preserve battery life). If this method is implemented,
        // AdMob will not request location information from the OS, even if the method returns
        // nil (which it should if the user's location is not known); if this method is not
        // implemented, then AdMob will request location information directly from the OS.
        //
        // If mayAskForLocation (above) is not implemented, or returns NO, this will not be called
        // and may be completely ignored.
        - (CLLocation *)location;

        // If implemented, lets you specify whether to issue a real ad request or a test
        // ad request (to be used for development only, of course). Defaults to NO.
        - (BOOL)useTestAd;

        // If implemented, lets you specify the action type of the test ad. Defaults to @"url" (web page).
        // Does nothing if useTestAd is not implemented or returns NO.
        // Acceptable values are @"url", @"app", @"video", @"itunes", @"call", @"canvas".
        // Normally, the adservers restricts ads appropriately (e.g. no click to call ads for iPod touches).
        // However, for your testing convenience, they will return any type requested for test ads.
        - (NSString *)testAdAction;

        // The following functions, if implemented, provide extra information
        // for the ad request. If you happen to have this information, providing it will
        // help select better targeted ads and will improve monetization.
        //
        // Keywords and search terms should be provided as a space separated string
        // like "iPhone monetization San Mateo". We strongly recommend that
        // you NOT hard code keywords or search terms.
        //
        // Keywords are used to select better ads; search terms _restrict_ the available
        // set of ads. Note, then, that providing a search string may seriously negatively
        // impact your fill rate; we recommend using it only when the user is submitting a
        // free-text search request and you want to _only_ display ads relevant to that search.
        // In those situations, however, providing a search string can yield a significant
        // monetization boost.
        //
        // For all of these methods, if the information is not available at the time of
        // the call, you should return nil.
        - (NSString *)postalCode; // user's postal code, e.g. "94401"
        - (NSString *)areaCode; // user's area code, e.g. "415"
        - (NSDate *)dateOfBirth; // user's date of birth
        - (NSString *)gender; // user's gender (e.g. @"m" or @"f")
        - (NSString *)keywords; // keywords the user has provided or that are contextually relevant, e.g. @"twitter client iPhone"
        - (NSString *)searchString; // a search string the user has provided, e.g. @"Jasmine Tea House San Francisco"

        // You can control the appearance of the AdMob mini-browser and the nav bars
        // to fit with the rest of your app. See the documentation for UIToolbar
        // and UINavigationBar for details. Defaults to standard iPhone chrome.
        - (UIBarStyle)embeddedWebViewBarStyle;
        - (UIColor *)embeddedWebViewTintColor;

        // Sent just before presenting the user a full screen view, such as a canvas page or an embedded webview,
        // in response to clicking on an ad. Use this opportunity to stop animations, time sensitive interactions, etc.
        - (void)willPresentFullScreenModal;

        // Sent just after dismissing a full screen view. Use this opportunity to
        // restart anything you may have stopped as part of -willPresentFullScreenModal:.
        - (void)didDismissFullScreenModal;
*/
    }
}
About these ads

Tags: , , ,

40 Responses to “MonoTouch Binding for AdMob”

  1. MonoTouch.Info Says:

    MonoTouch Article – MonoTouch Binding for AdMob…

    Thank you for submitting this entry – Trackback from MonoTouch.Info…

  2. Rory Says:

    Hey -

    Been trying to leave a comment, but I think WordPress is freaked out about the code. The C# prolly looks a little like javascript.

    Anyway, without the code sample (which I’ll still try to post), I think the problem with the Version binding is that it’s a class (static) method of the AdMob Objective-C class.

    Let’s see if WP will let me post at least this one little snippet – from your Version property (I’m removing the semicolon in case that’s part of what WP looks for):

    Messaging.IntPtr_objc_msgSend(this.Handle, selVersion.Handle)))

    In that line, the first argument is the Handle to your instance of your AdMob wrapper/binding thingy.

    I’m pretty sure it needs to be a Handle to the *classs*.

    I haven’t tried this yet, and I have no idea if it’ll work, but with MonoTouch’s Objective-C runtime namespace imported, you should be able to do this (leaving semicolons out again):

    Class adMobClass = new Class(this)

    Then, instead of passing “this.Handle” to the call, pass “adMobClass.Handle” – it *should* work. If not, I think it’s on the right path.

    Hope this helps.

    And I also hope this comment makes it through…

  3. Rory Says:

    Something else that *might* be a problem:

    return ((NSString) Runtime.GetNSObject(
    Messaging.IntPtr_objc_msgSend(this.Handle, selVersion.Handle))).ToString()

    I’m a MonoTouch noob (like everybody else), so I could be way off here, but I think you’d want to create the NSString using its IntPtr constructor. So (I’m splitting this into a couple lines for clarity):

    IntPtr ip = Messaging.IntPtr_objc_msgSend(adMobClass.Handle, selVersion.Handle)

    Once you have your IntPtr (the handle), you could do a couple things.

    One way is to create a new instance of NSString and return it like so (still splitting across lines for clarity):

    NSString s = new NSString(ip)
    return s.ToString()

    Another is to use a static method that returns a System.String, so you don’t even have to call ToString():

    return NSString.FromHandle(ip)

    Either works. It’s a matter of preference, I guess. If you want an NSString back, the instance method is dandy. If you want a .Net string back, NSString.FromHandle is a shortcut.

    Either way, you get to avoid some typing by not having to include Runtime.GetNSObject and then casting and so on…

    Again, I hope this helps :)

  4. Herding Code 62: MonoTouch with Miguel de Icaza and Geoff Norton | Herding Code Says:

    [...] MonoTouch Binding for AdMob (discussing binding to Objective-C from C#) [...]

  5. twestley Says:

    This comment tests inserting code in a comment.

    List<string> list = new List<string>()
    {
        "Tangerine",
        "Mango",
        "Grapefruit",
        "Orange",
        "Banana"
    };
    

    This can be done, apparently requiring two steps:

    1) Enter and post a comment with no code. Don’t post code in this little comment entry field. WordPress.com will strip out parts of your code and otherwise complain at you.

    2) Press the “edit” link in your posted comment to bring up the full WordPress.com text editor. Surround your code with these tags as described on the help page: http://en.support.wordpress.com/code/

    Wrap your code in these tags:

    [sourcecode language='css']

    your code here

    [/sourcecode]

    Any of the following can be used for the language parameter (using one is required):

    • bash
    • cpp
    • csharp
    • css
    • delphi
    • html
    • java
    • jscript
    • php
    • python
    • ruby
    • shell
    • sql
    • vb
    • xml

    Code in between the [sourcecode] tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

    Please let me know if this doesn’t work or if you can’t edit a comment after posting it.

  6. ChadR Says:

    Is it possible for someone to publish a working version of this? I have been trying to implement this but am at a dead end. I have a complicated news reader using a tab controller with navigation controllers within the tabs so that I can navigate to stories. I have been unable to implement even a simple applciation with this ad controller :S. Anyone?

    Chad

  7. twestley Says:

    See http://www.sabonrai.com/downloads/MT_SampleTableView2.zip for a sample project. It doesn’t have a navigation controller, but it will work if you substitute your publisher ID as indicated in the variable myPublisherID.

    By the way, the version in this sample project is as published above. I haven’t fixed it based on Rory’s comments yet.

  8. ChadR Says:

    Thanks twestley. I appreciate the sample. I can get the sample to display an ad. however, when I implement the class on my navigation controller I get this error:

    AdERROR:MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: *** +[AdMobView requestAdWithDelegate:]: unrecognized selector sent to class 0x105f7f0
    at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:IntPtr_objc_msgSend_IntPtr (intptr,intptr,intptr)
    at AdMob.AdMobView.RequestAdWithDelegate (AdMob.AdMobDelegate Delegate) [0x0000b] in /Users/chadrosenbohm/Downloads/Gazette NewsReader/RSSReader/AdMobView.cs:49
    at RSSReader.NavController..ctor (MonoTouch.UIKit.UIViewController viewController, System.String appTitle) [0x000cb] in /Users/chadrosenbohm/Downloads/Gazette NewsReader/RSSReader/ViewControllers/NavController.xib.cs:102

    Any suggestions?

  9. twestley Says:

    Hmm, the unrecognized selector error usually means that the interface is wrong, i.e., that the selector name is wrong here:

    static Selector selRequestAdWithDelegate =
        new Selector("requestAdWithDelegate:");
    

    However, I don’t see why it would work in one project and not in another as long as the inteface classes compile and successfully link.

  10. ChadR Says:

    I had to change the RequestAdWithDelegate interface to use selInit.Hand instead of selRequestAdWithDelegate.Handle. I’m not sure that worked. However, it next threw an error on the advertView.Frame =xxx. I tried setting it in the delegate.AdReceived… but still no success.

    2009-10-25 16:39:04.570 RSSReader[20393:20b] *** +[AdMobView frame]: unrecognized selector sent to class 0x105f7f0

    MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: *** +[AdMobView frame]: unrecognized selector sent to class 0x105f7f0
    at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSendSuper_RectangleF (intptr,intptr,System.Drawing.RectangleF)

    I’ll edit and add the file implementation.

  11. chadrosenbohm Says:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using MonoTouch.Foundation;
    using MonoTouch.UIKit;

    using System.Threading;
    using System.Drawing;
    using AdMob;

    namespace RSSReader
    {
    public partial class NavController : UINavigationController
    {
    #region Constructors

    // The IntPtr and NSCoder constructors are required for controllers that need
    // to be able to be created from a xib rather than from managed code

    public NavController (IntPtr handle) : base(handle)
    {
    Initialize ();
    }

    [Export("initWithCoder:")]
    public NavController (NSCoder coder) : base(coder)
    {
    Initialize ();
    }

    public NavController ()
    {
    Initialize ();
    }

    public NavController (UIViewController viewController, string appTitle)
    {
    Initialize ();

    viewController.NavigationItem.RightBarButtonItem = new UIBarButtonItem ( UIBarButtonSystemItem.Refresh );
    viewController.NavigationItem.RightBarButtonItem.Tag = ((FeedsController)viewController).Tag;
    viewController.NavigationItem.RightBarButtonItem.Clicked += delegate(object sender, EventArgs e) {
    {
    if (this.ViewControllers.Length>0)
    ((FeedsController)this.ViewControllers[0]).ReloadRSS();
    }
    };

    UIImageView(UIImage.FromFile(“images/logo.png”));

    this.ViewControllers = new UIViewController[]{ viewController };

    try
    {
    adMobDelegate = new AdMobDelegate();
    adMobDelegate.PublisherId = new NSString(myPublisherID);
    adMobDelegate.AdReceived += delegate (AdMobView adView)
    {

    /*
    // put the ad at the bottom of the screen
    advertView.Frame = new RectangleF (
    0,
    this.View.Frame.Height – advertHeight,
    this.View.Frame.Width,
    advertHeight);
    */
    //viewController.View.AddSubview(advertView);
    this.View.AddSubview(advertView);
    Thread thread = new Thread(new ThreadStart(RequestFreshAd));
    thread.Start();
    };
    adMobDelegate.AdBackgroundColor = new UIColor(0, 0, 0, 1);

    advertView = AdMobView.RequestAdWithDelegate(adMobDelegate);

    // put the ad at the bottom of the screen
    advertView.Frame = new RectangleF (
    0,
    this.View.Frame.Height – advertHeight,
    this.View.Frame.Width,
    advertHeight);

    }
    catch (Exception ex)
    {
    Console.WriteLine(“AdERROR:”+ex.ToString());
    }

    }

    private float advertHeight = 48;
    private AdMobView advertView;
    private AdMobDelegate adMobDelegate;
    private const string myPublisherID = “MyPubID”;

    private void RequestFreshAd()
    {
    while (true)
    {
    Thread.Sleep(60000); // 1 minute
    this.InvokeOnMainThread(advertView.RequestFreshAd);
    }
    }

    void Initialize ()
    {

    }

    #endregion

    }
    }

  12. Kenton Says:

    Hello all,

    Has anyone made any headway beyond these posts from late October? On an unmodified version of the sample project, I too get the “unrecognized selector” exception on requestAdWithDelegate that ChadR talked about…although it seems to me that replacing the selector binding for that method with selInit.Handle would simply re-call the “init” method and that requestAdWithDelegate would never get called…

    Thoughts?

    Thanks in advance!

  13. twestley Says:

    See http://www.sabonrai.com/downloads/MT_SampleAdMob.zip for a sample project. You will need to substitute your publisher ID as indicated in the variable myPublisherID.

    The AdMob interface classes have been fixed for Rory’s comments above, but I’ve not yet completed the interface.

    I can’t duplicate the problems ChadR is having. I don’t know what’s going on there.

    This will work in the simulator, not on the device. See my MonoTouch forum post.

  14. Kenton Says:

    Hi twestley,

    Thanks for the quick reply! After some more perseverance, I found that the problem both ChadR and I were having is related to the additional mtouch arguments in the .csproj file being housed within a node called “ExtraMtouchArgs”. However the latest version of MonoDevelop places them within a node called “MtouchExtraArgs”. After removing the first node from the project file, and re-specifying the arguments using the Project Options dialog, everything ran perfectly.

    Thanks again for your work on this, and the heads up that it’s not working on the hardware. I’ll follow up with you if we find a workaround for that one.

    Thanks!

    -Kenton

  15. twestley Says:

    Here’s the missing secret sauce to making AdMob work on the device. Set the mtouch extra arguments to:

    -noregistrar -gcc_flags "-framework QuartzCore -framework AddressBook -framework CoreLocation -L${ProjectDir}/admob -lAdMobDeviceNoThumb3_0 -ObjC"
    

    Of course, your app may need other frameworks, depending on what you’re doing.

    Thanks for this goes to phantomkingx in MonoTouch Forums post: http://forums.monotouch.net/yaf_postst224_Released-monotouch-app–Knights-Frenzy.aspx.

  16. Kenton Says:

    Hi Twestley,

    Thanks again! This is extremely helpful. Do you know what the difference is between specifying the “NoThumbs” versions of the AdMob files? Under the “Debug/iPhone” configuration, specifying the “NoThumbs” version does not compile, but when I specify the “regular” version, it succeeds…

  17. twestley Says:

    I don’t know the difference. When I searched for it on Google, I found this: http://code.google.com/p/gdata-issues/issues/detail?id=1705. I don’t know what it means. I posted a question to the MonoTouch forums.

    Regardless, you don’t compile it. You include it in your extra mtouch arguments as I described in my comment above.

  18. Kenton Says:

    I just meant that compiling the project itself would fail with “no mtouch output” or a similar error….however I later realized that the case for the folder “AdMob” was wrong in the argument (it was set at “admob”) and once that was fixed everything built and deployed to the device perfectly. It’d be very interesting to see if anyone knows what the NoThumb version actually does under the hood to make it all work.

    Thanks so much again for help and work on this!

    -k

  19. Kenton Says:

    Hi Twestley,

    Just wondered if you’re able to successfully deploy this under the “Release – iPhone” configuration? The project deploys to the device just fine for me under the Debug config, but using the same mtouch args under the Release one fails…I get:

    In file included from /Developer/MonoTouch/SDKs/MonoTouch1.0.iphoneos.sdk/usr/include/mono/metadata/appdomain.h:13,
    from /Developer/MonoTouch/SDKs/MonoTouch1.0.iphoneos.sdk/usr/include/mono/jit/jit.h:11,
    from /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/main.m:10:
    /Developer/MonoTouch/SDKs/MonoTouch1.0.iphoneos.sdk/usr/include/glib.h:91:1: warning: “ABS” redefined
    In file included from /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8,
    from /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:8,
    from /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:9,
    from /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/main.m:9:
    /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:200:1: warning: this is the location of the previous definition
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -miphoneos-version-min=3.0 -gdwarf-2 -L/Developer/MonoTouch/SDKs/MonoTouch1.0.iphoneos.sdk/usr/lib -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk -lz -u _catch_exception_raise -u _CreateZStream -u _CloseZStream -u _Flush -u _ReadZStream -u _WriteZStream -liconv -lmono -lmonotouch /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/HarvestByIcavia.exe.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/monotouch.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/mscorlib.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/System.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/Mono.Security.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/System.Xml.Linq.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/System.Xml.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/System.Core.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/Mono.Data.Sqlite.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/System.Data.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/Mono.Data.Tds.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/System.Transactions.dll.o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/main.o -o /var/folders/oL/oLDLzyqfFtOTeXXvAP07vU+++TI/-Tmp-/tmp266d74b4.tmp/HarvestByIcavia -framework AVFoundation -framework CoreFoundation -framework Foundation -framework OpenGLES -framework QuartzCore -framework CoreGraphics -framework CoreLocation -framework GameKit -framework MapKit -framework MediaPlayer -framework MessageUI -framework UIKit -framework StoreKit -framework AddressBookUI -framework AddressBook -framework AudioToolbox -framework SystemConfiguration -framework QuartzCore -framework AddressBook -L/Users/kenton/Icavia.Source/Core/icavia.core.svnroot/icavia.core/iPhone/HarvestByIcavia/AdMob -lAdMobDeviceNoThumb3_0 -ObjC

    Thoughts?

    Thanks!

    -k

  20. twestley Says:

    Yes, I use the same mtouch arguments for debug and release configurations on the device.

    Regarding the “ABS redefined” and “this is the location of the previous definition” warnings: I assume that’s not the root cause of your problem because I’m getting those as well.

    I’ll update and repost the MT_SampleAdMob project to reflect the NoThumb change.

  21. Kenton Says:

    Does the project successfully build and deploy to the device, even though you get those same messages? For me it does not…only under Debug config will it successfully upload. Do you get those messages under both Debug and Release configs for the device? Or just under Release?

    Thanks again!

    -k

  22. twestley Says:

    I’m at work now with no access to my MacBook. My recollection is that I get the error in both configurations and it still works. I’ll get back to you with more concrete information as soon as I can.

  23. twestley Says:

    The MonoTouch project, http://www.sabonrai.com/downloads/MT_SampleAdMob.zip, is a working example. All four configuration combinations of Debug|Release and iPhone|Simulator work. In all cases, they show the same error/warning messages identified in my previous comment.

    This updated version of the project corrects the mtouch extra arguments. They should be as follows for Simulator:

    -gcc_flags "-framework QuartzCore -framework AddressBook -framework CoreLocation -L${ProjectDir}/admob -lAdMobSimulator3_0 -ObjC"
    

    and for device:

    -noregistrar -gcc_flags "-framework QuartzCore -framework AddressBook -framework CoreLocation -L${ProjectDir}/admob -lAdMobDeviceNoThumb3_0 -ObjC"
  24. Ash Says:

    Hi Westley,

    The new version of monotouch 1.4.100 changes some settings
    http://forums.monotouch.net/yaf_postst448_Monotouch-project-build-fails-after-upgrading-to-MT-1499-and-also-14100.aspx

    Also the new version of AdMob requires these additional frameworks CoreGraphics, AudioToolbox, and MediaPlayer frameworks

    Thx for all the great work.

    - Ash

  25. twestley Says:

    Thanks for the update.

    I have been working on other aspects of my app, so hadn’t noticed the update to AdMob.

  26. Molly Says:

    Man,

    I have been working like crazy trying to get mobclix their ads up and running. I hope this article will help give me some guidance on how to try to get it working..

    It is so frustrating to feel like a noob. (More than a decade experiance in MS programming, so trying to understand the objective-C is like trying to learn chinese => hence monotouch)

    If you are bored or you want a challenge, feel free to post how to use moblix.a
    ;-)

  27. twestley Says:

    I’m not familiar with mobclix. How is that different than using admob?

  28. Dean Says:

    Hi All,

    I can’t seem to get this to compile, I am using the sample project, have put my ID in but it just sits there saying ‘Compiling to native code’ and doesn’t go any further…

    I did have to change the SDK Version and Minimum OS version to 3.2 as if they are on 3.0 it tells me I don’t have the 3.0 SDK.

    Any ideas where to go from here?

    Cheers,
    Dean

  29. twestley Says:

    Dumb question since I don’t know what you’re doing: are you building for iPad? Minimum version of 3.2 applies only to iPad. I’ve not built this for iPad so I don’t know what issues you might run into. If you’re not using iPad, I suggest setting your minimum OS version to 3.0 if you want to support older version of the OS and then you’ll have to download that SDK. Set your base SDK to 4.0 (or 4.0.1) so you can support the current version of the OS.

  30. Dean Says:

    Hi twestley, no, not building for iPad, I have tried many different combinations of OS and SDK settings and they all do the same thing…

    It just sits there saying “Compiling to native code” and goers no further…

    Any other ideas?

    Cheers,
    Dean

  31. Dean Says:

    Just a further note, if I try and build for the phone and not the simulator, I end up with ‘mtouch failed with no output (1)’

    Dean

  32. Dean Says:

    Hi twestley,

    No, definatley for iPhone not iPad…

    I’ve tried different configs of Min OS and SDK and they all do the same thing… just sits there on ‘Compiling to native code’….

    Any other ideas?

    Cheers,
    Dean

  33. Dean Says:

    Hi twestley,

    Deffinatley building for iPhone not iPad…

    I have tried many different combinations of SDK and OS settings but all do the same thing… Just sits there saying ‘Compiling to native code’.

    Any other ideas?

    Regards,
    Dean

  34. Dean Says:

    sorry about the multiple comments… it wasn’t showing any until just now so I thought it hadn’t posted anything :-S

  35. yvan Says:

    It also hangs on my computer, on the same spot.
    Here’s the output:

    Building: MT_SampleAdMob (Debug|iPhone)

    Building Solution MT_SampleAdMob

    Building: MT_SampleAdMob (Debug|iPhone)

    Detecting signing identity…
    Provisioning profile: “YvanSoftware” (3829F934-0BD3-48FF-8A4B-F95BBA7F0146)
    Signing Identity: “iPhone Developer: Yvan JANSSENS (UM96LR8R7K)”
    App ID: “TSZBNT8Q8J.mtsampleadmob”

    Performing main compilation…
    /Developer/MonoTouch/usr/bin/smcs /noconfig “/out:/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.exe” “/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.dll” “/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll” “/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll” “/r:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll” /nologo /warn:4 /debug:+ /debug:full /optimize- /codepage:utf8 “/define:DEBUG” /t:exe “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/Main.cs” “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/admob/AdMobDelegate.cs” “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/admob/AdMobView.cs” “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/Controller/AppController.cs” “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/Controller/MainViewController.cs”
    Build complete — 0 errors, 0 warnings

    Compiling to native code
    /Developer/MonoTouch/usr/bin/mtouch -v –nomanifest –nosign -dev “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app” -r=”/Developer/MonoTouch/usr/lib/mono/2.1/System.dll” -r=”/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll” -r=”/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll” -r=”/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll” -debug -linksdkonly -noregistrar -gcc_flags “-framework QuartzCore -framework AddressBook -framework CoreLocation -L/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/admob -lAdMobDeviceNoThumb3_0 -ObjC” “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.exe”
    Framework does not exist /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk
    Platform = iPhoneOS
    SDK = 3.2
    Deployment Version: 3.0
    Framework is: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk
    Copied /Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.exe to /Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/MT_SampleAdMob.exe
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll to /Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/mscorlib.dll
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll to /Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/monotouch.dll
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.dll to /Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/System.dll
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Security.dll to /Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/Mono.Security.dll
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll to /Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/System.Core.dll
    Linking SDK only for assembly /Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.exe into /Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app
    MONO_PATH=/Users/yvanjanssens/Downloads/MT_SampleAdMob\ 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app /Developer/MonoTouch/usr/bin/arm-darwin-mono –debug –aot=full,static,asmonly,nodebug,iphone-abi,outfile=/var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/monotouch.dll.s “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/monotouch.dll”
    MONO_PATH=/Users/yvanjanssens/Downloads/MT_SampleAdMob\ 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app /Developer/MonoTouch/usr/bin/arm-darwin-mono –debug –aot=full,static,asmonly,nodebug,iphone-abi,outfile=/var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/System.dll.s “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/System.dll”
    MONO_PATH=/Users/yvanjanssens/Downloads/MT_SampleAdMob\ 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app /Developer/MonoTouch/usr/bin/arm-darwin-mono –debug –aot=full,static,asmonly,soft-debug,iphone-abi,outfile=/var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/MT_SampleAdMob.exe.s “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/MT_SampleAdMob.exe”
    MONO_PATH=/Users/yvanjanssens/Downloads/MT_SampleAdMob\ 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app /Developer/MonoTouch/usr/bin/arm-darwin-mono –debug –aot=full,static,asmonly,nodebug,iphone-abi,outfile=/var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/mscorlib.dll.s “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/mscorlib.dll”
    MONO_PATH=/Users/yvanjanssens/Downloads/MT_SampleAdMob\ 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app /Developer/MonoTouch/usr/bin/arm-darwin-mono –debug –aot=full,static,asmonly,nodebug,iphone-abi,outfile=/var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/System.Core.dll.s “/Users/yvanjanssens/Downloads/MT_SampleAdMob 3/MT_SampleAdMob/bin/iPhone/Debug/MT_SampleAdMob.app/System.Core.dll”
    Generated /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/main.m
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -gdwarf-2 -miphoneos-version-min=3.0 -std=c99 -I/Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -c /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/monotouch.dll.s -o /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/monotouch.dll.o -DDEBUG
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -gdwarf-2 -miphoneos-version-min=3.0 -std=c99 -I/Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -c /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/System.dll.s -o /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/System.dll.o -DDEBUG
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -gdwarf-2 -miphoneos-version-min=3.0 -std=c99 -I/Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -c /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/MT_SampleAdMob.exe.s -o /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/MT_SampleAdMob.exe.o -DDEBUG
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -gdwarf-2 -miphoneos-version-min=3.0 -std=c99 -I/Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -c /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/mscorlib.dll.s -o /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/mscorlib.dll.o -DDEBUG
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -gdwarf-2 -miphoneos-version-min=3.0 -std=c99 -I/Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -c /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/System.Core.dll.s -o /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/System.Core.dll.o -DDEBUG
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -gdwarf-2 -miphoneos-version-min=3.0 -std=c99 -I/Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -c /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/main.m -o /var/folders/HM/HM9GVi0EFG8jR6D3RxiMPk+++TI/-Tmp-/tmp6a51fbf.tmp/main.o -DDEBUG

    Hope this get solved soon…

  36. guivho Says:

    Thanx for the MT_SampleAdMob project. We really needed some clever guy to shine his light on this prob :)

    When I try to build it (Debug for the Simulator, latest xcode and monotouch), the main compilation goes without probs, but the ‘Compiling to native code’ phase hangs without any output. When stopping it, it rightfully complains ‘mtouch failed wit no output (137)’

    Any suggestions?

    TIA, Guivho.

    The build output is as follows:

    Building: MT_SampleAdMob (Debug|iPhoneSimulator)

    Performing main compilation…
    /Developer/MonoTouch/usr/bin/smcs /noconfig “/out:/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.exe” “/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.dll” “/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll” “/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll” “/r:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll” /nologo /warn:4 /debug:+ /debug:full /optimize- /codepage:utf8 “/define:DEBUG” /t:exe “/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/Main.cs” “/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/admob/AdMobDelegate.cs” “/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/admob/AdMobView.cs” “/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/Controller/AppController.cs” “/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/Controller/MainViewController.cs”
    Build complete — 0 errors, 0 warnings

    Compiling to native code
    /Developer/MonoTouch/usr/bin/mtouch -v –nomanifest –nosign -sim “/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.app” -r=”/Developer/MonoTouch/usr/lib/mono/2.1/System.dll” -r=”/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll” -r=”/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll” -r=”/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll” -debug -nolink -sdk=”4.1″ -targetver=”4.0″ -gcc_flags ” -framework AudioToolbox -framework MediaPlayer -framework CoreLocation -framework CoreGraphics -framework QuartzCore -framework AddressBook -framework MessageUI -L/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/admob -lAdMobSimulator3_0 -ObjC” “/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.exe”
    Framework is: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk
    Copied /Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.exe to /Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.app/MT_SampleAdMob.exe
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll to /Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.app/mscorlib.dll
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll to /Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.app/monotouch.dll
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.dll to /Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.app/System.dll
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Security.dll to /Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.app/Mono.Security.dll
    Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll to /Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/bin/iPhoneSimulator/Debug/MT_SampleAdMob.app/System.Core.dll
    Generated /var/folders/hF/hF42FIdhEUmY1y-pGRsu1k+++TI/-Tmp-/tmp1a521210.tmp/main.m
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -gdwarf-2 -fobjc-legacy-dispatch -fobjc-abi-version=2 -miphoneos-version-min=4.1 -std=c99 -I/Developer/MonoTouch/SDKs/MonoTouch.iphonesimulator4.1.sdk/usr/include -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -c /var/folders/hF/hF42FIdhEUmY1y-pGRsu1k+++TI/-Tmp-/tmp1a521210.tmp/main.m -o /var/folders/hF/hF42FIdhEUmY1y-pGRsu1k+++TI/-Tmp-/tmp1a521210.tmp/main.o -DDEBUG
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -gdwarf-2 -fobjc-legacy-dispatch -fobjc-abi-version=2 -miphoneos-version-min=4.1 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk /var/folders/hF/hF42FIdhEUmY1y-pGRsu1k+++TI/-Tmp-/tmp1a521210.tmp/main.o -o /var/folders/hF/hF42FIdhEUmY1y-pGRsu1k+++TI/-Tmp-/tmp1a521210.tmp/MT_SampleAdMob -framework CFNetwork -framework AVFoundation -framework CoreFoundation -framework CoreMedia -framework CoreTelephony -framework EventKit -framework Foundation -framework OpenGLES -framework QuartzCore -framework CoreGraphics -framework CoreLocation -framework GameKit -framework MapKit -framework MediaPlayer -framework MessageUI -framework UIKit -framework StoreKit -framework CoreMotion -framework AddressBook -framework AddressBookUI -framework iAd -framework AudioToolbox -framework SystemConfiguration -framework ExternalAccessory -framework QuickLook -framework EventKitUI -framework AudioToolbox -lz -u _catch_exception_raise -u _CreateZStream -u _CloseZStream -u _Flush -u _ReadZStream -u _WriteZStream -liconv -lmono -lmonotouch -L/Developer/MonoTouch/SDKs/MonoTouch.iphonesimulator4.1.sdk/usr/lib -framework AudioToolbox -framework MediaPlayer -framework CoreLocation -framework CoreGraphics -framework QuartzCore -framework AddressBook -framework MessageUI -L/Users/guivho/Mono/MT_SampleAdMob/MT_SampleAdMob/admob -lAdMobSimulator3_0 -ObjC
    Build cancelled

    ———————- Done ———————-

    Build cancelled
    Build: 1 error, 0 warnings

  37. twestley Says:

    Here are two possible problems for you to look at:

    1) You are targeting iOS 4.1 but using a 3.0 AdMob library. Go to the AdMob dev wiki and see if there is an AdMob library for iOS 4,0 or later.

    2) You’re using the AdMob iPhone simulator library. If you’re building for iPhone, you want to use the iPhone library, not the simulator library.

  38. guivho Says:

    Hi Twestley,

    I am now building a debug version for the simulator with SDK version 4.1 and targeting minimum OS version 3.0. The extra arguments value I am using is

    -gcc_flags “-framework QuartzCore -framework AddressBook -framework CoreLocation -L${ProjectDir}/admob -lAdMobSimulator3_0 –force_load ${ProjectDir}/admob/libAdMobSimulator3_0.a”

    I use the –force_load option instead of the -ObjC option based upon the wiki at http://wiki.monotouch.net/HowTo/Interop/Consuming_3rd_Party_ObjC_Libraries. With the -ObjC option, the native phase just hangs.

    I have now 3 libraries I could use. The three are
    1) the original libAdMobSimulator3_0.a that is in the http://www.sabonrai.com/downloads/MT_SampleAdMob.zip file, and the
    2) libAdMob.a and
    3) libAdMobNoThumb.a libraries from the latest admob_iphone_sdk_20100908.tar.gz.

    All three libraries build and give the same test results (cfr later). I do not know which one I should use and why.

    Anyhow, the app crashes at the first access of the AdMobView class. It does not print any message, it just crashes.

    I have added some extra WriteLine calls, and moved the display of the AdMob.version before the creation of the advertView. Requesting the version or an advertView both cause the thing to crash without any message. I have read in http://stackoverflow.com/questions/1490155/requestadwithdelegate-crashing-because-im-in-gseventreceiverunloopmode that the runloopm ode would be important, so I have entered a WriteLine statement to display it before I access the AdMobView. The output of the app is as follows:

    TextView ready
    Configuring AdvertView
    adMobDelegate.AdReceived callback succesfully setup
    adMobDelegate.AdBackgroundColor setup
    Runloop=MonoTouch.Foundation.NSRunLoop mode=GSEventReceiveRunLoopMode
    About to write the AdMobView.version value!

    And that’s it…

    Again, Twestley, any help would be highly appreciated!

    TIA,

    Guivho

  39. molly Says:

    I tried to do some further investigation and detected a surprising behaviour:

    I just changed the Version method in the AdMobView class as follows:.

    static int count = 0;
    public static string Version
    {
    [Export("version")]
    get
    {
    Class adMobViewClass = new Class (“AdMobView”);
    Console.WriteLine
    (“Version ”
    + ++versioncount
    + ” class=”+adMobViewClass);
    IntPtr ip = Messaging.IntPtr_objc_msgSend
    (adMobViewClass.Handle, selVersion.Handle);
    return NSString.FromHandle(ip);
    }
    }

    I then changed the ViewDidLoad method in the MainViewController.cs as follows:

    public override void ViewDidLoad ()
    {
    base.ViewDidLoad ();
    ConfigureTextView ();
    WriteLine
    (String.Format
    (“AdMobView Version is {0}”,
    AdMobView.Version));
    }

    so all it does is to write the version.

    To my surprise, it does this some 14540 times, at what point the app just stops. I do not understand why this is called so many times. The last 5 lines are:

    Version 14536 class=MonoTouch.ObjCRuntime.Class
    Version 14537 class=MonoTouch.ObjCRuntime.Class
    Version 14538 class=MonoTouch.ObjCRuntime.Class
    Version 14539 class=MonoTouch.ObjCRuntime.Class
    Version 14540 class=MonoTouch.ObjCRuntime.Class

    I don’t know if this might be helpful, but at least, it did not expect this behavioiur and it is a symptom of what is going wrong.

    Molly.

  40. molly Says:

    We’ve put up two topics about this at stackoverflow to get some more visibility:
    http://stackoverflow.com/questions/4260577/binding-objectivec-class-to-c-problem
    and
    http://stackoverflow.com/questions/4269926/who-uses-admob-in-a-monotouch-iphone-app
    We have mentioned this blog in both topics.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 37 other followers

%d bloggers like this: