问题
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