1

Hello I'm try to save a file test.pdf from firebase storage to the document directory of my app but unfortunately not working.

here my content view with a button to run the task:

import SwiftUI
import Firebase
import WebKit


struct ContentView: View {

    var body: some View {
        VStack {

            Button(action: {
               let storage = Storage.storage()
                let storageRef = storage.reference()
                let islandRef = storageRef.child("test.pdf")
                // Create local filesystem URL
                let localURL = URL(string: self.cartellaDocuments())!
                
                let downloadTask = islandRef.write(toFile: localURL) { (url, err) in
                    if err != nil {
                     debugPrint(" // Uh-oh, an error occurred!")
                    } else {
                        debugPrint("\(String(describing: url))")
                    }
                }
            }) {
                Text("esegui")
            }
        }
    }

    func cartellaDocuments() -> String {
        let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
        debugPrint(paths[0])
        return paths[0]
    }
    
       
}

my storage in firebase:

Firebase Storage

I have try to follow the google firebase instruction but Im getting a following warning:

  • failed because it was passed an URL which has no scheme warning

how can I solve this issue.

thanks for the help

1 Answer 1

1

You can try this :

    let pdfView = PDFView()
    pdfView.translatesAutoresizingMaskIntoConstraints = false
    self.view.addSubview(pdfView)

    pdfView.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor).isActive = true
    pdfView.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor).isActive = true
    pdfView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
    pdfView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true
    

    if let document = PDFDocument(url: URL.init(string: "https://your storage download url")!) {
        pdfView.document = document
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.