我一直找不到足够的文档来开始照片项目扩展(在 High Sierra 中可用)。
如何检索用户选择的内容(例如 Apple 如何使用其 Prints 扩展程序进行操作),并将其显示在我的扩展程序视图中?
我一直找不到足够的文档来开始照片项目扩展(在 High Sierra 中可用)。
如何检索用户选择的内容(例如 Apple 如何使用其 Prints 扩展程序进行操作),并将其显示在我的扩展程序视图中?
我认为您只想查看在 beginProject 中传递给您的 PHProjectInfo。这就是您获得所选内容的真实背景的地方。例如:
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)
从那里,您可以获取实际的 PHAsset:
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: localIdentifiers, options: nil)
对于任何 PHAsset,当您想要使用 PHImageManager 的图像时:
imageManager.requestImage(for: asset, targetSize: targetSize, contentMode: PHImageContentMode.aspectFit, options: nil)