Problem with printing label

Hi. I have a problem with printing label. I have a WebView app with button (Print), when i push the button (Print), sometimes label is not printed without any errors. I tried to change timeout but this didn’t help.

We have 5 printers QLn 320 with last firmware V68.19.15Z and many iPad with iOS 9.2, 9.1, 8.1. This problem has long. Label 43x25мм and print 5 lines. 1-2Lines - Name, 3Lines - Size, 4Lines - order,date,article, 5Lines - barcode.

I use Zebra SDK and print code is:

 

-(

-(void)printWithGCDWithParameters:(NSDictionary *)parameters {

    //Dispatch this task to the default queue

    buttonhome.enabled = NO;

    buttonSettings.enabled = NO;

    viewPrinting.hidden = NO;

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {

        // Instantiate connection to Zebra Bluetooth accessory

        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

        NSString *serialNumber = [defaults valueForKey:@"selectedPrinterSN"];

        id<ZebraPrinterConnection, NSObject> thePrinterConn = [[MfiBtPrinterConnection alloc] initWithSerialNumber:serialNumber];

        NSInteger timeout = [defaults integerForKey:@"OZTimeout"];

        if (timeout < 30) {

            timeout = 30;

        }

        else if (timeout > 300) {

            timeout = 300;

        }

        [((MfiBtPrinterConnection*)thePrinterConn) setTimeToWaitAfterWriteInMilliseconds:timeout];

        [((MfiBtPrinterConnection*)thePrinterConn) setTimeToWaitAfterReadInMilliseconds:timeout];

      

        BOOL success = [thePrinterConn open];

      

        NSString *size = [parameters valueForKey:@"size"];

        size = [size stringByReplacingOccurrencesOfString:@"<br>" withString:@""];

        size = [size stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

        NSInteger symbolCount = 33;

        NSString *name = [parameters valueForKey:@"title"];

        NSString *name2 = @"";

        if (name.length > symbolCount) {

            name2 = [name substringFromIndex:symbolCount];

            name = [name substringToIndex:symbolCount];

          }

        NSString *zplData = [NSString stringWithFormat:

                              @"^XA^LH25,23^POI^CFT,20,20^CI28^FT5,5^FH^A@N,20,20,E:TT0003M_.TTF^FD%@^FS^FT5,25^FH^A@N,20,20,E:TT0003M_.TTF^FD%@^FS^FT5,45^FH^A@N,20,20,E:TT0003M_.TTF^FD%@%@^FS^FT5,65^FH^A@N,20,20,E:TT0003M_.TTF^FDЗаказ № %@   %@   %@^FS^FO30,80^BY2 ^BCN,50,Y,N,N,A^FD%@^FS^XZ",

                             name, name2, size.length > 0 ? @"Размер: " : @"", size, [parameters valueForKey:@"number"],[parameters valueForKey:@"nowDate"], [parameters valueForKey:@"artPostavshik"], [parameters valueForKey:@"barnumber"]];

      

        NSError *error = nil;

 

        NSMutableData *data = [[zplData dataUsingEncoding:NSUTF8StringEncoding] mutableCopy];

      

        long blockSize = 1024;

        long totalSize = data.length;

        long bytesRemaining = totalSize;

        while (bytesRemaining > 0) {

            long bytesToSend = MIN(blockSize, bytesRemaining);

            NSRange range = NSMakeRange(0, bytesToSend);

          

            NSData *partialLabel = [data subdataWithRange:range];

            [thePrinterConn write:partialLabel error:&error];

          

            bytesRemaining -= bytesToSend;

          

            [data replaceBytesInRange:range withBytes:NULL length:0];

            if (error) {

                break;

            }

        }

      

        [thePrinterConn close];