On button click how to directly search all iPhoto/photos Libraries available on mac

60 Views Asked by At

I am developing an app where on a button click a user can get all iphoto libraries available on mac. By using NSOpenPanel I can manually ask the user to select the library but I want that to happen automatically.

Here is the code:

-(void)checkinPicturesFolder{

    int i = 0;
    NSOpenPanel* openDlg = [NSOpenPanel openPanel];
    [openDlg setCanChooseFiles:YES];
    [openDlg setAllowsMultipleSelection:TRUE];
    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];

    if ( [openDlg runModal] == NSModalResponseOK )
    {
        NSArray *files = [openDlg URLs];
        for( i = 0; i < [files count]; i++ )
        {
            NSLog(@"File path: %@", [[files objectAtIndex:i] path]);
        }
    }   
}
0

There are 0 best solutions below