0

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?

Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68

2 Answers2

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.

Siyu Song
  • 897
  • 6
  • 21
  • 1
    I am using loadFileURL to load html file. But when I try to access Image urls from Documents folder I am getting issue. Same url works in UIWebview. – Jagan Nathan Feb 04 '16 at 04:20
0

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"

Vizllx
  • 9,135
  • 1
  • 41
  • 79
  • What will be the difference between two? Should I use without " file:///private" – Jagan Nathan Feb 01 '16 at 10:39
  • @Vizlix, But in wkwebview i cannot load using NSURL right? Whatever url i am getting from NSFileManager that one only I can use right? Please correct me if I am wrong. For testing I am trying to access all files from documents example below : directoryUrls = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsUrl, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions()) – Jagan Nathan Feb 01 '16 at 12:10