I have implemented a Custom PDFView that loads pdf files from the cloud and locally if available. For local instances as expected everything loads fast, but when the url is not local i.e from the server it may take a while, I'd like to add an UIActivityIndicator while the PDFView loads the file, is there a way for us to know like a delegate or a notification to listen to to keep track of this?
My implementation is basically like below:
let url = ReportsRepository.shared.getReportUrl(id: "1234")
self.pdfView.document = PDFDocument(url: url)
After this, if the URL is from the server the application seems to freeze, so I need to add a UIActivityIndicator here, the problem is how would I stop it using the PDFKit?
Another way to load your
PDFDocument
is to pass in raw data.If this were my problem, I'd load the data asynchronously via a method like this:
You could either display the UIActivityIndicator immediately (when you detect it's remote) or you could set a timer to fire after 1/2 - 1 second, invalidate and/removing both as the PDF file is about to display.