I'm getting infrequent crashes when I try to show a newly created PDF. The PDF is file based, and shortly after UIGraphicsEndPDFContext
its shown.
The crash reports make it appear that the file itself is being mutated after its displayed.
So my question: is the file (self.filePath) absolutely flushed and closed when UIGraphicsEndPDFContext
returns?
If not, is there some way to detect when it has finished?
Thanks!
David
`func addPageNumbers() { let url = URL(fileURLWithPath: filePath) guard let document = CGPDFDocument(url as CFURL) else { return }
// You have to change the file path otherwise it can cause blank white pages to be drawn.
self.filePath = "\(filePath)-final.pdf"
UIGraphicsBeginPDFContextToFile(filePath, .zero, nil)
let pageCount = document.numberOfPages
for i in 1...pageCount {
...
}
}
UIGraphicsEndPDFContext()
}