【问题标题】:Saving data to disk on iOS在 iOS 上将数据保存到磁盘
【发布时间】:2015-08-06 10:18:24
【问题描述】:

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

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?

【问题讨论】:

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


【解决方案1】:

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

[NSKeyedArchiver archiveRootObject:counters toFile:filePath];

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

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

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

如果你想存储你的自定义类,你需要实现NSCoding协议。

【讨论】:

  • 好的,现在我可以使用类似的东西: let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) let documentsDirectory = paths[0] as String let fileName = "(documentsDirectory)/file1 " 代表 "fileName"?
  • 是的,应该可以。如果没有,请尝试将.plist 放在路径的末尾。
  • 好的,一般情况下,如果我将那样的内容保存到文档目录中,我的应用程序不会被拒绝?
  • 不,不会。这实际上是少量的数据。
猜你喜欢
  • 1970-01-01
  • 2010-11-29
  • 2013-09-09
  • 1970-01-01
  • 1970-01-01
  • 2020-07-18
  • 2011-12-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多