2013-08-06 45 views
2

我可以用以下方法做相反的操作:但不能複製到應用程序包。是否可以將應用程序沙箱中的文件複製到應用程序包?

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]; 
+0

我很確定寫入捆綁目錄是不允許的。它不是沙盒的一部分。 – Steveo

+0

應用程序包已簽名,添加文件以破壞簽名 – AlexWien

+0

該應用程序包的目錄是隻讀的。 –

回答

6

應用程序包是隻讀的。在部署應用程序後它不能被修改。

如果應用支持File Sharing,則可以通過iTunes訪問應用文檔文件夾中的文件。檢查出How to enable File Sharing for my app

+0

這很有道理。我試圖完成的是獲取複製到我的Mac的文件的備份。有沒有辦法做到這一點? –

+0

@RonaldBledsoe,如果應用程序支持[文件共享](http://support.apple.com/kb/HT4094),則可以通過iTunes訪問應用文檔文件夾中的文件。看看[如何爲我的應用程序啓用文件共享](http://stackoverflow.com/questions/6029916/how-to-enable-file-sharing-for-my-app)。 –

相關問題