gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 12:19:23 24 4
gpt4 key购买 nike

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

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

最佳答案

我认为您只想查看在 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)

关于swift - 在照片项目扩展中显示选定的照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45397152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com