swift - 在 Swift 中,有没有办法知道文件是否正在下载?
问题描述
我正在使用 Swift for macOS 创建一个应用程序。我想知道是否有一种方法可以确定是否正在下载文件,例如图片中的那个。
我尝试了 attributesOfItemAtPath,它返回以下键:
NSFileAttributeKey(_rawValue: NSFileSystemFileNumber)
NSFileAttributeKey(_rawValue: NSFileHFSTypeCode)
NSFileAttributeKey(_rawValue: NSFileReferenceCount)
NSFileAttributeKey(_rawValue: NSFileOwnerAccountName)
NSFileAttributeKey(_rawValue: NSFileCreationDate)
NSFileAttributeKey(_rawValue: NSFileExtensionHidden)
NSFileAttributeKey(_rawValue: NSFileGroupOwnerAccountID)
NSFileAttributeKey(_rawValue: NSFileOwnerAccountID)
NSFileAttributeKey(_rawValue: NSFileModificationDate)
NSFileAttributeKey(_rawValue: NSFileSystemNumber)
NSFileAttributeKey(_rawValue: NSFileGroupOwnerAccountName)
NSFileAttributeKey(_rawValue: NSFilePosixPermissions)
NSFileAttributeKey(_rawValue: NSFileSize)
NSFileAttributeKey(_rawValue: NSFileType)
NSFileAttributeKey(_rawValue: NSFileHFSCreatorCode)
NSFileAttributeKey(_rawValue: NSFileExtendedAttributes)
NSFileAttributeKey(_rawValue: NSFileProtectionKey)
我没有找到相关的条目,所以我尝试使用这个扩展:
extension FileManager {
func getEntireSpotlightInformation(path: String) -> [AnyHashable : Any]? {
guard self.fileExists(atPath: path) else {
return nil
}
let cfPath = path as CFString
let ref = MDItemCreate(kCFAllocatorDefault, cfPath)
let attributes = MDItemCopyAttributeNames(ref) as? Array<String>
var returnValue: [AnyHashable : Any]! = Dictionary()
for (index, item) in attributes!.enumerated() {
//print("Eccoci - index = \(index) - AttributeName = \(item)")
let cfAttribute = item as CFString
let result = MDItemCopyAttribute(ref, cfAttribute)
returnValue[item] = result
}
return returnValue
}
}
其中返回以下键:
kMDItemDateAdded
kMDItemContentCreationDate
kMDItemDocumentIdentifier
kMDItemInterestingDate_Ranking
kMDItemFSFinderFlags
kMDItemContentTypeTree
kMDItemContentType
kMDItemFSNodeCount
kMDItemDisplayName
kMDItemFSCreatorCode
kMDItemFSInvisible
kMDItemLogicalSize
_kMDItemDisplayNameWithExtensions
kMDItemFSIsExtensionHidden
kMDItemContentCreationDate_Ranking
kMDItemFSName
kMDItemContentModificationDate
kMDItemFSCreationDate
kMDItemFSOwnerGroupID
kMDItemPhysicalSize
kMDItemDownloadedDate
kMDItemKind
kMDItemDateAdded_Ranking
kMDItemFSOwnerUserID
kMDItemContentModificationDate_Ranking
kMDItemWhereFroms
kMDItemFSSize
kMDItemFSTypeCode
kMDItemFSContentChangeDate
kMDItemFSLabel
但是,再一次,我看不到任何有希望的东西。任何帮助是极大的赞赏。谢谢
解决方案
推荐阅读
- xcode - 为什么 AppDelegate 文件看不到 GameAnalytics 文件?
- java - W/audio_hw_generic:pcm_read 失败无法读取流数据:I/O 错误
- cordova - 托管 webapp 中的科尔多瓦插件 twilio_client_phonegap :科尔多瓦
- java - 如果 Web 服务关闭,如何重试?
- python - 列表理解中的 Python 嵌套循环和 Else 子句
- postman - 尝试在 Slack 中获取用户列表时如何修复错误
- r - 任何有效的方法来标记 R 中 3D 图中前 3 个 PCA 的数据点?
- windows - 设置挂载文件夹的权限 - 如何为组添加写权限?
- java - 如何收听(复制/拆分)System.out 消息
- javascript - d3.js Zoomable Circle Packing - 如何在缩放完成之前防止额外的点击事件