调用方法导致创建LLDB目标时出错

时间:2014-09-26 17:44:17

标签: ios objective-c

我正在尝试制作我的第一个Objective-C库。我正在创建一个方法,该方法将接收UIImage并返回NSMutableData。我创建了以下内容:

+ (NSMutableData *)GetDataToSendToPrinter:(UIImage *)image
{

    int maxWidth = 100;
    BOOL drawerKick = YES;
    BOOL compressionEnable = YES;

    RasterDocument *rasterDoc = [[RasterDocument alloc] initWithDefaults:RasSpeed_Medium endOfPageBehaviour:RasPageEndMode_FeedAndFullCut endOfDocumentBahaviour:RasPageEndMode_FeedAndFullCut topMargin:RasTopMargin_Standard pageLength:0 leftMargin:0 rightMargin:0];
    StarBitmap *starbitmap = [[StarBitmap alloc] initWithUIImage:image :maxWidth :false];

    NSMutableData *commandsToPrint = [[NSMutableData alloc] init];
    NSData *shortcommand = [rasterDoc BeginDocumentCommandData];
    [commandsToPrint appendData:shortcommand];

    shortcommand = [starbitmap getImageDataForPrinting:compressionEnable];
    [commandsToPrint appendData:shortcommand];

    shortcommand = [rasterDoc EndDocumentCommandData];
    [commandsToPrint appendData:shortcommand];

    if (drawerKick == YES) {
        [commandsToPrint appendBytes:"\x07"
                              length:sizeof("\x07") - 1];    // KickCashDrawer
    }

    [starbitmap release];
    [rasterDoc release];

    return commandsToPrint;

}

仅出于测试目的,我试图通过按钮点击事件来调用它:

- (IBAction)DevButton_TouchUpInside:(id)sender {


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

//    NSMutableData *commandsToPrint = [[NSMutableData alloc] init];
//    *commandsToPrint=[self GetDataToSendToPrinter:imageToPrint];

    //This is where I call it
    NSMutableData *commandsToPrint = [self GetDataToSendToPrinter:imageToPrint]; 

    int commandSize = (int)[commandsToPrint length];
    unsigned char *dataToSentToPrinter = (unsigned char *)malloc(commandSize);
    [commandsToPrint getBytes:dataToSentToPrinter];

    NSString *portName = @"TCP:10.0.1.4";
    NSString *portSettings = @"Standard";
    NSMutableString *message;

    SMPort *starPort = nil;
    starPort = [SMPort getPort:portName :portSettings :10000];
    [starPort writePort:dataToSentToPrinter :0 :commandSize];
}

但是,点击按钮时,我一直遇到以下崩溃:

Warning: Error creating LLDB target at path '/Users/.../Library/Developer/Xcode/DerivedData/IOS_SDK-cjctcqoxudpegpadjbwitveqtkso/Build/Products/Debug-iphonesimulator/StarIO SDK.app'- using an empty LLDB target which can cause slow memory reads from remote devices.
2014-09-26 18:39:22.588 StarIO SDK[17823:513276] -[IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:]: unrecognized selector sent to instance 0xb366260
2014-09-26 18:39:22.624 StarIO SDK[17823:513276] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:]: unrecognized selector sent to instance 0xb366260'
*** First throw call stack:
(
    0   CoreFoundation                      0x021c4df6 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x01c49a97 objc_exception_throw + 44
    2   CoreFoundation                      0x021cca75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
    3   CoreFoundation                      0x021159c7 ___forwarding___ + 1047
    4   CoreFoundation                      0x0211558e _CF_forwarding_prep_0 + 14
    5   StarIO SDK                          0x000428bb -[IOS_SDKViewControllerRasterMode DevButton_TouchUpInside:] + 107
    6   libobjc.A.dylib                     0x01c5f7cd -[NSObject performSelector:withObject:withObject:] + 84
    7   UIKit                               0x0042179d -[UIApplication sendAction:to:from:forEvent:] + 99
    8   UIKit                               0x0042172f -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
    9   UIKit                               0x00554a16 -[UIControl sendAction:to:forEvent:] + 69
    10  UIKit                               0x00554e33 -[UIControl _sendActionsForEvents:withEvent:] + 598
    11  UIKit                               0x0055409d -[UIControl touchesEnded:withEvent:] + 660
    12  UIKit                               0x00471aba -[UIWindow _sendTouchesForEvent:] + 874
    13  UIKit                               0x00472595 -[UIWindow sendEvent:] + 791
    14  UIKit                               0x00437aa9 -[UIApplication sendEvent:] + 242
    15  UIKit                               0x004478de _UIApplicationHandleEventFromQueueEvent + 20690
    16  UIKit                               0x0041c079 _UIApplicationHandleEventQueue + 2206
    17  CoreFoundation                      0x020e87bf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    18  CoreFoundation                      0x020de2cd __CFRunLoopDoSources0 + 253
    19  CoreFoundation                      0x020dd828 __CFRunLoopRun + 952
    20  CoreFoundation                      0x020dd1ab CFRunLoopRunSpecific + 443
    21  CoreFoundation                      0x020dcfdb CFRunLoopRunInMode + 123
    22  GraphicsServices                    0x03b8c24f GSEventRunModal + 192
    23  GraphicsServices                    0x03b8c08c GSEventRun + 104
    24  UIKit                               0x0041fe16 UIApplicationMain + 1526
    25  StarIO SDK                          0x000027e2 main + 130
    26  libdyld.dylib                       0x036f0ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我认为我遗漏了一些非常基本的东西。它是我创建的第一个Objective-C方法,我只是在构建一个简单的库,然后我可以将其包装在Xamarin绑定中。我哪里错了?

1 个答案:

答案 0 :(得分:0)

您正在从实例方法调用类方法。

+ (NSMutableData *)GetDataToSendToPrinter:(UIImage *)image //Should be called using the class name
- (IBAction)DevButton_TouchUpInside:(id)sender //Should be called using self

我不确定实际编译的方式,你应该得到这样的错误:

  

IOS_SDKViewControllerRasterMode没有可见的@interface声明选择器' GetDataToSendToPrinter:'

根据它吐出的日志,它没有找到函数GetDataToSendToPrinter:。尝试将其称为类方法:

NSMutableData *commandsToPrint = [IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:imageToPrint];