Error Domain=NSCocoaErrorDomain Code=257

Hello, I have created a documentspicker to select a PDF file and then upload it to storage, but I am getting this error only on my device; it works correctly on the simulator.

This is my code:

    
    @Binding var alertShow:Bool
    
    var detailpet:String = ""
    
    func makeCoordinator() -> Coordinator {
        return DocumentPicker.Coordinator(parent1: self)
    }
    
    
    func makeUIViewController(context: UIViewControllerRepresentableContext<DocumentPicker>) ->  UIDocumentPickerViewController {
        
        let picker = UIDocumentPickerViewController(forOpeningContentTypes: [.pdf])
        picker.allowsMultipleSelection = false
        picker.delegate = context.coordinator
        return picker
        
    }
    
    func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: UIViewControllerRepresentableContext<DocumentPicker>) {

        
    }
    
    class Coordinator : NSObject, UIDocumentPickerDelegate {
        
        var parent:DocumentPicker
        
        init(parent1: DocumentPicker){
            
            parent = parent1
        
        }
        
        func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls:[URL]) {
            
            let bucket = Storage.storage().reference()
            let db = Firestore.firestore()
            let collection = "documents"
            
            
            guard let url = urls.first, url.startAccessingSecurityScopedResource() else {
                return
            }
            
            DispatchQueue.main.async {
                url.stopAccessingSecurityScopedResource()
                print("Documents Picker stop")
            }
            
            let referenceDocument = bucket.child("docu/\(url.deletingPathExtension().lastPathComponent)")
            
            let _ = referenceDocument.putFile(from:url, metadata: nil) {
                metadata , error in
                
                guard metadata != nil else{
                    print("Error \(String(describing: error?.localizedDescription))")
                    return
                }
                
                referenceDocument.downloadURL { url, error in
                    guard let url = url else {
                        print("Message error \(String(describing: error?.localizedDescription))")
                        return
                    }

                    let _ = try?  db.collection(collection).addDocument(from:DocumentData(idpet:self.parent.detailpet, name: "\(url.deletingPathExtension().lastPathComponent).pdf", url: url.absoluteString))

                }
                print("Succes")
                self.parent.alertShow.toggle()
            }
        }
    }
    
}

t seems to be a permissions issue, I believe. Do you know how I can fix this? It's my first application. Thank you.

Error 257 is the Cocoa .fileReadNoPermission error. Which specific API raised that error?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Error Domain=NSCocoaErrorDomain Code=257
 
 
Q