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

使用Swift、AppKit与ImageCaptureCore批量下载iPhone相机胶卷文件的性能及可靠性问题求助

Swift、AppKit与ImageCaptureCore批量下载iPhone相机胶卷文件的性能及可靠性问题求助

我现在在尝试用Swift、AppKit结合ImageCaptureCore框架,从连接的iPhone相机胶卷里下载文件。

当相机胶卷里的文件数量不多的时候(比如少于100个),整个流程运行得还算顺畅,但一旦文件数量很大(比如1500个左右),下载就变得特别慢,而且还不稳定——要么没法成功下载所有文件,要么连附带的侧载文件也下不全。

我也试过逐个请求下载,等当前文件下载完成后再请求下一个,但这种方式处理大量图片时耗时太长,而且同样不太可靠。

有没有大佬能给我一些建议或者解决方案呀?

import Foundation
import Cocoa
import ImageCaptureCore

func downloadCameraItems() {
        guard let downloadLocation else { return }
        let cd = cameraDevice.camDevice
        let downloadOptions : [ICDownloadOption : Any] = [.downloadsDirectoryURL: downloadLocation, .overwrite: false, .sidecarFiles: true]
        
        cameraItems.forEach { ci in
            print("requesting download of \(ci.name ?? "")")
            if let filename = ci.name {
                let fileURL = downloadLocation.appendingPathComponent(filename)
                if !FileManager.default.fileExists(atPath: fileURL.path) {
                    cd.requestDownloadFile(ci as! ICCameraFile, options: downloadOptions, downloadDelegate: self, didDownloadSelector: #selector(downloadItemCompleted), contextInfo: nil)
                    itemsRequested += 1
                } else {
                    print("Request: Skipping, file already exists: \(fileURL.path)")
                }
            }
        }
    }

    @objc func downloadItemCompleted(
        _ file: ICCameraFile,
        error: Error?,
        options: [AnyHashable: Any]?,
        contextInfo: UnsafeMutableRawPointer?
    ) {
        print("*** Download: File downloaded - \(file.name ?? "")")
    }

备注:内容来源于stack exchange,提问作者psb

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.15 10:34:27