2
votes

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.

Below is the description I made

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

I'm trying to bind the Bardecode library from Softek (http://www.bardecode.com/). Here's (part of) their header file

#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

And here's how I try to use the generated binding

    Bardecode bardecode = new Bardecode();
    bardecode.DidFinish += BardecodeDidFinish;
    bardecode.ScanBarcodeFromViewFinder();

And the callback routine:

    private void BardecodeDidFinish(object sender, EventArgs args)
    {
    }

Although the documentation states that a class with name BardecodeDidFinishEventArgs should be generated, it is not.

Here's what MonoDevelop generated after adding the library file.

using System;
using MonoTouch.ObjCRuntime;

[assembly: LinkWith ("libbardecode.a", LinkTarget.ArmV6 | LinkTarget.ArmV7 | LinkTarget.Simulator, ForceLoad = true)]

Regards Paul

1

1 Answers

2
votes

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.

Do you have a crash report for these crashes? Do you know exactly which line of managed code causes the crash?

Although the documentation states that a class with name BardecodeDidFinishEventArgs should be generated, it is not.

Bindings projects don't generate source code you'll see, the generated source code is automatically deleted after compiling them. You can run Reflector on the bindings library to see exactly what is generated.