使用 NSUserDefaults 将大图像文件存储在二进制字符串中不成功,还有其他解决方案吗?
我尝试放置我的自定义对象,该对象具有字符串和使用 NSUserDefaults 的图像存储,但我发现图像太大而无法存储。那么,还有其他解决方案来应对吗?我想以二进制格式存储它,而不是写入文件。
来自控制台的错误: * -[NSKeyedUnarchiver initForReadingWithData:]:数据为 NULL
谢谢。
I try to put my customized object, which have string and an image store using NSUserDefaults, but I found out that the image is too big that I can't store. So, any other solutions to deal with it? I would like to store it in a binary format, instead of writing a file.
The error from console:
* -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一种可能的解决方案是将其存储在核心数据中。在那里您可以指定将其保存为二进制数据。
Another possible solution is storing it in Core Data. There you can specify to save it as binary data.
直接来自 Apple 文档。
你应该使用 NSKeyedArchiver 类。请参阅此链接保存用户创建的数据。
directly from Apple Documentation.
you should use NSKeyedArchiver class. refer this link saving data created by the user.
将此图像存储在您的文档目录中,并将路径保存在您的 NSUserDefault 中。
您可以像这样访问文档目录
Store this image in your document directory and save the path in your NSUserDefault.
You can access to the document directory like that