1

Is there any way to find the current iPhoto library's path via code?

jscs
  • 62,161
  • 12
  • 145
  • 186
Alex Molskiy
  • 815
  • 1
  • 8
  • 14

1 Answers1

3

You can access the com.Apple.iApps plist file located in

/Users/userName/Library/Preferences/

Here you will find keys listing the most recent locations of iApp databases (including iTunes and iPhoto). This will allow you to automatically look towards the location of the iPhoto library no matter where the user has chosen to put it.

NSArray *libraryDatabases = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.apple.iApps"] objectForKey:@"iPhotoRecentDatabases"];
NSURL *libraryURL = (([libraryDatabases count])) ? [NSURL URLWithString:[libraryDatabases objectAtIndex:0]] : nil;

This NSURL returns the location of the current iPhoto library, if one exists.

Mick MacCallum
  • 124,539
  • 40
  • 277
  • 276
  • Thank you. It returns string like "file://localhost/...." and all space represented by special chars %20. I can not (or I don`t know) access this path with file manager. if ([fileMan fileExistsAtPath:[path stringByAppendingString:@"/Masters/"] isDirectory:NULL]) Is there simple way to convert this string to normal path or I should use stringreplace? – Alex Molskiy Sep 11 '12 at 20:58
  • @AlexMolskiy Hmm, I'm not exactly sure but you should be able to pass the url in string form through a "stringByReplacingOccurencesOf" to replace %20's with spaces, etc... – Mick MacCallum Sep 11 '12 at 21:03
  • Try with above code to get photo library path url, but its always nil. How can i get the iPad Photos library url in iOS8 programatically? – Jashu Jun 30 '15 at 13:17