在 iOS 上将数据保存到磁盘

Saving data to disk on iOS

我的申请被拒绝了,原因如下:

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 但最终不会保存在 "user's iCloud",而不是使用 CoreData

是的,有办法。 您可以使用 NSKeyedArchiverNSKeyedUnarchiver 存储数据。 NSKeyedArchiver 用于保存您的数据。一个例子:

[NSKeyedArchiver archiveRootObject:counters toFile:filePath];

filePath 的扩展名应该是 .plistcounters 在这种情况下是一个数组。

NSKeyedUnarchiver 用于加载您的数据。一个例子:

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
    counters = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
}

如果您想存储您的自定义 class,您需要实施 NSCoding 协议。