我正在尝试创建一个将所选声音文件复制到应用程序目录的应用程序。为此,我编写了以下代码:
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
。这段代码有什么问题?