NSUserActivity和CoreSpotlight的用法 [英] Usage of NSUserActivity and CoreSpotlight

查看:64
本文介绍了NSUserActivity和CoreSpotlight的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间来寻找 NSUserActivity 优于 CoreSpotlight 的优势,无论我实际上找不到什么.

I have spent plenty of time to find benefit of NSUserActivity over CoreSpotlight, whether i couldn't find anything practically.

实际上,它无法索引我们通过 NSUserActivity 设置的项目.我已在下面附上了我的代码段,该代码段应该可以按照Apple文档的要求运行,但是不会运行.

Actually, it couldn't index our item, which we set through NSUserActivity. I have attached my snippet below, which supposed to work as per apple documentation,however it won't.

        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()

我想找到

为什么要使用 NSUserActivity 进行搜索,因为 CoreSpotlight 可以实现?

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

推荐答案

根据Apple文档

为确保对活动及其元数据建立索引,必须对活动进行严格引用,直到将其添加到索引中为止.有两种方法可以执行此操作:第一种方法是将活动分配给创建活动的控制器对象中的属性.第二种方法是使用UIResponder对象的userActivity属性.如果使用第二种方法,则需要在updateUserActivityState:方法中设置元数据(例如userInfo属性中的信息).否则,您在活动上设置的元数据将不会保留.

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保留.

You activity is deallocated before getting indexed and best to retain using self .

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

And the answer to your second question remains mystery to me.

也许就像性能一样,索引中没有项目,而且重要的是CoreSpotlight不提供的公共索引.我们必须再等一会才能为您的问题提供答案.

Maybe its like the performance ,no of items in indexing, and importantly the public indexing which CoreSpotlight don't offer.We have to wait a little more to get the answer for your question.

这篇关于NSUserActivity和CoreSpotlight的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆