1

I am trying to create a binding for Good Dynamics so it can be used in Xamarin. I have finally got it to a point where it will build however when trying to initialize Good Dynamics the following error happens;

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInternalInconsisenter code heretencyException Reason: AppDelegate does not implement UIApplicationDelegate. Check that the class is correct and it conforms to this protocol.
  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend_IntPtr (intptr,intptr,intptr)
  at GDBinding.GDiOS.InitializeWithClassConformingToUIApplicationDelegate (MonoTouch.ObjCRuntime.Class applicationDelegate) [0x00000] in <filename unknown>:0
  at GDTest.Application.Main (System.String[] args) [0x00006] in /Users/gareth/GDTest/GDTest/Main.cs:20

Line 20 of Main.cs is

GDiOS.InitializeWithClassConformingToUIApplicationDelegate(new MonoTouch.ObjCRuntime.Class(typeof(AppDelegate)));

I tried having AppDelegate extend UIApplicationDelegate and also extend GDiOSDelegate which has a base type of UIApplicationDelegate with the same results.

namespace GDBinding
{
    [BaseType (typeof (NSObject), Delegates = new string[] {"WeakDelegate"}, Events = new Type[] {typeof(GDiOSDelegate)})]
    interface GDiOS {

    [Export ("delegate", ArgumentSemantic.Assign)]
    NSObject WeakDelegate { get; set;  }

    [Wrap("WeakDelegate")]
    [NullAllowed]
    GDiOSDelegate Delegate { get; set; }

    //+ (void)initializeWithClassNameConformingToUIApplicationDelegate:(NSString*)applicationDelegate;
    [Static, Export ("initializeWithClassNameConformingToUIApplicationDelegate:")]
    void InitializeWithClassNameConformingToUIApplicationDelegate (string applicationDelegate);

    //+ (void)initialiseWithClassConformingToUIApplicationDelegate:(Class)applicationDelegate;
    [Static, Export ("initializeWithClassConformingToUIApplicationDelegate:")]
    void InitializeWithClassConformingToUIApplicationDelegate (Class applicationDelegate);

    //+ (BOOL)isInitialized;
    [Static, Export ("isInitialized")]
    bool IsInitialized();

    //+ (GDiOS*)sharedInstance;
    [Static, Export ("sharedInstance")]
    GDiOS SharedInstance();

    //- (UIWindow*)getWindow;
    [Export ("getWindow")]
    UIWindow GetWindow();

}

[BaseType(typeof(UIApplicationDelegate))]
interface GDiOSDelegate {
    [Abstract, Export("handleEvent:")]
    void HandleEvent(GDAppEvent anEvent);
}

[BaseType(typeof(NSObject))]
interface GDAppEvent {
    [Export("message")]
    string Message { get; set; }

    [Export("code")]
    GDAppResultCode Code { get; set; }

    [Export("type")]
    GDAppEventType EventType { get; set; }
    }
}

The code is at https://github.com/garethrhughes/GDTest

I think the problem may be something to do with passing the monotouch AppDelegate into the native library.

Any ideas?

Thanks

Gareth
  • 380
  • 3
  • 12
  • Have you tried just passing `"AppDelegate"` to the string overload of that method? (Use the name the `[Register]` attribute is using on your `AppDelegate` this is usually just `"AppDelegate"`) – jonathanpeppers Oct 19 '12 at 12:08
  • 1
    Override all the methods on your `AppDelegate`, perhaps this library is expecting you to have a certain callback implemented and you don't – jonathanpeppers Oct 19 '12 at 14:48
  • I've implemented all the ones that are implemented on the sample xcode project. – Gareth Oct 22 '12 at 07:59

1 Answers1

2

I know this is an old thread, but a colleague and I just went through this process with the newer version of GOOD's SDK (v1.8.x) and were able to get it working. We posted a writeup about it here which contains a link to a sample project as well.

Greg Gammon
  • 66
  • 1
  • 6
  • I have no idea if it actually works, as you said it's an old question and I don't really have any way to verify. But good job gettin it working. Will accept this one! – Gareth Oct 11 '14 at 00:35