You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift中Failed to associate thumbnails错误排查与修复求助

UIDocumentPicker选择PDF上传Firebase时出现QLThumbnailErrorDomain Code=102错误

问题场景

开发ML2V_IOS应用时,通过UIDocumentPickerViewController选择PDF文件,上传至Firebase Storage并同步更新Firestore关联发票(业务中称为solde)文档时,控制台输出以下错误日志:

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}}}

相关业务代码位于UserSolde.swift和Solde.swift。

错误原因

  • 该错误属于iOS系统Document Manager的内部问题,和你的Firebase上传、Firestore同步业务代码无关
  • 本质是系统将选中的文件复制到APP临时Inbox目录时,尝试给副本关联原文件的缩略图失败,底层提示"Generation not found"(找不到文件版本),这种问题几乎只出现在模拟器环境,真机上极少发生,大概率是模拟器文件系统的缓存或iCloud同步异常导致

修复/规避方法

  • 直接忽略:该错误仅为日志输出,不会影响文件上传、Firestore更新等核心业务流程,终端用户无感知
  • 模拟器环境临时解决:
    • 重置模拟器:通过Hardware > Erase All Content and Settings清除模拟器缓存
    • 重启Xcode和模拟器,重新安装应用
    • 测试时优先选择本地文件,避免选择iCloud Drive中的文件(模拟器对iCloud文件的缩略图处理兼容性较差)
  • 代码优化(可选):若需消除日志,可在UIDocumentPickerDelegate的回调中,自行通过Quartz框架渲染PDF第一页生成缩略图,不依赖系统的缩略图关联逻辑:
    func generatePDFThumbnail(url: URL, size: CGSize) -> UIImage? {
        guard let document = CGPDFDocument(url as CFURL) else { return nil }
        guard let page = document.page(at: 1) else { return nil }
        
        let pageRect = page.getBoxRect(.mediaBox)
        let scale = min(size.width / pageRect.width, size.height / pageRect.height)
        let renderer = UIGraphicsImageRenderer(size: CGSize(width: pageRect.width * scale, height: pageRect.height * scale))
        
        return renderer.image { context in
            UIColor.white.setFill()
            context.fill(CGRect(origin: .zero, size: renderer.format.bounds.size))
            context.cgContext.scaleBy(x: scale, y: scale)
            context.cgContext.drawPDFPage(page)
        }
    }
    

内容的提问来源于stack exchange,提问作者Windows Frame

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 14:37:07