【问题标题】:Is it possible to copy a file from the app sandbox to the app bundle?是否可以将文件从应用程序沙箱复制到应用程序包?
【发布时间】:2013-08-06 20:20:12
【问题描述】:

我可以通过以下方式进行相反的操作:但无法复制到应用程序包。

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,    NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];

// Destination path
    NSString *fileInDocumentsPath = [documentsPath stringByAppendingPathComponent:@"Passwords File.txt"];
// Origin path - used when file is in bundle
    NSString *fileInBundlePath = [[NSBundle mainBundle] pathForResource:@"Passwords File" ofType:@"txt"];

// File manager for copying File in Bundle to Sandbox
    NSError *error = nil;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager copyItemAtPath:fileInBundlePath toPath:fileInDocumentsPath error:&error];

【问题讨论】:

  • 我很确定不允许写入捆绑目录。它不是沙盒的一部分。
  • 一个应用包被签名,添加一个文件会破坏签名
  • 应用程序的包目录是只读的。

标签: ios appstore-sandbox


【解决方案1】:

应用程序包是只读的。部署应用后无法修改。

如果应用支持File Sharing,则可以通过 iTunes 访问应用文档文件夹中的文件。查看How to enable File Sharing for my app。

【讨论】:

  • 这是有道理的。我想要完成的是获取复制到我的 Mac 的文件的备份。有没有办法做到这一点?
  • @RonaldBledsoe,如果应用程序支持File Sharing,则可以通过 iTunes 访问应用程序文档文件夹中的文件。查看How to enable File Sharing for my app。
猜你喜欢
  • 2018-05-05
  • 1970-01-01
  • 2020-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-16
  • 1970-01-01
相关资源
最近更新 更多