4

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
                        })
Varun Naharia
  • 5,318
  • 10
  • 50
  • 84
  • Which URL do you give Quick Look in your datasource? Note: your code to strip file:// is fishy. If you want to access the path, use either url.path or url.fileSystemRepresentation depending on the API you want to use with it. – Thomas Deniau Sep 08 '17 at 14:30
  • Simulator path is working but the device is not working it doesn't matter if there is file:// there or not, actually in device pdf is not visible but if I share that pdf to any other app it's showing content. – Varun Naharia Sep 08 '17 at 20:11
  • have u found any fix for this? – Zaporozhchenko Oleksandr May 17 '18 at 15:58
  • @Aleksandr no there was some bug or something with os and replaced with webview to open file – Varun Naharia May 17 '18 at 16:19

1 Answers1

0

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)

Zaporozhchenko Oleksandr
  • 4,660
  • 3
  • 26
  • 48