我在這裏找到了這篇帖子。它在iPad模擬器模式下按照預期工作,但在切換到實際的iPad設備模式時無法使用。相反,它提出了「沒有這樣的文件存在」的錯誤信息。在執行這些代碼之前,我確實通過右鍵單擊xxxxxx.app創建了一個Populator文件夾,然後選擇「顯示包內容」並將一些文件放入Populator文件夾。 Xcode是否將整個應用程序包複製到iPad設備上?有什麼建議麼?無法將文件從主包複製到iPad上的文檔目錄
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Populator"];
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"Files"];
NSLog(@"Source Path: %@\n Documents Path: %@ \n Folder Path: %@", sourcePath, documentsDirectory, folderPath);
NSLog(@"docdire: %@", documentsDirectory);
NSLog(@"loadImage button clicked");
label.text = [@"sourcePath: " stringByAppendingString:sourcePath];
textField.text = [@"clicked: " stringByAppendingString:documentsDirectory];;
NSError *error;
if([[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:folderPath error:&error]){
NSLog(@"File successfully copied");
label.text = @"copy succeeded";
} else {
NSLog(@"Error description-%@ \n", [error localizedDescription]);
NSLog(@"Error reason-%@", [error localizedFailureReason]);
label.text = [@"Error description: " stringByAppendingString:[error localizedDescription]];
label2.text = [@"Error reason: " stringByAppendingString:[error localizedFailureReason]];
}
我發現有2個地方有xxxxx.app包。一個用於模擬器,另一個用於構建分佈。 – user523234 2011-06-01 00:42:03