【问题标题】:iOS Group Photo Library photos by categoriesiOS 群组照片库照片(按类别)
【发布时间】:2019-05-31 07:41:05
【问题描述】:

在我的应用程序中,我正在使用此代码获取所有照片(PHAsset

    PHPhotoLibrary.requestAuthorization { (status) in
        switch status {
        case .authorized:
            print("Good to proceed")
            let fetchOptions = PHFetchOptions()
            let allPhotos = PHAsset.fetchAssets(with: .image, options: fetchOptions)
            print("Found \(allPhotos.count) images")
        case .denied, .restricted:
            print("Not allowed")
        case .notDetermined:
            print("Not determined yet")
        @unknown default:
            fatalError()
        }
    }

我有两个问题:

  1. 我可以从照片库中获取按类别分组的照片吗? (见下图)
  2. 我可以按类别对照片进行分组吗? (见下图)

【问题讨论】:

  • 计算机如何知道哪些照片是花,哪些是动物?
  • @matt Apple 通过图像识别完成了它。
  • @matt 你明白我的问题吗?

标签: ios swift phasset photosframework


【解决方案1】:

好像不能直接实现。

但是,你可以按系统智能相册、朋友圈或相册分类(结果为PHAssetCollection类型)。

斯威夫特 5

智能相册

let systemAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil)

时刻

let systemAlbums = PHAssetCollection.fetchAssetCollections(with: .moment, subtype: .albumRegular, options: nil)

专辑

let systemAlbums = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .albumRegular, options: nil)

还可以显示用户的相册(获取结果是包含用户收藏的PHCollection类型)

let userAlbums = PHCollectionList.fetchTopLevelUserCollections(with: nil)

此外: 不需要每次都请求授权,系统会在你第一次调用每个相关函数时提醒用户并请求授权。

有浏览照片的示例代码Browsing and Modifying Photo Albums

【讨论】:

  • 感谢您的回答,但这不是我想要的。如果您转到照片应用程序并选择搜索选项卡,则会按类别对照片进行分组,查看相关图像(动物、游乐场、鲜花等)。我想要那些收藏。
  • @Karen Hovhannisyan,哦,对不起,我没有仔细看图,我觉得没有这样的功能可以直接完成,苹果可能通过图像识别来完成。
【解决方案2】:

目前没有公共 API 可以访问 3rd 方应用中的类别。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多