1

我正在尝试为 Good Dynamics 创建一个绑定,以便它可以在 Xamarin 中使用。我终于把它弄到了可以构建的地步,但是在尝试初始化 Good Dynamics 时会发生以下错误;

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

Main.cs 的第 20 行是

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

我尝试让 AppDelegate 扩展 UIApplicationDelegate 并扩展 GDiOSDelegate,它具有 UIApplicationDelegate 的基本类型,结果相同。

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; }
    }
}

代码位于https://github.com/garethrhughes/GDTest

我认为问题可能与将 monotouch AppDelegate 传递到本机库有关。

有任何想法吗?

谢谢

4

1 回答 1

2

我知道这是一个旧线程,但我和一位同事刚刚使用 GOOD 的 SDK (v1.8.x) 的较新版本完成了这个过程,并且能够让它工作。我们在这里发布了一篇关于它的文章,其中还包含一个示例项目的链接。

于 2014-10-10T16:34:26.430 回答