在iCloud中更新UIDocument的缩略图

时间:2017-10-20 15:36:20

标签: swift icloud uidocument

我有UITableViewController,其中显示NSMetaDataItem的列表,这些列表连接到StoryDocument子类UIDocument。每个StoryDocument都有一个名为UIImage的{​​{1}}属性。每行显示它的缩略图。

我已覆盖image以保存缩略图,如下所示:

fileAttributesToWrite(to: URL, for: UIDocumentSaveOperation)

我在override func fileAttributesToWrite(to url: URL, for saveOperation: UIDocumentSaveOperation) throws -> [AnyHashable : Any] { let thumbnailSize = CGSize(width: 1024, height: 1024) if let thumbnail = image?.at(targetSize: thumbnailSize) { return [ URLResourceKey.hasHiddenExtensionKey : true, URLResourceKey.thumbnailDictionaryKey : [ URLThumbnailDictionaryItem.NSThumbnail1024x1024SizeKey : thumbnail ] ] } else { return [:] } } 设置了缩略图,其中url是网址func tableView(_:, cellForRowAt:)

metadataItems.value(forAttribute: NSMetadataItemURLKey)

如果我在详情视图中更改了do { var thumbnailDictionary: AnyObject? let nsurl = url as NSURL try nsurl.getPromisedItemResourceValue(&thumbnailDictionary, forKey: URLResourceKey.thumbnailDictionaryKey) cell.thumbnailImageView.image = thumbnailDictionary?[URLThumbnailDictionaryItem.NSThumbnail1024x1024SizeKey] as? UIImage } catch { cell.thumbnailImageView.image = nil } 的{​​{1}}然后返回StoryDocument,即使我告诉我,仍会显示原始缩略图(未更改) imageUITableViewController。当下一个UITableViewreloadData()通知进入时,图片只会在大约10秒后更新。是否有一种很好的方法可以获取最近更改过的缩略图而不是旧的缩略图?

我正在使用Swift 4,虽然我希望我也可以在Swift 3中调整建议。

非常感谢提前。

0 个答案:

没有答案