iOS 写入资产库观察结果
我正在尝试编写一个应用程序,从资产库读取图像,修改图像的 GPS 数据并将其写回资产库。我通过“枚举资产”方法将资产存储在 mutableArray 中。有关如何执行各个步骤的大部分详细信息,我是通过搜索此论坛获得的。谢谢!
我发现,当我通过“writeimagedatatosavedphotosalbum”方法写入第一个“资产”时,与资产 URL 关联的 mutableArray 的所有元素都变为 null。此外,我注意到写回图像不会替换原始图像,而是创建图像的第二个实例。
只是想我会将这些结果传递出去,以防其他人有疑问。当然,我会对其他人的评论、观察等感兴趣。
这个论坛为我提供了很好的信息。再次感谢。
I am attempting to write an app that reads images from the asset library, modifies the image's GPS data and writes it back to the asset library. I store the assets in a mutableArray via the "enumerating assets" methods. Most of the details on how to do the various steps, I got from searching this forum. Thanks!
I have found that when I write the first "asset" via the "writeimagedatatosavedphotosalbum" method, all the elements of the mutableArray associated with the assets' URL became null. Furthermore, I noticed that writing back an image does not replace the original image, but instead creates a second instance of the image.
Just thought I'd pass these results along, in case others had questions. And, of course, I'd be interested in other's comments, observations, etc.
This forum has provided me with great information. Thanks again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 ALAsset 对象仅在 ALAssetsLibrary 对象存在的时间内有效。当您获取 ALAsset 时,您需要在完成块中执行所需的所有操作,或者将 ALAssetsLibrary 存储在实例变量中,以便 ARC 不会释放它。
Your ALAsset object is only as good for the amount of time that your ALAssetsLibrary object is around. You either need to do everything you want in the completion block when you get the ALAsset, or store the ALAssetsLibrary in an instance variable so ARC does not deallocate it.
ALAsset 本质上是一个核心数据对象,可以从多个线程访问属性,但是 NSManagedObject 或 NSManagedObject 的子类没有意义。父 NSManagedObjectContext 与没有 ALAssetsLibrary 的 ALAsset 就没有意义一样。
通常的做法是将NSManagedObjectContext存储在AppDelegate上;当我将该功能抽象为包装器/单例时,在整个应用程序生命周期中都会保留对 NSManagedObjectContext 的引用。将相同的逻辑应用于ALAssetsLibrary,一切都会按预期工作。
An ALAsset is essentially a Core Data object who can have properties accessed from multiple threads but a NSManagedObject or a subclass of NSManagedObject does not make sense without a parent NSManagedObjectContext much in the same way an ALAsset doesn't make sense without an ALAssetsLibrary.
It is common practice to store the NSManagedObjectContext on the AppDelegate; and while I abstract that functionality into a wrapper/singleton there is a retained reference to the NSManagedObjectContext throughout the app lifecycle. Apply the same logic to the ALAssetsLibrary and everything will works as expected.