在 Swift 中获取 UIPrintInteractionController 的作业状态
Get the Job Status of UIPrintInteractionController in Swift
我有一个问题:我想知道打印作业的状态。我正在打印一个临时存储在云驱动器中的 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 ...
}
}
为了补充 Martin R 的回答,您可以通过声明闭包来添加完成处理程序。如果您想根据设备以不同方式呈现打印控制器,这将很有用:
let printCompletionHandler: UIPrintInteractionCompletionHandler = { (controller, success, error) -> Void in
if success {
// Printed successfully
// Remove file here ...
} else {
// Printing failed, report error ...
}
}
if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad {
printController.presentFromRect(self.printButton.frame, inView: self.view, animated: true, completionHandler: printCompletionHandler)
} else {
printController.presentAnimated(true, completionHandler: printCompletionHandler)
}
这样您就可以对两个调用使用相同的完成处理程序:)
我有一个问题:我想知道打印作业的状态。我正在打印一个临时存储在云驱动器中的 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 ...
}
}
为了补充 Martin R 的回答,您可以通过声明闭包来添加完成处理程序。如果您想根据设备以不同方式呈现打印控制器,这将很有用:
let printCompletionHandler: UIPrintInteractionCompletionHandler = { (controller, success, error) -> Void in
if success {
// Printed successfully
// Remove file here ...
} else {
// Printing failed, report error ...
}
}
if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad {
printController.presentFromRect(self.printButton.frame, inView: self.view, animated: true, completionHandler: printCompletionHandler)
} else {
printController.presentAnimated(true, completionHandler: printCompletionHandler)
}
这样您就可以对两个调用使用相同的完成处理程序:)