How to access Media section (Photo & Movies) directly from NSOpenPanel in Mac OS X application?

拈花ヽ惹草 提交于 2019-12-12 05:38:59

问题


I already refered this link

iMedia

Now i am using NSOpenPanel to open iPhoto library folder.

Here is the code which allow to open.

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]);
    }
}

This code always open my Finder library folder, As i want to open Media Photo and Movies folder directly.

Please give me any solution.

I have attached here one screen shot.

Thanks & Regards,


回答1:


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

This won't help if the user has moved his iPhoto library to some non-standard location.




回答2:


There is a private API of Apple that contains exactly the control you want to access; this control is an ILMediaBrowserView and provides the exact same view than the one in NSOpenDialog. If you are planning an AppStore release of your app don't use it but it can be useful. The framework to integrate to your project to get that view is iLifeMediaBrowser.framework in /System/Library/PrivateFrameworks.



来源:https://stackoverflow.com/questions/15815183/how-to-access-media-section-photo-movies-directly-from-nsopenpanel-in-mac-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!