WKWebView does load resources from local document folder

后端 未结 8 508
伪装坚强ぢ
伪装坚强ぢ 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:23

    The files must be in the document directory.

    I implemented the following to retrieve a document:

    let documentDirUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
    let fileNameWithExtension = "IMG_0002.PNG"
    let indexFileUrl = documentDirUrl.appendingPathComponent(fileNameWithExtension)
    if FileManager.default.fileExists(atPath: indexFileUrl.path) {
        webView.loadFileURL(indexFileUrl, allowingReadAccessTo: documentDirUrl)
    }
    

提交回复
热议问题