1

我正在尝试从用户相机胶卷中获取过去 7 天内拍摄的照片和视频。

这是我的代码...

let oneWeekAgoDate = NSCalendar.current.date(byAdding: .weekOfYear, value: -1, to: NSDate() as Date)

fetchOptions.predicate = NSPredicate(format: "date > %@ && (mediaType = %d || mediaType = %d)",oneWeekAgoDate! as NSDate, PHAssetMediaType.image.rawValue, PHAssetMediaType.video.rawValue)

取自https://stackoverflow.com/a/30520861/6633865

但是我的应用程序不断终止此消息

提取选项中不支持的谓词:日期> CAST(556405508.551209,“NSDate”)

有任何想法吗?

谢谢

4

1 回答 1

1
 var p: NSPredicate?
 let date = Date()
 p = NSPredicate(format: "mediaType = %d AND ( creationDate < %@ )",PHAssetMediaType.image.rawValue,date as NSDate)

再试一次!

于 2019-10-18T02:20:13.590 回答