forked from januslo/react-native-bluetooth-escpos-printer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PrintColumnBleWriteDelegate.m
53 lines (49 loc) · 1.64 KB
/
PrintColumnBleWriteDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// PrintColumnBleWriteDelegate.m
// RNBluetoothEscposPrinter
//
// Created by januslo on 2018/10/6.
// Copyright © 2018年 Facebook. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "PrintColumnBleWriteDelegate.h"
@implementation PrintColumnBleWriteDelegate
NSMutableArray<NSMutableString *> *columns;
NSInteger maxRowCount;
- (void)didWriteDataToBle:(BOOL)success {NSLog(@"Call back deletgate: %lu",_now+1);
if(_canceled){
if(_pendingReject) _pendingReject(@"ERROR_IN_PRINT_COLUMN",@"ERROR_IN_PRINT_COLUMN",nil);
return;
}
_now = _now+1;
if(_now >= maxRowCount){
if(_error && _pendingReject){
_pendingReject(@"ERROR_IN_PRINT_COLUMN",@"ERROR_IN_PRINT_COLUMN",nil);
}else if(_pendingResolve){
_pendingResolve(nil);
}
}else{
if(!success){
_error = true;
}
[self print];
}
[NSThread sleepForTimeInterval:0.05f];//slow down.
}
-(void)printColumn:( NSMutableArray<NSMutableString *> *)columnsToPrint withMaxcount:(NSInteger)maxcount{
columns = columnsToPrint;
maxRowCount = maxcount;
[self print];
}
-(void)print{
[(NSMutableString *)[columns objectAtIndex:_now] appendString:@"\n\r"];//wrap line..
@try {
[self.printer textPrint:[columns objectAtIndex:_now] inEncoding:_encodig withCodePage:_codePage widthTimes:_widthTimes heightTimes:_heightTimes fontType:_fontType delegate:self];
}
@catch (NSException *e){
NSLog(@"ERROR IN PRINTING COLUMN:%@",e);
_pendingReject(@"ERROR_IN_PRINT_COLUMN",@"ERROR_IN_PRINT_COLUMN",nil);
self.canceled = true;
}
}
@end;