0

I'm indexing 'Person' and 'Product' objects into Spotlight like so:

// 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")
    }
}

You can see that I'm using to domainIdentifiers: "person" & "product". But how would I access these domainIdentifiers when I come back into the app?

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
}
cannyboy
  • 24,180
  • 40
  • 146
  • 252

1 Answers1

2

From what I know, in CoreSpotlight you don't have direct access to domainIdentifier. What you have is uniqueIdentifier, so you can work around it with some prefix in it of some sort. To get the identifier you can use:

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

}

in your AppDelegate.

sunshinejr
  • 4,834
  • 2
  • 22
  • 32
  • thanks. each `Product` or `Person` has an associated website URL - i.e. example.com/person/1234 example.com/product/1234. So it might make sense for me to use the url string as a uniqueIdentifier, as then parse it in `continueUserActivity`. – cannyboy Dec 14 '15 at 14:52
  • Maybe not the whole URL, but product/1234, person/1234 seems like an idea, easy to parse. – sunshinejr Dec 14 '15 at 14:56