react-native-thermal-receipt-printer-image-qr
react-native-thermal-receipt-printer-image-qr copied to clipboard
BLEPrinter.getDeviceList() not response
I don't get any response from func getDeviceList() including error message
I have the same issue @thiendangit, any idea?
RCT_EXPORT_METHOD(getDeviceList:(RCTResponseSenderBlock)successCallback
fail:(RCTResponseSenderBlock)errorCallback) {
@try {
!_printerArray ? [NSException raise:@"Null pointer exception" format:@"Must call init function first"] : nil;
__block BOOL foundDevice = NO; // flag để kiểm tra xem có thiết bị nào được tìm thấy hay không
[[PrinterSDK defaultPrinterSDK] scanPrintersWithCompletion:^(Printer* printer){
foundDevice = YES; // đánh dấu đã tìm thấy thiết bị
[self->_printerArray addObject:printer];
}];
// chờ cho hàm scanPrintersWithCompletion kết thúc
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (!foundDevice) {
// không có thiết bị nào được tìm thấy
successCallback(@[]);
} else {
NSMutableArray *mapped = [NSMutableArray arrayWithCapacity:[self->_printerArray count]];
[self->_printerArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[Printer class]]) {
Printer *printer = (Printer *)obj;
NSDictionary *dict = @{ @"device_name" : printer.name, @"inner_mac_address" : printer.UUIDString};
[mapped addObject:dict];
}
}];
NSMutableArray *uniquearray = (NSMutableArray *)[[NSSet setWithArray:mapped] allObjects];
successCallback(@[uniquearray]);
}
});
} @catch (NSException *exception) {
errorCallback(@[exception.reason]);
}
}