0

I have created an Objective-C library with one function in. The header is defined as:

@interface StarIOFunctions : NSObject {

}

+ (NSMutableData *) GetDataToSendToPrinter:(UIImage *)image maxWidth:(int)maxWidth drawerKick:(BOOL)drawerKick compressionEnable:(BOOL)compressionEnable;

@end

I have created a binding for it:

[BaseType (typeof (NSObject))]
interface StarIOFunctions {
    [Static, Export ("GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:")]
    NSMutableData GetDataToSendToPrinter (UIImage image, int maxWidth, bool kickDrawer, bool compressionEnable);
}

And the call it via:

        image = UIImage.FromBundle("barcode.png");
        NSMutableData commandsToPrint = StarIOFunctions.GetDataToSendToPrinter(image,576,true,true);

All works fine in the simulator, but when I release to device the app crashes when it tries to call the function with the following error:

2014-09-30 19:10:52.776 DemoApp[280:26219] +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x14e787c
2014-09-30 19:11:14.697 DemoApp[280:26219] Unhandled managed exception: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x14e787c (MonoTouch.Foundation.MonoTouchException)
(null)

I have built the Objective-C library for device, and included that .a file in my bindings. My linkwith file is:

[assembly: LinkWith ("libStarIOFunctions.a", LinkTarget.ArmV7, ForceLoad = true)]

Why is it crashing on the iPad but not the simulator?

Edit: Build output is at http://pastebin.com/mtVgHA6L

Edit 2: I have just LIPO'ed my two version today. So my linkwith is now:

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

And still works fine in simulator and crashes with the following on device:

2014-09-30 20:20:50.519 DemoApp[313:35575] +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x140887c
2014-09-30 20:20:50.521 DemoApp[313:35575] MonoTouch: Received unhandled ObjectiveC exception: NSInvalidArgumentException +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x140887c
libc++abi.dylib: terminate_handler unexpectedly threw an exception
Joseph
  • 2,706
  • 6
  • 42
  • 80
  • There must be other differences between your simulator and device builds, otherwise `LinkTarget.ArmV7` would **not** work on the simulator. A full build log (with `-v -v -v -v` for maximum verbosity) might help us see what went wrong. – poupou Sep 30 '14 at 18:44
  • @poupou I have edited with a link to the build output. I did have LinkTarget.Simulator originally, when I was using the sim, but recompiled my binding for the device. – Joseph Sep 30 '14 at 18:56
  • Please do a "Clean" before (or use "Rebuild"), otherwise the build will be using cached (pre-built) binaries - and we won't be able to see how things were built. – poupou Sep 30 '14 at 20:04
  • @poupou Just cleaned and then built. http://pastebin.com/s3TSmKc3 Thanks. – Joseph Sep 30 '14 at 20:11
  • 1
    Shot in the dark here, make sure that the casing on `libStarIOFunctions.a` matches the filename. IOs devices are case sensitive, IOs simulators are not: http://stackoverflow.com/a/1715795/1099111 – matthewrdev Sep 30 '14 at 22:34
  • Doesn't appear to be that unfortunately. This is driving me crazy!! – Joseph Sep 30 '14 at 22:37
  • Can you run the `nm` tool on the libStarIOFunctions.a library and pastebin the entire output (`nm /path/to/libStarIOFunctions.a`)? – Rolf Bjarne Kvinge Oct 01 '14 at 07:14
  • Sure - http://pastebin.com/RBn6HTiX Thanks – Joseph Oct 01 '14 at 10:13
  • @RolfBjarneKvinge What should I be looking for in the build logs/RM? – Joseph Oct 02 '14 at 09:13
  • Can you do this as well: `nm -arch all /path/to/libStarIOFunctions.a` (this will show if the symbol actually exists for device architectures in the library). You're looking for the exact selector '+[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]' – Rolf Bjarne Kvinge Oct 02 '14 at 12:53
  • @RolfBjarneKvinge http://pastebin.com/uqjMyqFJ – Joseph Oct 02 '14 at 12:57
  • Also, I've done a bit more testing and when I use the library in an Objective-C project I have the same issue. So it's not a Xamarin bindings problem. – Joseph Oct 02 '14 at 12:58
  • OK, thanks for letting us know. – Rolf Bjarne Kvinge Oct 02 '14 at 16:35

0 Answers0