WKWebView does load resources from local document folder

后端 未结 8 562
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 09:38

In my Swift iOS app, I want to download some dynamic HTML pages from a remote server, save them in the document directory, and display those pages from document directory.

8条回答
  •  粉色の甜心
    2020-11-28 10:14

    Constructing the URLs this way allowed me to load resources from the document directory with WKWebView:

    guard let docDir = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) else {
        return
    }
    
    let resourceURL = docDir.appendingPathComponent("/Path/To/Your/Resource")
    self.wkWebView.loadFileURL(resourceURL, allowingReadAccessTo: docDir)
    

提交回复
热议问题