0

我按照NSUserActivity 中的示例对 Spotlight 搜索结果进行索引isEligibleForSearch,并尝试通过设置为将项目索引到 Spotlight true。该项目已正确编入索引,但是当我在 Spotlight 中单击该项目时,我得到了错误的 activityType(NSUserActivityTypeBrowsingWeb而不是com.myCompany.myContentType)。

索引代码:

let newUserActivity = NSUserActivity(activityType: "com.myCompany.myContentType")
newUserActivity?.isEligibleForSearch = true
newUserActivity?.persistentIdentifier = "123"
newUserActivity?.userInfo = [
    "url": "https://www.stackoverflow.com"
]
newUserActivity?.requiredUserInfoKeys = ["url"]

var attributeSet = CSSearchableItemAttributeSet()
if #available(iOS 14.0, *) {
    attributeSet = CSSearchableItemAttributeSet(contentType: .item)
} else {
    attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String)
}

attributeSet.displayName = "Test Spotlight Item"
newUserActivity?.contentAttributeSet = attributeSet
newUserActivity?.becomeCurrent()

搜索结果深层链接处理程序代码:

func application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool {
    if userActivity.activityType == "com.myCompany.myContentType" {
        // Does not go in here since the activityType is different.
    }
    return true
}

关于我可能做错了什么的任何想法?

4

0 回答 0