1

I had an issue, which I originally thought was related to my Xamarin bindings. However, I have now made a sample Objective-C app, to remove Xamarin from the equation, and I have the same issue. I have created a library with the following header:

#import <Foundation/Foundation.h>


@interface StarIOFunctions : NSObject {

}

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

@end

And am calling it from my app on the click of a button:

- (IBAction)DevButton_TouchUpInside:(id)sender {

    UIImage *imageToPrint = [UIImage imageNamed:@"image1.png"];

    NSMutableData *commandsToPrint = [StarIOFunctions GetDataToSendToPrinter:imageToPrint maxWidth:100 drawerKick:YES compressionEnable:YES];

}

Everything works fine in the simulator but crashes when I deploy to device with:

2014-10-02 13:34:04.821 StarIO SDK[449:95479] +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x13dddc
2014-10-02 13:34:04.825 StarIO SDK[449:95479] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x13dddc'
*** First throw call stack:
(0x24b2df87 0x324cac77 0x24b33299 0x24b31259 0x24a62d68 0xce213 0x27fdd497 0x27fdd439 0x27fc804d 0x27fdce69 0x27fdcb43 0x27fd6451 0x27faccc5 0x28220513 0x27fab707 0x24af4807 0x24af3c1b 0x24af2299 0x24a3fdb1 0x24a3fbc3 0x2bd74051 0x2800ba31 0x93a3f 0x93040)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Someone has mentioned about the difference between the device and simulator with regards to case, but the filename is deffinitely lower case:

enter image description here

Whats causing my app to crash?

Community
  • 1
  • 1
Joseph
  • 2,706
  • 6
  • 42
  • 80
  • 1
    Try to add an exception breakpoint to see exactly where is the problem – Iulian Popescu Oct 02 '14 at 12:47
  • 1
    Is the `StarIOFunctions` class implemented in a static library that you're linking with the iOS app? If so, you need to add the `-ObjC` linker flag to your project settings. It looks like the method isn't present in the app binary after compiling. – Greg Oct 02 '14 at 13:00
  • Breaks on the line where I call the GetDataToSendToPrinter with 2014-10-02 13:59:37.408 StarIO SDK[473:99349] +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x121ddc (lldb) – Joseph Oct 02 '14 at 13:00
  • @PartiallyFinite Yes, StarIOFunctions is in a library that I have created and then added. How do I add the linker flag? – Joseph Oct 02 '14 at 13:05
  • 1
    @Joseph https://developer.apple.com/library/ios/technotes/iOSStaticLibraries/Articles/configuration.html – Greg Oct 02 '14 at 13:06
  • @PartiallyFinite make your comment an answer. – zaph Oct 02 '14 at 13:17
  • 2
    Independent of your question, you should look at Cocoa naming conventions. Method names should start with a lower case same as variables. Classes and ENUMS should start with uppercase. Coding conventions helps everyone so it's always good to stick to them, it will especially help us understand your code better. – Popeye Oct 02 '14 at 13:24

1 Answers1

0

If your StarIOFunctions class implemented in a static library that you're linking with the iOS app, you need to add the -ObjC linker flag to your project settings. It looks like the method isn't present in the app binary after compiling. This article describes how to add the linker flag.

Greg
  • 9,068
  • 6
  • 49
  • 91
  • Adding that then stops me from building, with Error: clang: error: linker command failed with exit code 1 (use -v to see invocation) – Joseph Oct 02 '14 at 13:29
  • Click on the error in the left pane. It should show you the full error text. – Greg Oct 02 '14 at 13:32
  • I've managed to resolve that issue - it was to do with another library and is now fixed. The app still crashes with the exact same error with -ObjC set. – Joseph Oct 02 '14 at 13:53
  • @Joseph try add `-all_load` as well. Sometimes I find myself having to do that for some reason. – Greg Oct 02 '14 at 13:53
  • Make sure you're setting both these flags on the iOS app target, not the library itself. – Greg Oct 02 '14 at 14:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62343/discussion-between-joseph-and-partiallyfinite). – Joseph Oct 02 '14 at 14:07