title: wkwebview - display image from documents directory into local html
body: <p>I have an app with downloaded images to be displayed in local html. I am still using <code>Objective-C</code> because this app is 4 years old.
  When first launch the app, it will download the images and other dynamic content (which I check, it is in Documents/content/ directory). </p>
  
  <p>I have this code to get the content location:</p>
  
  <pre><code>NSString *contentBasePath = [app.contentManager contentBasePath];
  </code></pre>
  
  <p>which I get:</p>
  
  <blockquote>
    <p>/var/mobile/Containers/Data/Application/4AFD30E2-F4F7-405A-9FE9-1857EEC11CC7/Documents/content</p>
  </blockquote>
  
  <p>Then I have a few html pages that will call the downloaded images dynamically:</p>
  
  <pre><code>&lt;div class="box-round benefits-thumbnail" style="background-image:url('file://{{../contentBasePath}}/{{filename}}');"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Which I check, <code>{{../contentBasePath}}</code> will get:</p>
  
  <blockquote>
    <p>/var/mobile/Containers/Data/Application/4AFD30E2-F4F7-405A-9FE9-1857EEC11CC7/Documents/content</p>
  </blockquote>
  
  <p>and <code>{{filename}}</code> will get</p>
  
  <pre><code>example.jpg
  </code></pre>
  
  <p>which is all correct.</p>
  
  <p>All this works with <code>uiwebview</code>. However I need to use <code>wkwebview</code>, the image did not show up. </p>
  
  <p>I tried:</p>
  
  <pre><code>&lt;div class="box-round benefits-thumbnail" style="background-image:url('{{../contentBasePath}}/{{filename}}');"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>and it still not working. </p>
  
  <p>I googled and read around and it seems like <code>wkwebview</code> do not allow absolute path. so I tried as per this suggest:</p>
  
  <pre><code>[_webConfig.preferences  setValue:@YES forKey:@"allowFileAccessFromFileURLs"];
  </code></pre>
  
  <p>and still not working.</p>
  
  <p>How can I resolve this?</p>