【发布时间】:2015-12-14 22:38:59
【问题描述】:
我将“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")
}
}
你可以看到我正在使用 domainIdentifiers: "person" & "product"。但是当我回到应用程序时,我将如何访问这些domainIdentifiers?
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
}
【问题讨论】:
标签: ios swift corespotlight nsuseractivity