0

我将“Person”和“Product”对象索引到 Spotlight 中,如下所示:

// Person
let personItem = CSSearchableItem(uniqueIdentifier: personID, domainIdentifier: "person", attributeSet: attributeSet)                

CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([personItem]) { (error: NSError?) -> Void in
    if let error = error {
        print("Indexing error: \(error.localizedDescription)")
    } else {
        print("person added to spotlight")
    }
}


// Product
let productItem = CSSearchableItem(uniqueIdentifier: productID, domainIdentifier: "product", attributeSet: attributeSet)                

CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([productItem]) { (error: NSError?) -> Void in
    if let error = error {
        print("Indexing error: \(error.localizedDescription)")
    } else {
        print("product added to spotlight")
    }
}

你可以看到我正在使用 to domainIdentifiers: "person" & "product"。domainIdentifier但是当我回到应用程序时,我将如何访问这些s?

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
    if userActivity.activityType == CSSearchableItemActionType {

        // if product do this
        // if person do that

    }

    return true
}
4

1 回答 1

2

据我所知,CoreSpotlight您无法直接访问domainIdentifier. 您所拥有的是uniqueIdentifier,因此您可以使用某种前缀来解决它。要获取标识符,您可以使用:

if let itemActivityIdentifier = userActivity.userInfo?["kCSSearchableItemActivityIdentifier"] {

}

在你的AppDelegate.

于 2015-12-14T14:38:59.650 回答