如何更改 CSSearchableItem 中的年日期(内容类型 — kUTTypeMovie)?

How to change year date in CSSearchableItem (content type — kUTTypeMovie)?

我有一个包含视频内容的应用程序,我使用 NSUserActivity 跟踪所有查看的项目以将其添加到 Spotlight。结果看起来很完美,除了年份,它总是 NSUserActivity 被添加到索引的年份。但我需要将其更改为电影的发行年份。

let activity = NSUserActivity(activityType: "com.bundleid.movie")
activity.isEligibleForSearch = true
activity.title = "Mess"
let movie = kUTTypeMovie as String
let attributes = CSSearchableItemAttributeSet(itemContentType: movie)
attributes.title = "Mess"
attributes.contentDescription = "Even if you get behind bars..."
attributes.thumbnailData = try? Data(contentsOf: thumbURL) // cover
attributes.rating = NSNumber(value: 3.7)
attributes.ratingDescription = "(Kinopoisk: 7.9, IMDb: 7.4)"
attributes.duration = NSNumber(value: 5785) // 1:36:25 in sec
attributes.contentCreationDate = dateFormatter.date(from: "1989") // ¯\_(ツ)_/¯
activity.contentAttributeSet = attributes

我不仅要设置 attributes.contentCreationDate,还要设置 addedDateCSSearchableItemAttributeSet_Media.h 中可用的所有其他日期。但它总是 2018(

我能够重现这个。

但是,当我将此 CSSearchableItemAttributeSet 放在 NSUserActivity 内而不是放在 CSSearchableItem 内并用 CSSearchableIndex.default().indexSearchableItems() 索引时,搜索结果显示 1989 根据需要。

这对你有用吗?