Created
February 12, 2013 02:33
-
-
Save glebd/4759724 to your computer and use it in GitHub Desktop.
Determine iPhoto library location with and without sandbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSString *)libraryPath { | |
#ifdef APPSTORE | |
// Sandbox prevents us from accessing other apps' preferences. | |
// So we get a r/o access to ~/Library/Preferences/ and read the files directly. | |
// | |
// Need the following entitlement: | |
// | |
// <key>com.apple.security.temporary-exception.files.home-relative-path.read-only</key> | |
// <array> | |
// <string>/Library/Preferences/</string> | |
// </array> | |
// http://stackoverflow.com/a/10955994 | |
const char *home = getpwuid(getuid())->pw_dir; | |
NSString *homePath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:home length:strlen(home)]; | |
NSString *plistPath = [homePath stringByAppendingPathComponent:@"Library/Preferences/com.apple.iPhoto.plist"]; | |
NSDictionary *iPhotoPrefs = [NSDictionary dictionaryWithContentsOfFile:plistPath]; | |
return [iPhotoPrefs objectForKey:@"LibraryPath"]; | |
#else | |
CFStringRef appId = (__bridge CFStringRef)iPhotoBundleID; | |
return [(NSString *)CFBridgingRelease(CFPreferencesCopyAppValue(CFSTR("LibraryPath"), appId)) stringByExpandingTildeInPath]; | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment