gpt4 book ai didi

iOS 团体照片库照片(按类别)

转载 作者:行者123 更新时间:2023-11-29 05:42:54 26 4
gpt4 key购买 nike

在我的应用程序中,我使用此代码获取所有照片(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. 我可以在我的侧边按类别对照片进行分组吗? (见下图)

enter image description here

最佳答案

似乎不能直接实现。

但是,您可以按系统智能相册、 friend 圈或相册进行分类(结果为PHAssetCollection类型)。

swift 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

关于iOS 团体照片库照片(按类别),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56390767/

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