Reputation: 2325
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:
I have try to follow the google firebase instruction but Im getting a following warning:
how can I solve this issue.
thanks for the help
Upvotes: 1
Views: 236
Reputation: 1158
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
}
Upvotes: 1