我可以用以下方法做相反的操作:但不能複製到應用程序包。是否可以將應用程序沙箱中的文件複製到應用程序包?
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];
我很確定寫入捆綁目錄是不允許的。它不是沙盒的一部分。 – Steveo
應用程序包已簽名,添加文件以破壞簽名 – AlexWien
該應用程序包的目錄是隻讀的。 –