title: Downloading files WKWebView ios
body: <p>I'm in the progress of migrating my app from UIWebView to WKWebView. All is going well and working as I tinker more with it. However, I notice now that I can't download forum attachments.</p>
  
  <p>I'm using HCDownload, and thus far has always worked perfect for me, so I know it's not on that end. I believe its the request, but I cant figure it out.</p>
  
  <p>I know the following:</p>
  
  <pre><code>UIWebView =&gt; WKWebView Equivalent
  --------------------------------------------------------------
  didFailLoadWithError =&gt; didFailNavigation
  webViewDidFinishLoad =&gt; didFinishNavigation
  webViewDidStartLoad =&gt; didStartProvisionalNavigation
  shouldStartLoadWithRequest =&gt; decidePolicyForNavigationAction
  </code></pre>
  
  <p>So with that known I am trying below:</p>
  
  <pre><code>- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  
      NSURLRequest *request = navigationAction.request;
      NSURL *fileURl = [request URL];
      NSString *externalFileExtension = [fileURl pathExtension];
      NSString *internalFileExtension = [[fileURl absoluteString] pathExtension];
  
      HCDownloadViewController *dlvc = [[HCDownloadViewController alloc] init];
      UINavigationController *vc = [[UINavigationController alloc] initWithRootViewController:dlvc];
      dlvc.delegate = self;
      vc.transitioningDelegate  = self;
  
      if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
  
          //External file extensions
          if ([fileExtensions containsObject:[externalFileExtension lowercaseString]]) {
              [dlvc downloadURL:fileURl userInfo:nil];
              [self presentViewController:vc animated:YES completion:nil];
              [vc release];
  
              NSLog(@"externalURL is %@", fileURl);
              decisionHandler(WKNavigationActionPolicyCancel);
              return;
          }
  
          //Internal file links
          if ([fileExtensions containsObject:[internalFileExtension lowercaseString]]) {
              [self presentViewController:vc animated:YES completion:nil];
              [dlvc downloadURL:fileURl userInfo:nil];
              [vc release];
  
              NSLog(@"internalURL is %@", fileURl);
              decisionHandler(WKNavigationActionPolicyCancel);
              return;
  
          }
  }
  </code></pre>
  
  <p>It will fire my download controller by finding the file extension, but instead it downloads the index.php, not the file.</p>
  
  <p>Example url:</p>
  
  <pre><code>https://example.com/index.php?app=core&amp;module=attach&amp;section=attach&amp;attach_id=1234=example.zip;
  </code></pre>
  
  <p>What am I doing wrong. It worked fine before in UIWebView and I know things are done differently. But how can it download something from say dropbox just fine, but an attached file on a forum gets goofed up.</p>
  
  <p>Any help would be appreciated</p>