在照片项目扩展中显示选定的照片

Display selected photos in Photos Project extension

我找不到足够的文档来开始使用 Photos Project 扩展(在 High Sierra 中可用)。

如何检索用户选择的内容(例如 Apple 如何使用他们的 Prints 扩展),并在我的扩展视图中显示?

我认为您只想查看在 beginProject 中传递给您的 PHPProjectInfo。这就是您获得所选内容的真实背景的地方。例如:

let sections = projectInfo.sections
guard let firstContentSection = sections.first(where: { section in    section.sectionType == .content }),
let firstContents = firstContentSection.sectionContents.first

然后您需要将云标识符转换为本地标识符以进行提取:

localIdentifiers = context.photoLibrary.localIdentifiers(for: cloudIdentifiers)

从那里,您可以获取实际的 PHAssets:

let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: localIdentifiers, options: nil)

对于任何 PHAsset,当您想要使用 PHImageManager 的图像时:

imageManager.requestImage(for: asset, targetSize: targetSize, contentMode: PHImageContentMode.aspectFit, options: nil)