【问题标题】:Xamarin AppDelegate does not implement UIApplicationDelegate when initializing good DynamicsXamarin AppDelegate 在初始化好的 Dynamics 时未实现 UIApplicationDelegate
【发布时间】:2012-10-19 10:24:17
【问题描述】:

我正在尝试为 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 传递到本机库有关。

有什么想法吗?

谢谢

【问题讨论】:

  • 您是否尝试过将"AppDelegate" 传递给该方法的字符串重载? (使用[Register] 属性在您的AppDelegate 上使用的名称,这通常只是"AppDelegate"
  • 覆盖AppDelegate 上的所有方法,也许这个库希望你实现某个回调而你没有实现
  • 我已经实现了在示例 xcode 项目中实现的所有功能。

标签: ios xamarin.ios xamarin good-dynamics


【解决方案1】:

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

【讨论】:

  • 我不知道它是否真的有效,正如你所说,这是一个老问题,我真的没有任何方法可以验证。但干得好。会接受这个!
猜你喜欢
  • 2021-09-25
  • 2023-03-14
  • 1970-01-01
  • 2013-07-04
  • 2023-03-20
  • 2018-12-21
  • 1970-01-01
  • 1970-01-01
  • 2017-02-01
相关资源
最近更新 更多