'Download pdf from base64 url webview swift

I am trying to download a pdf from a url in a webview to the device. here is what the base64 endpoint looks like data:application/pdf;base64,JVBERi0xLjMKJf////8KOCAwIG9iago8PAovVHlwZSAvRXh0R1N0YXRlCi9jYSAxCj4+CmVuZG9iagoxMiAwIG9iago8 ... JSVFT0YK

Problem now is getting the data and downloading to show Activity view controller

private func downloadData(from url: URL, fileName: String, completion: @escaping (Bool, URL?) -> Void) {
        webView.configuration.websiteDataStore.httpCookieStore.getAllCookies() { cookies in
            let session = URLSession.shared
            session.configuration.httpCookieStorage?.setCookies(cookies, for: url, mainDocumentURL: nil)
            let task = session.downloadTask(with: url) { localURL, urlResponse, error in
                if let localURL = localURL {

                    let destinationURL = self.moveDownloadedFile(url: localURL, fileName: fileName)
                    completion(true, destinationURL)
                }
                else {
                    completion(false, nil)
                }
            }

            task.resume()
        }
    }

in the navigationResponse I have this but the my break point is not triggered.

if let data = Data(base64Encoded: url.absoluteString, options: .ignoreUnknownCharacters) {
                        print("THE MINETYPE data: \(data)")
                    } 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source