A.Gum
1
Although my app doesn’t crash, it does spit out the following when I run it on the simulator…
2020-07-17 21:02:42.553238-0500 wfpsmobileapp[81720:1913019] WF: === Starting WebFilter logging for process wfpsmobileapp
2020-07-17 21:02:42.553429-0500 wfpsmobileapp[81720:1913019] WF: _userSettingsForUser : (null)
2020-07-17 21:02:42.553560-0500 wfpsmobileapp[81720:1913019] WF: _WebFilterIsActive returning: NO
I get a different error when I use my iPhone in place of the simulator…
The iPhone error…
2020-07-17 21:05:23.302720-0500 wfpsmobileapp[8845:2924127] WF: === Starting WebFilter logging for process wfpsmobileapp
2020-07-17 21:05:23.302782-0500 wfpsmobileapp[8845:2924127] WF: _userSettingsForUser mobile: {
filterBlacklist = (
);
filterWhitelist = (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}
2020-07-17 21:05:23.302837-0500 wfpsmobileapp[8845:2924127] WF: _WebFilterIsActive returning: NO
2020-07-17 21:05:23.411177-0500 wfpsmobileapp[8845:2924127] Could not create sandbox extension
Could not create sandbox extension
I believe it is associated with this bit of code as it only occurs when I open a PDF file which is the basis of this app…
//Opens PDF based on button pressed
func openPdfFile() {
let url = Bundle.main.url(forResource: pdfTitle, withExtension: "pdf")
if let url = url {
let webView = WKWebView(frame: view.frame)
let urlRequest = URLRequest(url: url)
webView.load(urlRequest)
view.addSubview(webView)
}
}
//Opens AA01 Protocol
@IBAction func aa01Protocol(_ sender: Any) {
pdfTitle = "aa01Protocol"
openPdfFile()
}
}
Any ideas &/or suggestions?
What happens if you load the PDF from a Website. Say this one. It’s just a simple DrillChart PDF.
http://www.smithbearing.com/images/pdf/ENG-FractionalChart.pdf
Hi,
This is the method I use to display a pdf in the bundle. You can see some sight differences form your method.
func getPrayPdf(name: String) {
if let path = Bundle.main.path(forResource: name, ofType: "pdf") {
let url = URL(fileURLWithPath: path)
if let pdfDocument = PDFDocument(url: url) {
pdfView.displayMode = .singlePageContinuous
pdfView.autoScales = true
pdfView.displayDirection = .vertical
pdfView.document = pdfDocument
}
}
} //end getPrayPdf
I found that Apple is REALLY picky if you use a web view instead of opening it in Safari. Hence I just placed them in the bundle.
Best of luck.
Blessings,
—Mark
Good one Mark. I’ll try that myself and see how it goes.
Hmmmmmm, there is a bit more to it than just that.
This might also help:
https://www.hackingwithswift.com/example-code/libraries/how-to-display-pdfs-using-pdfview
Arnie,
This was some code I implemented in a simple UIKit program just to display a PDF and I based it on the Paul Hudson article I posted previously.
import UIKit
import PDFKit
class ViewController: UIViewController {
let pdfView = PDFView()
override func viewDidLoad() {
super.viewDidLoad()
setupPDFView()
displayPDF()
}
func setupPDFView() {
pdfView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(pdfView)
pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
pdfView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
}
func displayPDF() {
guard let path = Bundle.main.url(forResource: "results", withExtension: "pdf") else { return }
let pdfDocument = PDFDocument(url: path)
pdfView.document = pdfDocument
pdfView.displayMode = .singlePageContinuous
pdfView.autoScales = true
pdfView.displayDirection = .vertical
}
}
The file I added was just a multi page PDF I had lying around and it worked nicely.