我正在尝试绑定(bind)一个 Xcode 库,并且正在为如何做到这一点而绞尽脑汁。当我尝试访问任何事件或方法时,应用程序会严重崩溃。
下面是我的描述
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
namespace BardecodeBinding
{
[BaseType (typeof(NSObject),
Delegates= new string [] {"WeakDelegate"},
Events = new Type [] { typeof(BardecodeDelegate) })]
interface Bardecode
{
[Export ("delegate", ArgumentSemantic.Assign)]
[NullAllowed]
NSObject WeakDelegate { get; set; }
[Wrap ("WeakDelegate")]
[NullAllowed]
BardecodeDelegate Delegate { get; set; }
[Export("ScanBarcodeFromViewFinder")]
void ScanBarcodeFromViewFinder();
}
[BaseType (typeof(NSObject))]
interface BardecodeDelegate
{
[Export ("didfinish:sender:notification:"), EventArgs("BardecodeDidFinish")]
void DidFinish (Bardecode sender, NSNotification notification);
}
}
我正在尝试绑定(bind) Softek (http://www.bardecode.com/) 的 Bardecode 库。这是他们的头文件(部分)
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#include "barcode.h"
#if TARGET_IPHONE_SIMULATOR
@interface Bardecode : NSObject <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
#else
@interface Bardecode : NSObject <UINavigationControllerDelegate, UIImagePickerControllerDelegate, AVCaptureVideoDataOutputSampleBufferDelegate>
#endif
{
...
- (void) ScanBarcodeFromViewFinder;
...
}
@interface NSObject(NSWindowNotifications)
- (void)BardecodeDidFinish:(NSNotification*)notification;
@end
这是我尝试使用生成的绑定(bind)的方法
Bardecode bardecode = new Bardecode();
bardecode.DidFinish += BardecodeDidFinish;
bardecode.ScanBarcodeFromViewFinder();
以及回调例程:
private void BardecodeDidFinish(object sender, EventArgs args)
{
}
尽管文档指出应该生成名为 BardecodeDidFinishEventArgs 的类,但事实并非如此。
这是添加库文件后 MonoDevelop 生成的内容。
using System;
using MonoTouch.ObjCRuntime;
[assembly: LinkWith ("libbardecode.a", LinkTarget.ArmV6 | LinkTarget.ArmV7 | LinkTarget.Simulator, ForceLoad = true)]
问候 保罗
最佳答案
I'm trying to bind a Xcode library and am pulling my hair out on how to do that. The App crashes terribly when I try to access any event or method.
您有这些崩溃的崩溃报告吗?您确切知道哪一行托管代码导致崩溃吗?
Although the documentation states that a class with name BardecodeDidFinishEventArgs should be generated, it is not.
绑定(bind)项目不会生成您将看到的源代码,生成的源代码在编译后会自动删除。您可以在绑定(bind)库上运行 Reflector 以准确查看生成的内容。
关于binding - XCode 库的 Monotouch 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9854665/