【问题标题】:Which directory to save files to, according to Apple guidelines?根据 Apple 指南,将文件保存到哪个目录?
【发布时间】:2011-05-16 16:38:28
【问题描述】:

我正在编写一个将文本文件保存到设备的应用程序,例如购物车。

所以只有在使用应用程序时才需要它。

现在,网络上的教程中有很多目录,但没有人说我可以将文件保存到哪个目录并通过 Apple 的指导方针。

在我的设备上,我将文件保存到NSDocumentDirectory,如下所示:

NSArray *pfad = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *dokumente = [pfad objectAtIndex:0];

NSString *dateiname = [NSString stringWithFormat:@"%@/warenkorb.txt", dokumente];

有人知道这是否会通过 Apple 的审核并能够进入 App Store 吗?

【问题讨论】:

  • 请用英文编写代码,大多数人无法理解您的德文变量名。另外,我建议您使用 stringByAppendingPathComponent: 而不是 stringWithFormat: 来连接路径。

标签: objective-c cocoa-touch ios appstore-approval file-management


【解决方案1】:

文档目录是标准的,将被 Apple 接受。但最好使用stringByAppendingPathComponent 来形成完整路径。

NSString *dateiname = [dokumente stringByAppendingPathComponent:@"warenkorb.txt"];

【讨论】:

    【解决方案2】:

    请参阅A Few Important Application Directories 以选择合适的目录来存储您的文件。在您的情况下,听起来您想使用tmp 而不是Documents,因为这些文件不需要在应用程序启动之间保留或在设备同步时备份。

    请参阅Getting Paths to Standard Application Directories 以了解查找这些目录的建议方法。在这种情况下,您可能想使用NSTemportaryDirectory

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      • 1970-01-01
      • 2020-04-21
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多