1

I'm developing an iMac desktop application which is able to upload normal photos as well as Photos library (Previously iPhotos library) to online services like Flickr,SmugMug. Before upgrading to Sierra i was able to get details of iPhotos and could upload too but after upgradation those files/directories doesn't exist.

Below is the block by which i was getting files:

string PhotosLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Photos Library.photoslibrary/Database/apdb/Library.apdb");

But above is not working anymore in Sierra 10.12, if i go to finder itself to locate above mentioned path then i find 'Database' directory but no 'apdb' is there by which i can get Library.apdb

I have googled but no luck, can anybody please show me some pointers on how to get Photos Library files using C#.

Please tell me if i missed any information to share. Thanks.

Saurav Anand
  • 41
  • 1
  • 4

1 Answers1

1

The Media Library Framework is the place to go if your situation permit.

NSDictionary<NSString, NSObject> options = new NSDictionary<NSString, NSObject>(
    new[] { MLMediaLibrary.MediaLoadSourceTypesKey, MLMediaLibrary.MediaLoadIncludeSourcesKey },
    new[] { new NSString(MLMediaSourceType.Image.ToString()), MLMediaSource.MediaSourcePhotosIdentifier }
);
var ml = new MLMediaLibrary(options);
ml.AddObserver("mediaSources", 0, (obj) => Console.WriteLine("Loaded"));
var src = ml.MediaSources; // returns null first time

In order to access MLMediaLibrary, your application has to be sandboxed and codesigned.

See also https://stackoverflow.com/a/29626032 to learn how to deal with entitlements.plist.

Community
  • 1
  • 1
ailen0ada
  • 13
  • 2
  • For this i need to change/update xamarin studio channel to Alpha from Stable? And then need to add key in entitlements file? – Saurav Anand Apr 18 '17 at 06:11
  • It does not matter whether the channel is alpha or stable. Just add key and value in entitlements.plist – ailen0ada Apr 18 '17 at 15:28
  • This library is non-trivial to get working. I have a slightly larger example here: https://gist.github.com/chamons/9f9b6aa1f4b45ba8603cd5ba09a79b1f – Chris Hamons Apr 19 '17 at 17:16