ios - 在 Swift 中获取 UIPrintInteractionController 的作业状态

标签 ios swift ios9 airprint

我有一个问题:我想知道打印作业的状态。我正在打印一个临时存储在云驱动器中的 PDF 文件。我想在打印作业完成后删除该文件。我怎样才能 swift 意识到这一点? 这是我的代码片段:

 // 1
    let printController = UIPrintInteractionController.sharedPrintController()
    // 2
    let printInfo = UIPrintInfo(dictionary:nil)
    printInfo.outputType = UIPrintInfoOutputType.General
    printController.showsNumberOfCopies = false
    printController.showsPageRange = false
    printInfo.jobName = "PDF ID: " + pdfObjectID
    printController.printInfo = printInfo

    // 3
    //let formatter = UIMarkupTextPrintFormatter(markupText: "Test")
    let formatter = pdf.viewPrintFormatter()
    formatter.contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    printController.printFormatter = formatter

    // show PrintController
    printController.presentAnimated(true, completionHandler: nil)

您有什么建议吗? 谢谢:)

最佳答案

我自己没有测试过,但是根据文档, 你可以传递 UIPrintInteractionCompletionHandler作为 completionHandler: 参数:

When a print job concludes, you can reset any state set up for printing and do related housekeeping tasks.

一个简单的例子:

    printController.presentAnimated(true) { (controller, success, error) -> Void in
        if success {
            // Printed successfully
            // Remove file here ...
        } else {
            // Printing failed, report error ...
        }
    }

关于ios - 在 Swift 中获取 UIPrintInteractionController 的作业状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34495493/

相关文章:

ios - 请求 ALAssetRepresentation 的 size 属性时代码卡住

ios - 如何为 TableView 的 TableViewCell 设置 padding/margin 和圆角半径?

swift - 遍历每个节点名称

swift - 通过不同的排序选项对排行榜进行排序

ios - 使用 iOS API 创建私有(private)提醒?

ios - 如何在运行时更改约束优先级

ios - Collection View 高度

ios - 传输安全已阻止明文 HTTP

uinavigationcontroller - iOS 9 : Frame no longer set in viewWillAppear after UINavigationController pushViewController

ios - 通过 WhatsApp 分享图片,只需显示 WhatsApp 图标