本文介绍了如何在Mac OS X应用程序中直接从NSOpenPanel访问“媒体"部分(照片和电影)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经引用了此链接
现在我正在使用NSOpenPanel打开iPhoto库文件夹.
Now i am using NSOpenPanel to open iPhoto library folder.
这是允许打开的代码.
int i = 0;
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:YES];
[openDlg setAllowedFileTypes:[NSArray arrayWithObjects:@"public.image",@"public.video",nil]];
[openDlg setAllowsMultipleSelection:TRUE];
[openDlg setAllowsOtherFileTypes:NO];
if ( [openDlg runModal] == NSOKButton )
{
NSArray *files = [openDlg URLs];
for( i = 0; i < [files count]; i++ )
{
NSLog(@"File path: %@", [[files objectAtIndex:i] path]);
}
}
此代码始终打开我的Finder库文件夹,因为我想直接打开Media Photo and Movies文件夹.
This code always open my Finder library folder, As i want to open Media Photo and Movies folder directly.
请给我任何解决方案.
我在这里附上了一个屏幕截图.
I have attached here one screen shot.
感谢&问候
推荐答案
您可以考虑添加以下代码段:
You may consider adding the following code snipet:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
NSURL *picturesURL = [fileManager URLForDirectory:NSPicturesDirectory inDomain:NSUserDomainMask appropriateForURL:NULL create:NO error:&error];
NSURL *iPhotoURL = [picturesURL URLByAppendingPathComponent:@"iPhoto Library.photolibrary"];
[openDlg setDirectoryURL:iPhotoURL];
// Now run the dialog
如果用户将其iPhoto库移动到了一些非标准位置,这将无济于事.
This won't help if the user has moved his iPhoto library to some non-standard location.
这篇关于如何在Mac OS X应用程序中直接从NSOpenPanel访问“媒体"部分(照片和电影)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!