【问题标题】:Display selected photos in Photos Project extension在照片项目扩展中显示选定的照片
【发布时间】:2017-08-01 21:26:59
【问题描述】:

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

如何检索用户选择的内容(例如 Apple 如何使用其 Prints 扩展程序进行操作),并将其显示在我的扩展程序视图中?

【问题讨论】:

    标签: swift xcode macos macos-high-sierra


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-20
      • 1970-01-01
      相关资源
      最近更新 更多