gpt4 book ai didi

ios - 在 PHAssetCollection 中过滤矩

转载 作者:可可西里 更新时间:2023-11-01 01:10:28 26 4
gpt4 key购买 nike

使用 iOS 11/Swift 4,我正在尝试从照片库中过滤一组精彩瞬间。我只想要 Places。使用 nil 选项检索时刻集合,我得到 13 个时刻,其中 8 个时刻具有非零标题(位置)。当我使用一个简单的谓词 localizedTitle != nil 执行获取时刻时,结果始终为 nil。用空 String ("") 替换 nil 也会产生空结果。

这里是示例代码和控制台结果:

let momentOptions = PHFetchOptions()
momentOptions.predicate = NSPredicate(format:"localizedTitle != nil")
momentList = PHAssetCollection.fetchMoments(with: nil)
let momentListFiltered = PHAssetCollection.fetchMoments(with: momentOptions)
let assetCount = momentList.count

for index in 0...assetCount-1 {
let a = momentList[index]
let sta = a.localizedTitle
let stb = a.localizedLocationNames
print(index, sta ?? "--", stb)
}

控制台上的结果:

0 -- []
1 -- []
2 Point Reyes National Seashore ["Point Reyes Station, CA"]
3 Þingeyjarsveit, Northeast Iceland ["Goðafossvegur"]
4 Djúpavogshreppur ["East Iceland"]
5 Rangárþing eystra ["South Iceland"]
6 New York - Washington Heights ["W 168th St"]
7 -- []
8 -- []
9 Jacksonville, NC ["Western Blvd"]
10 -- []
11 Locust Shade Park ["Triangle, VA"]
12 Piedmont Triad International Airport ["Friendship, NC"]

(lldb) po momentListFiltered
<PHFetchResult: 0x60c0002e2100> count=0

最后,只是为了确认正确的比较:

p momentList[7].localizedTitle == nil
(Bool) $R2 = true

最佳答案

这似乎确实是 Photos API 中的错误或未记录的限制。我鼓励您通过 Bug Reporter 向 Apple 提交错误。 .

您可能会发现这种替代方法很有用:

let momentLists = PHCollectionList.fetchMomentLists(with: .momentListCluster, options: nil)
if momentLists.count > 0 {
for index in 0...momentLists.count - 1 {
let a = momentLists[index]
print(index, a.localizedTitle ?? "--", a.localizedLocationNames)
}
} else {
print("-- No moment lists! --")
}

这会得到一个瞬间集群列表,它似乎是按地点和时间对照片进行分组。

关于ios - 在 PHAssetCollection 中过滤矩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47637654/

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