WKwebview : Cannot view app documents images in app web view iOS swift

风格不统一 提交于 2019-12-12 03:30:45

问题


I am trying to load images from app documents directory(image were downloaded in app) in wkwebview. Is there any limitations in wkwebiview or any permission problem?

Eg Image url:

file:///private/var/mobile/Containers/Data/Application/34EDAFAD-F0CD-4A63-8B2E-74BB370C71DF/Documents/00286863-49ED-4C4D-8E36-106098DA5D72.jpeg

Can anyone help me out?


回答1:


Are you using - loadRequest: to load the local file? It is a known issue that it doesn't work for local files.

If you can use iOS 9 APIs, use - loadFileURL:allowingReadAccessToURL: instead.




回答2:


You have to load the image using File path not image Url as you are not downloading any image from any link, so you have load the URL with image file path, like this:-

[NSURL fileURLWithPath:imgpath]   ---objective C

 NSURL(fileURLWithPath:imgpath)  --- swift

For your case imgpath is " file:///private/var/mobile/Containers/Data/Application/34EDAFAD-F0CD-4A63-8B2E-74BB370C71DF/Documents/00286863-49ED-4C4D-8E36-106098DA5D72.jpeg"



来源:https://stackoverflow.com/questions/35128009/wkwebview-cannot-view-app-documents-images-in-app-web-view-ios-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!