選択したサウンド ファイルをアプリのディレクトリにコピーするアプリを作成しようとしています。それを行うために、私は次のコードを書きました:
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
。このコードのどこが間違っていますか?