1
我試圖創建一個應用程序,它將選定的聲音文件複製到應用程序的目錄中。要做到這一點,我已經寫了下面的代碼:使用NSOpenPanel並複製選定的文件 - Objective-C
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:YES];
[openDlg setAllowsMultipleSelection:NO];
[openDlg setCanChooseDirectories:NO];
[openDlg setAllowedFileTypes:[NSArray arrayWithObjects:@"aif",@"aiff",@"mp3",@"wav",@"m4a",nil]];
if ([openDlg runModalForDirectory:nil file:nil] == NSOKButton)
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dataPath = [[NSBundle mainBundle] bundlePath];
NSLog(@"Datapath is %@", dataPath);
NSLog(@"Selected Files : %@",[[openDlg URLs] objectAtIndex:0]);
if ([fileManager fileExistsAtPath:dataPath] == NO)
{
[fileManager copyItemAtPath:[[openDlg URLs] objectAtIndex:0] toPath:[[NSBundle mainBundle] bundlePath] error:&error];
NSLog(@"File copied");
}
}
的問題是,我可以選擇文件中的每個類型(不僅是AIF,WAV,MP3等),我從來沒有得到File copied
。雖然,路徑是正確的。當我刪除if語句時,出現錯誤:[NSURL fileSystemRepresentation]: unrecognized selector sent to instance 0x1005a0b90
。 這段代碼有什麼問題?
非常感謝! – user2331955 2013-05-03 11:00:06