最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - Downloading from Camera Roll - Stack Overflow

programmeradmin0浏览0评论

I am trying to download files from the camera roll of an attached iPhone using Swift, AppKit and the ImageCaptureCore framework.

It seems to work fairly well when the camera roll contains a relatively small number of files – like < 100 or so, however it becomes very slow and unreliable with a very large number – like 1500 (ie. doesn't successfully download all of the files or sidecar files).

I have also tried requesting the each item individually, then requesting the next item once that download has been completed, however that takes much, much longer with a large number of images, and seems to also not be reliable.

I would appreciate any suggestions or advice.

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 ?? "")")
    }
发布评论

评论列表(0)

  1. 暂无评论