objective-c - NSUserActivity 和 CoreSpotlight 的使用

标签 objective-c swift ios9 nsuseractivity

我花了很多时间来寻找 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 不提供的性能、索引中的项目数量,以及重要的是 CoreSpotlight 不提供的公共(public)索引。我们必须再等待一段时间才能得到您问题的答案。

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

相关文章:

ios - 在自定义 UICell 中获取 UIImage 的框架在 iOS8.3 中使用自动布局

ios - 如何在 parse.com 中将一列拆分为多个变量列

ios - 黄色警告 : Conditional cast from UITextDocumentProxy to UIKeyInput always succeeds

ios - UITableView 重新加载数据很慢

objective-c - 不同的 C++ include 语句在 Objective-C header 中抛出错误

swift - 如何使用 map 函数快速从数组中获取替代索引数据

xcode - 添加一个 UITabBarItem 到一个已经存在的 UITabBar(在 Storyboard中制作)

ios9 - CNContactViewController forUnknownContact 不可用,破坏接口(interface)

ios - 3D Touch peek 和 pop 问题

ios - 两个NSData对象-base64编码为1个“包”