2

我在 Monotouch 中包装了一个 Objective-c 库。问题是,在使用 btouch 生成 DLL 后,当我尝试在示例应用程序中使用 DLL 中的一些类时,大多数类的classHandle返回0x0。我调试了这个问题,发现Messaging 类使用的class_ptr也返回 0x0。

我检查了构建输出(在 MonoDevelop 中构建项目之后),它看起来链接了我的本机库,但我仍然得到同样的错误。构建输出包括在下面。问题是我有一个协议 GDiOSDelegate 定义如下

@protocol GDiOSDelegate
@required

- (void)handleEvent:(GDAppEvent*)anEvent;
@end

该协议由 GDiOS 类(我也包括在内)使用,但它还需要与 UIApplicationDelegate 交互,因为 HandleEvent 方法需要与 UIApplicationDelegate 中的某些对象进行通信(在 Objective-C 中使用该库的等效示例代码有一个类答:NSObject)。

我的方法是在 GDiOSDelegate 的绑定中,我将 typeof 属性设置为 UIApplicationDelegate 而不是 NSObject

[BaseType(typeof(UIApplicationDelegate))]

所以,回到我在使用 Monotouch 绑定 DLL 中的一些方法后遇到的错误,它抛出了一个异常,说 AppDelegate 没有实现 UIApplicationDelegate。

[Register ("AppDelegate")]
public partial class AppDelegate : GDiOSDelegate
{...}

即使我将 UIApplicationDelegate 而不是 GDiOSDelegate 作为基类,也会发生这种情况。

构建输出:

Building: GDBinding (Debug)

Build started 7/16/2012 9:03:46 AM.
__________________________________________________
Project "/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj" (Build   target(s)):

Target CreateGeneratedSourcesDir:
    Created directory "obj/Debug/ios/"

Target PrepareForBuild:
    Configuration: Debug Platform: AnyCPU

Target CopyFilesMarkedCopyLocal:
    Copying file from '/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll' to '/Users/thabetkacem/Projects/GDBinding/GDBinding/bin/Debug/GDBinding.dll'

Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.

Target GenerateBindings:
    Tool /Developer/MonoTouch/usr/bin/btouch execution started with arguments: /d:DEBUG GDBinding.cs /s:StructsAndEnums.cs /tmpdir:obj/Debug/ios/  /sourceonly:obj/Debug/ios//sources.list 
GDBinding.cs(642,22): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?

Target CoreCompile:
    Tool /Developer/MonoTouch/usr/bin/smcs execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/Debug/GDBinding.dll /resource:libGD.a libGD.linkwith.cs Extra.cs AssemblyInfo.cs StructsAndEnums.cs obj/Debug/ios/ObjCRuntime/Messaging.g.cs obj/Debug/ios/GDBinding/GDCReadStream.g.cs obj/Debug/ios/GDBinding/GDCWriteStream.g.cs obj/Debug/ios/GDBinding/GDPersistentStoreCoordinator.g.cs obj/Debug/ios/GDBinding/GDFileSystem.g.cs obj/Debug/ios/GDBinding/GDDirectByteBuffer.g.cs obj/Debug/ios/GDBinding/GDSocketDelegate.g.cs obj/Debug/ios/GDBinding/GDSocket.g.cs obj/Debug/ios/GDBinding/GDHttpRequestDelegate.g.cs obj/Debug/ios/GDBinding/GDHttpRequest.g.cs obj/Debug/ios/GDBinding/NSURLCache.g.cs obj/Debug/ios/GDBinding/GDURLLoadingSystem.g.cs obj/Debug/ios/GDBinding/GDCacheController.g.cs obj/Debug/ios/GDBinding/GDPushConnectionDelegate.g.cs obj/Debug/ios/GDBinding/GDPushConnection.g.cs obj/Debug/ios/GDBinding/GDPushChannelDelegate.g.cs obj/Debug/ios/GDBinding/GDPushChannel.g.cs obj/Debug/ios/GDBinding/GDSecureDocs.g.cs obj/Debug/ios/GDBinding/GDAppEvent.g.cs obj/Debug/ios/GDBinding/GDiOSDelegate.g.cs obj/Debug/ios/GDBinding/GDiOS.g.cs obj/Debug/ios/GDBinding/NSMutableURLRequest.g.cs /target:library /unsafe+ /define:DEBUG /reference:/Developer/MonoTouch/usr/lib/mono/2.1/System.dll /reference:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll /reference:../../../Desktop/GDExtended/GDBinding.dll /reference:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll /reference:/Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll /warn:4
obj/Debug/ios/GDBinding/GDSocket.g.cs(273,53): warning CS0436: The type   `GDBinding.GDSocketDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(541,58): warning CS0436: The type `GDBinding.GDHttpRequestDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(180,61): warning CS0436: The type `GDBinding.GDPushConnectionDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(175,58): warning CS0436: The type `GDBinding.GDPushChannelDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDiOS.g.cs(393,50): warning CS0436: The type `GDBinding.GDiOSDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(53,134): warning CS0436: The type `GDBinding.GDFileStat' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(159,31): warning CS0436: The type `GDBinding.GDCReadStream' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(181,31): warning CS0436: The type `GDBinding.GDCWriteStream' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDDirectByteBuffer.g.cs(139,46): warning CS0108: `GDBinding.GDDirectByteBuffer.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDSocket.g.cs(177,32): warning CS0436: The type `GDBinding.GDDirectByteBuffer' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(377,46): warning CS0108: `GDBinding.GDHttpRequest.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(449,32): warning CS0436: The type `GDBinding.GDHttpRequest_state_t' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/NSURLCache.g.cs(79,57): warning CS0436: The type `GDBinding.NSURLCache' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(84,31): warning CS0436: The type `GDBinding.GDPushConnection' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(148,46): warning CS0108: `GDBinding.GDPushChannel.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDSecureDocs.g.cs(101,85): warning CS0436: The type `GDBinding.SendFileSuccessBlock' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(82,32): warning CS0436: The type `GDBinding.GDAppResultCode' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(102,32): warning CS0436: The type `GDBinding.GDAppEventType' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDiOSDelegate.g.cs(76,51): warning CS0436: The type `GDBinding.GDAppEvent' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDiOS.g.cs(139,36): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?
obj/Debug/ios/GDBinding/GDiOS.g.cs(163,31): warning CS0436: The type `GDBinding.GDiOS' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDiOS.g.cs(281,94): warning CS0436: The type `GDBinding.GDUIColorTheme' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/NSMutableURLRequest.g.cs(83,67): warning CS0436: The type `GDBinding.NSMutableURLRequest' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(44,84): warning CS0436: The type `GDBinding.Messaging' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)

Target DeployOutputFiles:
    Copying file from '/Users/thabetkacem/Projects/GDBinding/GDBinding/obj/Debug/GDBinding.dll.mdb' to '/Users/thabetkacem/Projects/GDBinding/GDBinding/bin/Debug/GDBinding.dll.mdb'
    Copying file from '/Users/thabetkacem/Projects/GDBinding/GDBinding/obj/Debug/GDBinding.dll' to '/Users/thabetkacem/Projects/GDBinding/GDBinding/bin/Debug/GDBinding.dll'
Done building project "/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj".

Build succeeded.

Warnings:

/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj (Build) ->    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Xamarin.ObjcBinding.CSharp.targets 
(GenerateBindings target) ->

GDBinding.cs(642,22): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?

/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj (Build) ->
/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/mono/4.0/Microsoft.CSharp.Targets  (CoreCompile target) ->

obj/Debug/ios/GDBinding/GDSocket.g.cs(273,53): warning CS0436: The type `GDBinding.GDSocketDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(541,58): warning CS0436: The type `GDBinding.GDHttpRequestDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(180,61): warning CS0436: The type `GDBinding.GDPushConnectionDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(175,58): warning CS0436: The type `GDBinding.GDPushChannelDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDiOS.g.cs(393,50): warning CS0436: The type `GDBinding.GDiOSDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(53,134): warning CS0436: The type `GDBinding.GDFileStat' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(159,31): warning CS0436: The type `GDBinding.GDCReadStream' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(181,31): warning CS0436: The type `GDBinding.GDCWriteStream' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDDirectByteBuffer.g.cs(139,46): warning CS0108: `GDBinding.GDDirectByteBuffer.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
obj/Debug/ios/GDBinding/GDSocket.g.cs(177,32): warning CS0436: The type `GDBinding.GDDirectByteBuffer' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(377,46): warning CS0108: `GDBinding.GDHttpRequest.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(449,32): warning CS0436: The type `GDBinding.GDHttpRequest_state_t' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/NSURLCache.g.cs(79,57): warning CS0436: The type `GDBinding.NSURLCache' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(84,31): warning CS0436: The type `GDBinding.GDPushConnection' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(148,46): warning CS0108: `GDBinding.GDPushChannel.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
obj/Debug/ios/GDBinding/GDSecureDocs.g.cs(101,85): warning CS0436: The type `GDBinding.SendFileSuccessBlock' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(82,32): warning CS0436: The type `GDBinding.GDAppResultCode' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(102,32): warning CS0436: The type `GDBinding.GDAppEventType' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDiOSDelegate.g.cs(76,51): warning CS0436: The type `GDBinding.GDAppEvent' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDiOS.g.cs(139,36): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?
obj/Debug/ios/GDBinding/GDiOS.g.cs(163,31): warning CS0436: The type `GDBinding.GDiOS' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDiOS.g.cs(281,94): warning CS0436: The type `GDBinding.GDUIColorTheme' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/NSMutableURLRequest.g.cs(83,67): warning CS0436: The type `GDBinding.NSMutableURLRequest' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(44,84): warning CS0436: The type `GDBinding.Messaging' conflicts with the imported type of same name'. Ignoring the imported type definition

 25 Warning(s)
 0 Error(s)

Time Elapsed 00:00:05.0845450

---------------------- Done ----------------------

Build: 0 errors, 25 warnings


Any help would be greatly appreciated.
4

1 回答 1

0

如果您不手动或(更好地)使用[LinkWith]属性将本机库(您绑定的)与您的应用程序链接,则可能会发生这种情况。

在这种情况下,选择器消息将不会到达本代码并将返回null(这将显示句柄(实例或类)为0x0.

要确认这一点,请查看您的构建输出(在 MonoDevelop 内)并查看您libX.a是否链接到您的应用程序。

还可以在模拟器(i386)和设备(armv6 和/或 armv7)上尝试此操作,因为您的本机库架构可能不可用(在您的.a.

于 2012-07-15T15:15:05.283 回答