Search code examples
iosxamarin.iosxamaringood-dynamics

Xamarin AppDelegate does not implement UIApplicationDelegate when initializing good Dynamics


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


Solution

  • 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.