Print on iMZ320 with iOS SDK (Objective C)



I'm developing an iPhone application, it has print feature. I use iZM320, I did test with Zebra SDK and it worked fine.

But with I try with my app, after send print cmd, the bluetooth light on the printer flashed about 3-4 times, but no paper was printed.

I attached my source code, I hope anybody can help me.

1. Printing string

^XA^PON^PW384^MNN^LL1260^LH0,0^FX ---1^FO40,40^GB304,100,3^FS^CF8,40^FO80,60^FDVIOLATION^FS^CF0,10^FO60,110^FB264,1,1,C,0^FDYOU ARE IN VIOLATION OF PARKING RULES/LAWS^FS^FX ---2 ^FO80,160^FDCITATION ID#^FS ^FO240,160^FDOTHER ID#^FS^FO40,180^FB140,1,1,C,0^FDID 1606^FS^FO192,180^FB140,1,1,C,0^FDOT 1786^FS^FO192,150^GB1,50,1^FS ^FO20,210^GB344,1,1^FS^FX ---3 ^FO80,230^FB224,1,1,C,0^FDSPECIFIC VIOLATION(S)^FS^FO30,260^FDMORE THAN 12" FROM CURB^FS^FO30,290^FDASSIGNED PARKING SPACE^FS^FO30,320^FDBLOCKING GARAGE^FS^FO30,350^FDEXPIRED TAGS^FS^FO30,380^FDEXCESSIVE USE OF GUEST PARKING^FS^FO30,410^FDEXPIRED REGISTRATION^FS^FO20,440^GB344,1,1^FS^FX ---4 ^FO80,460^FB224,1,1,C,0^FDVEHICLE INFORMATION^FS^FO110,490^FDMAKE:   Make^FS^FO109,520^FDMODE:   Model^FS^FO107,550^FDPLATE:   Plate^FS^FO103,580^FDCOLOR:   Color^FS^FO106,610^FDSTATE:   State^FS^FO78,640^FDEXPIRATION:   Expire^FS^FO20,670^GB344,1,1^FS^FX ---5 ^FO80,690^FB224,1,1,C,0^FDPROPERTY^FS^FO70,720^FD4 Doan tests^FS^FO20,750^GB344,1,1^FS^FX ---6 ^FO80,770^FB224,1,1,C,0^FDLOCATION / COMMENTS^FS^FO30,800^FB324,2,1,B,0^FDThis is note content, we need to notice this issues I commented here.

Thanks.^FS^FO20,830^GB344,1,1^FS^FX ---7 ^FO80,850^FB224,1,1,C,0^FDVEHICLE STATUS^FS^FO70,880^FDPAY FINE SHOWN IN COMMENT BOX^FS^FO20,910^GB344,1,1^FS^FX ---8 ^FO80,930^FB224,1,1,C,0^FDTOW INFORMATION^FS^FO63,960^FDTOW COMPANY:  Tow Company^FS^FO68,990^FDTOW PHONE #:   Tow Phone^FS^FO90,1020^FDCLEARED:   Operator^FS^FO94,1050^FDAGENCY:   Agency^FS^FX ---9 ^FO20,1070^GB344,80,1^FS^FO80,1090^FB224,1,1,C,0^FDDATE / TIME OF VIOLATION^FS^FO80,1120^FB224,1,1,C,0^FD2015-08-08 11:31:54^FS^FX ---10 ^FO88,1170^FDOFFICER:   DOAN^FS^FO143,1200^FDDPS TESTING ACCOUNT^FS^FO143,1230^FD(949) 342-4334^FS^XZ


2. Print Button click

- (IBAction)buttonClick:(id)sender {

          if (_printString) {

                [NSThread detachNewThreadSelector:@selector(performReportPrinting) toTarget:self withObject:nil];




3. performReportPrinting function

- (void)performReportPrinting


    BOOL completed = NO;

    @autoreleasepool {

        _lblStatus.text = [NSString stringWithFormat:@"Status: Connect printer:%@",_printerSerialNumber];

        id<ZebraPrinterConnection, NSObject> connection = [[MfiBtPrinterConnection alloc] initWithSerialNumber:_printerSerialNumber];

        BOOL didOpen = [connection open];

        if(didOpen == YES) {

            NSError *error = nil;

            id<ZebraPrinter,NSObject> printer = [ZebraPrinterFactory getInstance:connection error:&error];


            if(printer != nil) {

                PrinterLanguage language = [printer getPrinterControlLanguage];

                if(language == PRINTER_LANGUAGE_CPCL) {

                    _lblStatus.text = @"Status: No support CPCL printers";

                } else {

                    _lblStatus.text = @"Status: Printing...";

                    [self printReportAsOneJobUsingNSString:printer withString:[_printString mutableCopy]];

                    _lblStatus.text = @"Status: Print completed.";


                    completed = YES;



            } else {

                _lblStatus.text = [NSString stringWithFormat:@"No Printer Language: %@", _printerSerialNumber];




        } else {

            _lblStatus.text = [NSString stringWithFormat:@"Status: Not connect printer:%@",_printerSerialNumber];



        [connection close];

        _btnPrint.enabled = YES;



    if (completed) {

        [self hide];




4. printReportAsOneJobUsingNSString function

I copy this function from Zebra SDK Demo app.

-(BOOL)printReportAsOneJobUsingNSString:(id<NSObject,ZebraPrinter>)printer withString:(NSMutableString*)fullLabel {


     Sending large amounts of data in a single write command can overflow the NSStream buffers which are the underlying mechanism used by the SDK to communicate with the printers.

     This method shows one way to break up large strings into smaller chunks to send to the printer


    NSError *error = nil;


    long blockSize = 256;

    long totalSize = fullLabel.length;

    long bytesRemaining = totalSize;


    while (bytesRemaining > 0) {

        long bytesToSend = MIN(blockSize, bytesRemaining);

        NSRange range = NSMakeRange(0, bytesToSend);


        NSString *partialLabel = [fullLabel substringWithRange:range];


        [[printer getToolsUtil] sendCommand:partialLabel error:&error];


        bytesRemaining -= bytesToSend;


        [fullLabel deleteCharactersInRange:range];




    return (error == nil);



Please help me, I did face this issue for 2 weeks.


Thanks a lot!