Swift Failed to associate thumbnails for picked URL file

143 Views Asked by At

I would like to understand what this error come from : The error

This the error from text :

2023-09-07 12:16:50.304646+0200 ML2V_IOS[4697:148814] [DocumentManager] Failed to associate thumbnails for picked URL file:///Users/clement/Library/Developer/CoreSimulator/Devices/0F76A94C-620C-405E-8761-545CC2C583D3/data/Containers/Shared/AppGroup/75D64675-C770-4EED-8CF4-39606A85E838/File%20Provider%20Storage/Facture_gggggg.pdf with the Inbox copy file:///Users/clement/Library/Developer/CoreSimulator/Devices/0F76A94C-620C-405E-8761-545CC2C583D3/data/Containers/Data/Application/1B7A183D-2658-478F-AB87-FCB46C780168/tmp/SMW.ML2V-IOS-Inbox/Facture_gggg.pdf: Error Domain=QLThumbnailErrorDomain Code=102 "(null)" UserInfo={NSUnderlyingError=0x600001927e70 {Error Domain=GSLibraryErrorDomain Code=3 "Generation not found" UserInfo={NSDescription=Generation not found}}}

My goal is to send file and an update to my firestore and my firebase to link the document to my file. Nothing really hard normally but ... I just finished to build the code but this error show up and nothing seems to be wrong from my code... This is the following swift code :

//
//  UserSolde.swift
//  ML2V_IOS
//
//  Created by Clément Enjolras on 05/09/2023.
//

import SwiftUI
import FirebaseStorage
import UIKit
import MobileCoreServices

struct UserSolde: View {
    @EnvironmentObject var viewModel: AuthViewModel
    @StateObject var soldemodel = SoldeModel()
    @State private var soldes: [Solde] = []
    @State private var isDocumentPickerPresented = false
    @State private var selectedURL: URL?
    @State private var selectedSoldeID: String? = nil
    @State private var selectedSoldeOwner: String? = nil
    
    var body: some View {
        content.onAppear{
            Task{
                do{
                    try await soldemodel.getAllSolde()
                    soldes = soldemodel.resultsolde
                }catch{
                    print("Erreur lors de la récupération des soldes : \(error)")
                }
            }
        }
    }
    
    var content: some View{
        VStack{
            HStack{
                Text("Mes Soldes").font(.system(size: 24).bold())
                Spacer()
                Image(systemName: "creditcard")
                    .font(.system(size: 32))
                    .foregroundColor(.black)
                    .frame(width: 32, height: 32)
                    .background(Color(.white))
            }.padding(.horizontal)
            
            List($soldes){ solde in
                
                HStack{
                    VStack{
                        Text("Total du solde en cours").font(.system(size: 14)).multilineTextAlignment(.center)
                        Text("\(solde.total.wrappedValue)").padding(.top,5).font(.system(size: 12)).foregroundColor(.gray).multilineTextAlignment(.center)
                    }
                    Spacer()
                    VStack{
                        Text("Etat de la demande").font(.system(size: 14)).multilineTextAlignment(.center)
                        Text("\(solde.etat.wrappedValue)").padding(.top,5).font(.system(size: 12)).foregroundColor(.gray).multilineTextAlignment(.center)
                    }
                    Spacer()
                    VStack{
                        Text("Date d'émission").font(.system(size: 14)).multilineTextAlignment(.center)
                        Text("\(solde.date.wrappedValue)").padding(.top,5).font(.system(size: 12)).foregroundColor(.gray).multilineTextAlignment(.center)
                    }
                    Spacer()
                    Button {
                        selectedSoldeID = solde.id
                        selectedSoldeOwner = solde.proprietaire.wrappedValue
                        isDocumentPickerPresented.toggle()
                            } label: {
                                Text("Envoyer la facture").multilineTextAlignment(.center)
                            }.sheet(isPresented: $isDocumentPickerPresented) {
                                DocumentPickerView(selectedURL: $selectedURL,soldeDataId:$selectedSoldeID,soldeOwner:$selectedSoldeOwner)
                            }
                }
            }
            
            Button {
                
            } label: {
                HStack{
                    Text("DEMANDER MON SOLDE").fontWeight(.semibold)
                    Image(systemName: "arrow.right")
                    
                }.foregroundColor(.white)
                    .frame(width: UIScreen.main.bounds.width - 32, height: 48)
            }.background(Color(.systemBlue)).cornerRadius(10).padding(.top,24)
            
        
            NavigationLink {
                UserDashboard().navigationBarBackButtonHidden(true)
            } label: {
                HStack(spacing: 3){
                    Text("Retour à la page")
                    Text("Principale").fontWeight(.bold)
                }.font(.system(size: 14))
            }
        }
    }
}

private func formatDate(_ date: Date) -> String {
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "dd/MM/yyyy"
    return dateFormatter.string(from: date)
}

//Mettre à jour firestore et firebase avec la facture
func uploadInvoice(url:String,iddocument:String,filename:String){

}

struct DocumentPickerView: UIViewControllerRepresentable {
    @Binding var selectedURL: URL?
    @Binding var soldeDataId: String?
    @Binding var soldeOwner: String?
    @EnvironmentObject var soldeModel: SoldeModel

    func makeUIViewController(context: Context) -> some UIViewController {
        let controller = UIDocumentPickerViewController(forOpeningContentTypes: [.png,.pdf,.jpeg,], asCopy: true)
        controller.delegate = context.coordinator
        return controller
    }

    func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
        
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    class Coordinator: NSObject, UIDocumentPickerDelegate {
        let parent: DocumentPickerView

        init(_ parent: DocumentPickerView) {
            self.parent = parent
        }

        private func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) async {
            if let selectedURL = urls.first {
                parent.selectedURL = selectedURL
                if let soldeDataid = parent.soldeDataId{
                    let filename = selectedURL.lastPathComponent
                    let storageRef = Storage.storage().reference().child("invoices/\(parent.soldeOwner ?? "unknow")/\(parent.soldeDataId ?? "solde")/\(filename)")
                    
                    storageRef.putFile(from: selectedURL, metadata: nil) { metadata, error in
                        if let error = error {
                            print("Erreur lors de la mise à jour du fichier Firebase Storage : \(error.localizedDescription)")
                        } else {
                            print("Fichier mis à jour avec succès dans Firebase Storage")
                        }
                    }
                    do {
                        try await parent.soldeModel.sendInvoiceFileName(filename: filename, idsoldedocuement: soldeDataid)
                        print("Nom du fichier envoyé à Firebase Firestore avec succès.")
                    } catch {
                        print("Erreur lors de l'envoi du nom du fichier à Firebase Firestore : \(error)")
                    }
                }
            }
        }
    }
}

struct UserSolde_Previews: PreviewProvider {
    static var previews: some View {
        UserSolde()
    }
}

For people who ask me what is "solde" it's like an invoice for me. this is the code :

//
//  Solde.swift
//  ML2V_IOS
//
//  Created by Clément Enjolras on 05/09/2023.
//

import Foundation

struct Solde: Identifiable,Codable{
    var id: String
    var date: Date
    var etat: String
    var facture: String
    var proprietaire: String
    var total:Int
}

The error come from my code ? the simulator ? or this is a bug from iOS ? how can I fix this problem. I'm new into swift development if somebody can explain me I will be so thankful

0

There are 0 best solutions below