admin管理员组文章数量:1336631
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 ?? "")")
}
本文标签: swiftDownloading from Camera RollStack Overflow
版权声明:本文标题:swift - Downloading from Camera Roll - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742412655a2470097.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论