Currently I have a webservice which returns an array of bytes which I transform into base64 to assemble the PDF, this is saved in a path and if I go to the path I can open the pdf normally.
I do all this in
func saveBase64StringToPDF(base64String: String, fileName: String) {
guard
var documentsURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last,
let convertedData = Data(base64Encoded: base64String)
else {
//handle error when getting documents URL
self.showMessageAlert(strTitle: NSLocalizedString("strErrorTitle",comment:""), strMessage: NSLocalizedString("strErrorPdfMsg",comment:""))
return
}
//name your file however you prefer
documentsURL.appendPathComponent(fileName)
do {
try convertedData.write(to: documentsURL)
} catch {
//handle write error here
self.showMessageAlert(strTitle: NSLocalizedString("strErrorTitle",comment:""), strMessage: NSLocalizedString("strErrorPdfMsg",comment:""))
}
SVProgressHUD.dismiss()
print(documentsURL)
}
and in documentsURL
I have the path of the pdf file what I cannot do is show or open this file.
I tried with UIApplication.shared.open(documentsURL)
and with webView
.
I solved as follows