gpt4 book ai didi

objective-c - NSUserActivity 和 CoreSpotlight 的使用

转载 作者:可可西里 更新时间:2023-11-01 00:52:32 25 4
gpt4 key购买 nike

我花了很多时间来寻找 NSUserActivity 相对于 CoreSpotlight 的好处,但实际上我找不到任何东西。

实际上,它无法索引我们通过 NSUserActivity 设置的项。我在下面附上了我的代码片段,它应该按照苹果文档工作,但它不会。

        let personName = "Jon Doe"
let activity = NSUserActivity(activityType: "com.SearchAPIs.test”)
activity.userInfo = ["name": "Jon Doe"]
activity.title = person.name
let keywords = personName.componentsSeparatedByString(" ")
activity.keywords = Set(keywords)
activity.eligibleForSearch = true
activity.eligibleForPublicIndexing = true
activity.expirationDate = NSDate().dateByAddingTimeInterval(16666600)
activity.becomeCurrent()

我想找到答案

Why we need to use NSUserActivity in way of search, since it can be possible with CoreSpotlight?

最佳答案

根据苹果文档

To guarantee that the activity and its metadata get indexed, you must hold a strong reference to the activity until it gets added to the index. There are two ways to do this: The first way is to assign the activity to a property in the controller object that creates the activity. The second way is to use the userActivity property of the UIResponder object. If you use the second way, you need to set the metadata—such as information in the userInfo property—in the updateUserActivityState: method; otherwise, the metadata you set on the activity will not be persisted.

你的事件在被索引之前被释放,最好使用 self 来保留。

第二个问题的答案对我来说仍然是个谜。

也许它像性能,索引中没有项目,重要的是 CoreSpotlight 不提供的公共(public)索引。我们必须再等一会儿才能得到您问题的答案。

关于objective-c - NSUserActivity 和 CoreSpotlight 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32134733/

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