Post

Replies

Boosts

Views

Activity

Document Picker does not work on device
I have a problem with Xcode version 15.0.1: I have programmed a DocumentPicker in Swift UI to load a document from my own cloud into the app. When I run the app, it works fantastic with the simulator, but it doesn't work with my device. I always get the following error message: file is not reachable. Ensure file URL is not a directory, symbolic link, or invalid url. As I said, when I run the code in the simulator, it works fine. I am using IOS 17.2 Here is the code. import SwiftUI import MobileCoreServices import Firebase import FirebaseStorage import CoreData import UniformTypeIdentifiers struct DocumentPickerView: UIViewControllerRepresentable { @Binding var fileContent : String @Binding var nameContent : String @Binding var showqr : Bool @Binding var documentURL: URL? @Binding var alert: Bool // @Binding var webViewURL : URL func makeCoordinator() -> Coordinator { Coordinator(self) } func makeUIViewController(context: Context) -> UIDocumentPickerViewController { // let picker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import) let types: [UTType] = [UTType.content] let picker = UIDocumentPickerViewController(forOpeningContentTypes:types) picker.allowsMultipleSelection = false picker.delegate = context.coordinator return picker } func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {} class Coordinator: NSObject, UIDocumentPickerDelegate { var parent: DocumentPickerView init(_ parent: DocumentPickerView) { self.parent = parent } func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { if let selectedURL = urls.first { parent.documentURL = selectedURL parent.uploadToFirebase(selectedURL) } } } func uploadToFirebase(_ fileURL: URL) { let storage = Storage.storage() let storageRef = storage.reference() let fileRef = storageRef.child(fileURL.lastPathComponent) // if FileManager.default.fileExists(atPath: fileURL.path){ // print("File Existiert:\(fileURL)") // } else { // print("File Existiert nicht") // } _ = fileRef.putFile(from: fileURL, metadata: nil){ (metadata, error) in if let error = error { print("Fehler beim Hochladen der Datei: \(error.localizedDescription)") } else { print("Datei erfolgreich hochgeladen!") // Rufen Sie die Download-URL für die hochgeladene Datei ab fileRef.downloadURL { (url, error) in if let error = error { alert = true print("Fehler beim Abrufen der Download-URL: \(error.localizedDescription)") } else { if let downloadURL = url { print("Download-URL: \(downloadURL)") self.fileContent = "\(downloadURL)" self.showqr = true } } } } } } }
2
0
1.2k
Nov ’23