게시 한 직후에 알아 냈습니다. (분명히) ... 희망적으로 이것은 다른 사람에게 도움이되기를 바랍니다.
웹 뷰를 생성 ...
let configuration = WKWebViewConfiguration()
let script = WKUserScript(source: "window.print = function() { window.webkit.messageHandlers.print.postMessage('print') }", injectionTime: WKUserScriptInjectionTime.AtDocumentEnd, forMainFrameOnly: true)
configuration.userContentController.addUserScript(script)
configuration.userContentController.addScriptMessageHandler(self, name: "print")
self.webView = WKWebView(frame: CGRectZero, configuration: configuration)
그럼 그냥
func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
if message.name == "print" {
printCurrentPage()
} else {
println("Some other message sent from web page...")
}
}
func printCurrentPage() {
let printController = UIPrintInteractionController.sharedPrintController()
let printFormatter = self.webView.viewPrintFormatter()
printController?.printFormatter = printFormatter
let completionHandler: UIPrintInteractionCompletionHandler = { (printController, completed, error) in
if !completed {
if let e = error? {
println("[PRINT] Failed: \(e.domain) (\(e.code))")
} else {
println("[PRINT] Canceled")
}
}
}
if let controller = printController? {
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
controller.presentFromBarButtonItem(someBarButtonItem, animated: true, completionHandler: completionHandler)
} else {
controller.presentAnimated(true, completionHandler: completionHandler)
}
}
}
인쇄 할보기를 물어 볼 수 있습니까? – MobileOverlord
WKWebView의 viewPrintFormatter를 인쇄하고 있습니다. –