I have the following lines of code to print the webView
content.
let directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let printOpts: NSDictionary = [NSPrintJobDisposition: NSPrintSaveJob, NSPrintSaveJob: directoryURL, NSPrintScalingFactor: 2.0]
let printInfo = NSPrintInfo(dictionary: printOpts as! [String : AnyObject])
printInfo.horizontalPagination = .autoPagination
printInfo.verticalPagination = .autoPagination
let printOperation = NSPrintOperation(view: webView.mainFrame.frameView, printInfo: printInfo)
printOperation.printPanel.options = [.showsOrientation, .showsPaperSize, .showsPreview, .showsPageSetupAccessory, .showsScaling, .showsPrintSelection]
printOperation.run()
The problem is that it sometimes causes the application to crash when the user interacts with the print operation panel.
If I just click on the cancel button, the application can crash. And if I try to set a different scale rate, it can sometimes crash. I don't know why the application will crash. It's always the last line. What am I doing wrong? Thanks.