UIWebView不会从Documents文件夹重新加载图像文件

时间:2016-05-14 07:19:05

标签: javascript html swift uiwebview

我正在使用RichEditorView作为记笔记应用的编辑器。所以笔记的文字是html。当我插入从相机胶卷中选择的图像时,它们都会出现(参见下面的屏幕截图)。但是,当我停止模拟器并重新启动应用程序时,无法找到图像。 我确保图像文件位于Documents文件夹中。

didFinishPickingMediaWithInfo看起来像这样

 if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {

            if let imageData = pickedImage.resizeImage(200.0 , maxWidth:300.0, compression:0.7) {

let filename = NSUUID()。UUIDString +“.jpg”

let fileURL = getDocumentsURL()。URLByAppendingPathComponent(filename)

print(“file url:(fileURL)”)

做{ 尝试imageData.writeToURL(fileURL,options:NSDataWritingOptions.DataWritingAtomic)    } 捕获错误为NSError {

打印(误差)
 //这是来自RichEditorView self.keyboardToolbar.editor?.insertImage(fileURL.absoluteString,alt:“new image”)的函数
 dismissViewControllerAnimated(true,completion:nil)

写入文件成功,不会抛出任何错误 - 否则无法再次检索并且不会显示。

请参阅下面的屏幕截图。 html中的图片标记看起来像这样

<img src="file:///Users/Dominik/Library/Developer/CoreSimulator/Devices/BC19750C-FE45-4C7A-853E-1933DE0B5515/data/Containers/Data/Application/6F3EFBA9-E1CA-45F7-9567-D5E653972DB6/Documents/3E9BCE98-033D-4754-9125-683F704E2CEA.jpg" alt="image">

注释文本(以html格式)保留在Core Data中。所以关闭应用程序后重新加载。 img标签仍然在文本中,应该加载图像..但它不加载。

感谢您提供任何提示......

html loads the image from the document folder

After reloading the app in Xcode, the image cannot be found

0 个答案:

没有答案