iosswiftquicklookqlpreviewcontroller

QLPreviewController does not work on iOS11


class ViewController: UIViewController {
    let quickLookController = QLPreviewController()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        quickLookController.dataSource = self
        quickLookController.delegate = self
    }
    
    @IBAction func buttonAction(_ sender: Any) {
        present(quickLookController, animated: true, completion: nil)
        
        quickLookController.reloadData()
        quickLookController.refreshCurrentPreviewItem()
    }
}

extension ViewController: QLPreviewControllerDataSource,QLPreviewControllerDelegate {
    
    func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
        return 1
    }
    
    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
        let path = Bundle.main.path(forResource: "AppCoda-Ppt.ppt", ofType: nil)
        
        let url = NSURL(fileURLWithPath: path!)
        
        return url
    }
}

enter image description here


Solution

  • This is a bug in iOS 11.2. Please file it at bugreport.apple.com if you want to be kept up to date on its status. A workaround is not to store your ppt file in your app bundle. Use a different location somewhere in your container, such as your Application Support directory.