如何避免将重复图像复制到 iPhone 照片库?
我正在编写一个简单的应用程序,将一组图像复制到用户的照片库,以便用户可以将它们用作背景。问题是,如果用户多次运行该应用程序,重复的图像将被复制到照片库中。鉴于 Apple 对访问照片库内容的限制,避免将重复文件写入库的最简单方法(如果有)是什么?
本
I am writing a simple application to copy a set of images to the user's photo library so that the user may use them as backgrounds. The problem is that if the user runs the application more than once, duplicate images will be copied to the photo library. Given the restrictions Apple places on accessing the contents of the photo library, what is the simplest way, if any, to avoid writing a duplicate file to the library?
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过将应用程序中保存的图像数据写入文件或使用 Core Data 来存储它们,这样您就知道哪些已保存,哪些尚未保存。是
You can store the images data that have been saved in your application by writing them to a file or using Core Data, that way you know which have been saved and which have not. Y
这个答案有点迟了,但迟到的答案总比没有答案好。答案是无法检查照片库 (PL) 中是否存在重复图像(至少在公共 API 的限制内)。写入照片库的唯一方法是通过 UIKit 全局函数:
此代码只是将 UIImage 的实例写入照片库。它的四个参数都不代表可能与图像一起保存的附加的、潜在的识别对象。它包装的 UIImage 或 CGImage 也不为此类“元数据”提供插槽。当然,我们总是可以子类化,但不幸的是没有办法检查 PL 的内容。 PL 是一种只写持久存储,其内容(至少就 API 程序员而言)本质上是匿名的。就像黑洞一样,照片库有一个“单向表面”。
This answer is somewhat belated, but a late answer is better than no answer at all. The answer is that there is no way to check the photo library (PL) for a duplicate image (at least within the constraints of the public API). The only way to write to the photo library is via the UIKit global function:
This code simply writes the instance of UIImage to the photo library. None of its four parameters represent an additional, potentially identifying, object that might be saved with the image. Nor does the UIImage or the CGImage it wraps provide a slot for "metadata" of this sort. Of course, one can always subclass, but unfortunately there is no way to inspect the contents of the PL. The PL is a write-only persistent store whose contents, at least as far as the API programmer is concerned, are essentially anonymous. Like a black hole, the photo library has a "one-way surface."