Post

Replies

Boosts

Views

Activity

WKWebView and QuickLook Issues Previewing iWork Files
Hello, I've been having some issues getting WKWebView or QuickLook rendering a preview of files with iWork type extensions (.pages, .numbers, .key) At first, I thought it was the contentType (or media type) not being set correctly, but I'm almost positive the correct one is application/vnd.apple.pages. I've seen older posts that reference the contentType as .pages.zip as iWork files at some point in time were directories, but it's my understanding that is no longer the case. I've tried the following media types application/zip, application/pdf, application/vnd.apple.pages and the default application/octet-stream see this doc for application/vnd.apple.pages confirmation.  iana.org/assignments/media-types/media-types.xhtml I tried to just use QuickLook thinking this framework would solve all my problems. Well, the result is better in the respect that QuickLook doesn't default to showing the file encoding when a preview can't be shown. But the file preview is still missing. See these basic implementations of WKWebView and QuickLook. Note: Target iOS 13.6 All iWork Apps are updated Assume files haven't been tampered with Storyboard wkwebview Pages_test.pages file is added into project and is in the correct target No protocol methods implemented WKWebView WKWebView class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate { @IBOutlet weak var webView:WKWebView! override func viewDidLoad() { 		super.viewDidLoad() 		 		webView.uiDelegate = self 		webView.navigationDelegate = self 		 		let url = Bundle.main.url(forResource: "pages_test", withExtension: "pages")! 		 		var data:Data? 		do { 				try data = Data(contentsOf: url) 		} catch { 				fatalError("Error fetching data") 		} 		 		webView.load(data!, mimeType: "application/vnd.apple.pages", characterEncodingName: "", baseURL: url.deletingLastPathComponent()) } QuickLook class ViewController: UIViewController {   var previewView:QLPreviewController!       override func viewDidLoad() {     super.viewDidLoad()     setUpQuickLookPreview()   }       override func viewDidAppear(_ animated: Bool) {     super.viewDidAppear(animated)     showQuickLookPreview()   }       func setUpQuickLookPreview(){     previewView = QLPreviewController()     previewView.dataSource = self     previewView.delegate = self     previewView.currentPreviewItemIndex = 0   }       func showQuickLookPreview(){     present(previewView, animated: true, completion: nil)   } } extension ViewController: QLPreviewControllerDataSource, QLPreviewControllerDelegate {   func numberOfPreviewItems(in controller: QLPreviewController) -> Int {     return 1   }       func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {     let url = Bundle.main.url(forResource: "pages_test", withExtension: "pages")!     return url as QLPreviewItem   } }    
1
0
1.5k
Sep ’20