【问题标题】:Could not send command to XPrinter无法向 XPrinter 发送命令
【发布时间】:2019-09-02 05:27:26
【问题描述】:

我在向 xPrinter 发送命令时遇到问题。我有它的 SDK for iOS 应用程序,并按照此框架中的说明通过 WIFI 连接成功地将我的 iOS 应用程序连接到这台打印机。

NSString * ip = "IPAddress";
[manager MConnectWithHost:ip port:9100 completion: ^(BOOL result){  
}];

--> 管理器已创建,连接成功。

但是当通过 MWIFIManager 类的 MWriteCommandWithData 方法发送命令时,总是打印出字符串,而不是命令到打印机。

示例: 我想通过为 TscCommnand 准备 cmd 来剪切页面:

NSData *data = [TscCommand cut] 

然后通过以下方式将其发送给 MWIFIManager:

[manager MWriteCommandWithData:data];

结果:它在打印机的纸张上打印'CUT',而不是裁切纸张

我从这里下载的 SDK:https://www.xprintertech.com/sdk 它是由 Objective C 编写的,而我的 iOS 应用程序是由 Swift 开发的。 我只想实现一种方法来连接和在 XPrinter(热敏打印机)上打印。

请有这方面经验的朋友指教。非常感谢!

【问题讨论】:

    标签: objective-c frameworks thermal-printer


    【解决方案1】:

    不确定您要对 IP 地址做什么...

    这是您在 iOS 中打印所需的全部内容:

    类 printInteractionController = NSClassFromString(@"UIPrintInteractionController");

    if ((printInteractionController != nil) && [printInteractionController isPrintingAvailable])
    {
        NSURL *fileURL = document.fileURL; // Document file URL
    
        printInteraction = [printInteractionController sharedPrintController];
    
        if ([printInteractionController canPrintURL:fileURL] == YES) // Check first
        {
            UIPrintInfo *printInfo = [NSClassFromString(@"UIPrintInfo") printInfo];
    
            printInfo.duplex = UIPrintInfoDuplexLongEdge;
            printInfo.outputType = UIPrintInfoOutputGeneral;
            printInfo.jobName = document.fileName;
    
            printInteraction.printInfo = printInfo;
            printInteraction.printingItem = fileURL;
            printInteraction.showsPageRange = YES;
    
            if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
            {
                [printInteraction presentFromRect:button.bounds inView:button animated:YES completionHandler:
                    ^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
                    {
                        #ifdef DEBUG
                            if ((completed == NO) && (error != nil)) NSLog(@"%s %@", __FUNCTION__, error);
                        #endif
                    }
                ];
            }
            else // Presume UIUserInterfaceIdiomPhone
            {
                [printInteraction presentAnimated:YES completionHandler:
                    ^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
                    {
                        #ifdef DEBUG
                            if ((completed == NO) && (error != nil)) NSLog(@"%s %@", __FUNCTION__, error);
                        #endif
                    }
                ];
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      相关资源
      最近更新 更多