有没有办法“静音打印”使用ios AirPrint(例如,没有打印对话框)?

发布于 2024-12-15 10:57:31 字数 94 浏览 1 评论 0原文

我熟悉 ios 和 AirPrint 功能。但是,我想在没有看到打印对话框的情况下打印到打印机,并且找不到正确的 API 调用。

还有其他人遇到过这种情况吗?

I am familiar with ios and AirPrint features. However, I'd like to print to my printer without seeing a print dialog and cannot find the correct API calls.

Has anyone else encountered this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

够运 2024-12-22 10:57:32

从 iOS 8 开始,您可以在不显示打印对话框的情况下进行打印。查看 UIPrintInteractionController(直接打印到打印机)

Starting with iOS 8 you can print without showing a print dialog. Check out UIPrintInteractionController (Printing Directly to a Printer)

妞丶爷亲个 2024-12-22 10:57:32
class func printEvent(view : UIView , image: UIImage){

    let printController = UIPrintInteractionController.sharedPrintController()!

    let printInfo = UIPrintInfo(dictionary:nil)!
    printInfo.outputType = UIPrintInfoOutputType.General
    printInfo.jobName = "print Job"
    printController.printInfo = printInfo
    printController.printingItem = image

    let url = NSURL(string: "http://192.168.10.173:631/ipp/print")
    let printerObj =  UIPrinter(URL: url!)
    printController.printToPrinter(printerObj, completionHandler: nil)
}
class func printEvent(view : UIView , image: UIImage){

    let printController = UIPrintInteractionController.sharedPrintController()!

    let printInfo = UIPrintInfo(dictionary:nil)!
    printInfo.outputType = UIPrintInfoOutputType.General
    printInfo.jobName = "print Job"
    printController.printInfo = printInfo
    printController.printingItem = image

    let url = NSURL(string: "http://192.168.10.173:631/ipp/print")
    let printerObj =  UIPrinter(URL: url!)
    printController.printToPrinter(printerObj, completionHandler: nil)
}
浅浅淡淡 2024-12-22 10:57:32

我正在使用如下所示,一次会出现打印机选择选项,之后每次都会发生无声打印

- (void)printCard:(UIImage*)printImage{

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSURL *printURL = [NSURL URLWithString:[defaults stringForKey:@"printURLLink"]];
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
{
    if(printURL)
    {
        UIPrinter *printer = [UIPrinter printerWithURL:printURL];
        [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printer];
        UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
        controller.printingItem = printImage;
        if(printer)
        {
            [controller printToPrinter:printer completionHandler:^(UIPrintInteractionController *printController, BOOL completed, NSError *error)
             {
                 if(completed)
                 {
                 }
                 else
                 {
                     NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
                 }
             }];
        }
    }
    else
    {
        UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
        [printPicker presentFromRect:printCardBtn.frame inView:self.view animated:YES completionHandler:
         ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
         {

             if (userDidSelect)
             {
                 [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
                 NSURL *printerURL = printerPicker.selectedPrinter.URL;
                 NSLog(@"printerURL--->%@",printerURL.absoluteString);
                 [defaults setObject:[printerURL absoluteString] forKey:@"printURLLink"];
                 [defaults synchronize];

                 UIPrinter *printer = [UIPrinter printerWithURL:printerURL];
                 [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printer];
                 UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
                 controller.printingItem = printImage;
                 if(printer)
                 {
                     [controller printToPrinter:printer completionHandler:^(UIPrintInteractionController *printController, BOOL completed, NSError *error)
                      {
                          if(completed)
                          {
                          }
                          else
                          {
                              NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
                          }
                      }];
                 }

             }
         }];
    }

}

}

i am using like below, one time there will come printer selection option and after it every time silent print will happen

- (void)printCard:(UIImage*)printImage{

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSURL *printURL = [NSURL URLWithString:[defaults stringForKey:@"printURLLink"]];
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
{
    if(printURL)
    {
        UIPrinter *printer = [UIPrinter printerWithURL:printURL];
        [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printer];
        UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
        controller.printingItem = printImage;
        if(printer)
        {
            [controller printToPrinter:printer completionHandler:^(UIPrintInteractionController *printController, BOOL completed, NSError *error)
             {
                 if(completed)
                 {
                 }
                 else
                 {
                     NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
                 }
             }];
        }
    }
    else
    {
        UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
        [printPicker presentFromRect:printCardBtn.frame inView:self.view animated:YES completionHandler:
         ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
         {

             if (userDidSelect)
             {
                 [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
                 NSURL *printerURL = printerPicker.selectedPrinter.URL;
                 NSLog(@"printerURL--->%@",printerURL.absoluteString);
                 [defaults setObject:[printerURL absoluteString] forKey:@"printURLLink"];
                 [defaults synchronize];

                 UIPrinter *printer = [UIPrinter printerWithURL:printerURL];
                 [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printer];
                 UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
                 controller.printingItem = printImage;
                 if(printer)
                 {
                     [controller printToPrinter:printer completionHandler:^(UIPrintInteractionController *printController, BOOL completed, NSError *error)
                      {
                          if(completed)
                          {
                          }
                          else
                          {
                              NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
                          }
                      }];
                 }

             }
         }];
    }

}

}

终止放荡 2024-12-22 10:57:32

不,Apple 的政策是按照用户理解的方式进行操作。

No, it's Apple's policy to make things the way user understands what's going on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文