gpt4 book ai didi

ios - 快速获取屏幕截图(相册)计数

转载 作者:可可西里 更新时间:2023-11-01 00:21:20 31 4
gpt4 key购买 nike

我是 Swift 的新手,我正在尝试使用 fetchAssetCollections 创建一个简单地返回屏幕截图相册中照片数量的函数

我有

func getNumScreenshots() -> Int {

let collection:PHFetchResult =
PHAssetCollection.fetchAssetCollections(with: .album, subtype:.smartAlbumScreenshots, options: nil)

return collection.count
}

但是,这总是返回 3,我不确定为什么(我的 iPhone 上有 600 个屏幕截图)。

最佳答案

你可以试试这个:

let albumsPhoto:PHFetchResult<PHAssetCollection> = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil)

albumsPhoto.enumerateObjects({(collection, index, object) in
if collection.localizedTitle == "Screenshots"{
let photoInAlbum = PHAsset.fetchAssets(in: collection, options: nil)
print(photoInAlbum.count) //Screenshots albums count
}
})

注意:使用这段代码是Swift 3

关于ios - 快速获取屏幕截图(相册)计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42195423/

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