QuickLook not displaying pdf only gray screen with file name as title

732 views Asked by At

I have added QuickLook in my app to show docs, pdf etc from Document Directory, It is working fine in simulator but in iPad it's only showing file name as title and gray screen instead of pdf page, don't know whats wrong in there here is the code

docUrlLocal = jobDocument.docFileLocal
docUrlLocal = docUrlLocal.replacingOccurrences(of: "file://", with: "") 
/* Simulator path /Users/varunnaharia/Library/Developer/CoreSimulator/Devices/86CE9E4C-7D50-4831-934C-442A7558024C/data/Containers/Data/Application/86E66141-4F69-4347-81B5-415F805884C1/Documents/33fe5731-129a-4b8e-aa67-c3e840a69677.pdf 
   iPad Path     /var/mobile/Containers/Data/Application/743CEA41-89F4-4EEF-84E5-FCECA1FCB038/Documents/33fe5731-129a-4b8e-aa67-c3e840a69677.pdf
*/
let ql = QLPreviewController()
ql.dataSource  = self
parentVC.present(ql, animated: true, completion: nil)

And code to download and save doc

let fileName = (self.docURL as NSString).lastPathComponent
                    let fullFilePath = URL(fileURLWithPath: 
FileManager.documentsDir()).appendingPathComponent("\(fileName)")
                    let destination = 
DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
                    Alamofire.download(
                        self.docURL,
                        method: .get,
                        parameters: nil,
                        encoding: JSONEncoding.default,
                        headers: nil,
                        to: destination).downloadProgress(closure: { (progress) in
                            //progress closure

                        }).response(completionHandler: { (DefaultDownloadResponse) in
                            //here you able to access the DefaultDownloadResponse
                            //result closure
                            self.jobDocument.docFileLocal = fullFilePath.absoluteString
                            self.parentVC.tblView.reloadData()
                            self.btnOpen.isHidden = true
                        })
1

There are 1 answers

1
Zaporozhchenko Oleksandr On

Idk, if that's really ur problem, I fixed it like this:

    let filename          = name.fileName().replacingOccurrences(of: ".", with: " ")
    let fileExtension     = name.fileExtension()
    let fixedFileTypeName = filename + fileExtension

So the problem was dots in the file name (url)