Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed printrawdata in ios #101

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,15 @@ var BLEPrinter = {
*/
printRaw: function (text) {
if (Platform.OS === "ios") {
var processedText = textPreprocessingIOS(text, false, false);

RNBLEPrinter.printRawData(
processedText.text,
processedText.opts,
function (error) {
return console.warn(error);
}
);
} else {
RNBLEPrinter.printRawData(text, function (error) {
return console.warn(error);
Expand Down
5 changes: 4 additions & 1 deletion ios/RNBLEPrinter.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ - (void)handleNetPrinterConnectedNotification:(NSNotification*)notification
@try {
!m_printer ? [NSException raise:@"Invalid connection" format:@"printRawData: Can't connect to printer"] : nil;

NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:text options:0];
NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];

NSNumber* boldPtr = [options valueForKey:@"bold"];
NSNumber* alignCenterPtr = [options valueForKey:@"center"];

Expand All @@ -91,7 +94,7 @@ - (void)handleNetPrinterConnectedNotification:(NSNotification*)notification

bold ? [[PrinterSDK defaultPrinterSDK] sendHex:@"1B2108"] : [[PrinterSDK defaultPrinterSDK] sendHex:@"1B2100"];
alignCenter ? [[PrinterSDK defaultPrinterSDK] sendHex:@"1B6102"] : [[PrinterSDK defaultPrinterSDK] sendHex:@"1B6101"];
[[PrinterSDK defaultPrinterSDK] printText:text];
[[PrinterSDK defaultPrinterSDK] printText:decodedString];

NSNumber* beepPtr = [options valueForKey:@"beep"];
NSNumber* cutPtr = [options valueForKey:@"cut"];
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ const BLEPrinter = {
*/
printRaw: (text: string): void => {
if (Platform.OS === "ios") {
var processedText = textPreprocessingIOS(text, false, false);

RNBLEPrinter.printRawData(
processedText.text,
processedText.opts,
function (error) {
return console.warn(error);
}
);
} else {
RNBLEPrinter.printRawData(text, (error: Error) => console.warn(error));
}
Expand Down