-1
ためFileManagerのに働いていない私のコードです:はWKWebViewがここdocumentDirectory
var fileContent = ""
let baseURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileURL = baseURL.appendingPathComponent("index").appendingPathExtension("html")
do {
fileContent = try String(contentsOf: fileURL, encoding: String.Encoding.utf8)
} catch let error as NSError {
print("Failed getting content of the file: \(fileURL), Error: " + error.localizedDescription)
fileContent = ""
}
editorWebView!.loadHTMLString(fileContent, baseURL: baseURL)
問題は、次のとおりです。
<img src='resources/check-box-uncheck.png'>
WKWebView負荷HTML文字列が、画像が表示されません。 FileManagerを使用して、index.htmlファイルと関連ファイルをdocumentDirectoryにコピーしました。私はmainBundleを使いたくない。 助けてください
ベースURLは次のとおりです。 ファイル:ファイルやフォルダをチェックする/// VAR /モバイル/コンテナ/データ/アプリケーション/ C89D5B66-30FD-4B88-949F-F591E0EA1BE7 /ドキュメント/
機能: FUNC allFilesList( atPath:URL) - > [文字列]? {
var allFileNames = [String]()
do {
let fullPaths = try self.contentsOfDirectory(at: atPath, includingPropertiesForKeys:[], options: FileManager.DirectoryEnumerationOptions.skipsHiddenFiles)
for fileName in fullPaths {
let theFileName = fileName.lastPathComponent
allFileNames.append(theFileName)
}
} catch let error {
print("Error for list folders OR notes: \(error.localizedDescription)")
}
return allFileNames
}
あなたはデリゲートプロトコルを実装しましたか?そこにあるメソッドの1つが、どこに何がロードできるかを制御します。 – Mgetz
@Mgetzはい、しました。 editorWebView!.uiDelegate = selfそしてクラスWKUIDelegateに含まれています – mriaz0011
@mattファイルをチェックする方法があります。 – mriaz0011