Iterate through photo library on OS X?

后端 未结 1 1578
一整个雨季
一整个雨季 2020-12-18 08:52

I\'m trying to iterate through a user\'s photo library on OS X. On iOS, I would use the Photos framework, but apparently that\'s not available on OS X, and we\'re supposed

相关标签:
1条回答
  • 2020-12-18 09:16

    This framework isn't hard to work with, but it is tedious because it async/lazy loads the properties, and KVO is the only want to be notified about the async completion.

    If you want to iterate the photos, you don't need to know the identifiers in advance.

    Create a media library:

    self.library = [[MLMediaLibrary alloc] initWithOptions:options];

    Add a KVO observer for mediaSources. Access mediaSources, if non-nil, go to the next step, otherwise go to the next step when your KVO observer fires.

    In the next step, iterate the sources, add a KVO observer on rootMediaGroup, and access rootMediaGroup on each source. If it is non-nil, call your iterator now, otherwise call it from the KVO notification handler.

    For each rootMediaGroup, follow the same strategy as above, but for mediaObjects. The media objects are the things you are ultimately after.

    0 讨论(0)
提交回复
热议问题