在iOS上将数据保存到磁盘

时间:2015-08-06 10:18:24

标签: ios objective-c swift core-data nsuserdefaults

我的申请因以下原因被拒绝:

App Review
1.0 Binary Rejected August 5, 2015
2.23 Details On launch and content download, your app stores 9.51 MB on the user's iCloud, which does not comply with the iOS Data Storage

尽我所知(如果我错了,请纠正我),因为我在NSUserDefaults上节省了太多(我不保存在其他任何地方)。

所以这是我的问题:是否有一种快速,简便的方法可以在本地保存数据(类似NSUserDefaults但不会最终保存在“用户的iCloud”上,而不是使用CoreData

1 个答案:

答案 0 :(得分:2)

是的,有办法。 您可以使用NSKeyedUnarchiverNSKeyedArchiver存储数据。 [NSKeyedArchiver archiveRootObject:counters toFile:filePath]; 用于保存您的数据。一个例子:

filePath

.plist的扩展名应为counters;在这种情况下,NSKeyedUnarchiver是一个数组。

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { counters = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath]; } 用于加载您的数据。一个例子:

NSCoding

如果要存储自定义类,则需要实现put_file_contents()协议。

相关问题