Show PDF with urlPath Swift Xcode

2

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 route and if I go to the route I can open the pdf normally.

All this I do 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 still have the path of the pdf file what I can not show or open this file.

I tried with UIApplication.shared.open(documentsURL) and with webView .

    
asked by Bruno Sosa Fast Tag 25.10.2018 в 16:48
source

1 answer

2

Resolved as follows

 var docController:UIDocumentInteractionController!
  self.docController = UIDocumentInteractionController(url: documentsURL)
                        docController.presentOptionsMenu(from: self.view.frame, in: self.view, animated: true)
    
answered by 29.10.2018 / 14:05
source