Hello cwagdev,
i have bought the book containing the said tutorial- ios9 app search however iam not finding a search bar in the tutorial.
I did tried to add the search function but its not working.
Can you help me out iam just started following you
Hi @cwagdev - Thanks for the tutorial. The apple documentation for app search wasnt very detailed.
I had one question with respect to app search - specifically around the thumbnailData.
Can you incorporate an example of setting the thumbnailData with an image fetched over the network? How would you then instruct spotlight that the item has to be re-indexed with the image you set for the thumbNail?
// In EmployeeViewController.swift
private func updateThumbnailImage(for activity: NSUserActivity) {
// make a request and set the thumbnail
let url = URL(string: "https://i.imgur.com/B14aN7g.png")! // url for a star icon
let imageTask = URLSession.shared.dataTask(with: url) { (data, response, error) in
if let data = data {
let attributeSet = activity.contentAttributeSet
attributeSet?.thumbnailData = data
}
}
imageTask.resume()
}
// And this is called from viewDidLoad as:
override func viewDidLoad() {
// ...
// other stuff
// ...
let activity = employee.userActivity
updateThumbnailImage(for: activity)
switch Setting.searchIndexingPreference {
case .disabled:
activity.isEligibleForSearch = false
case .viewedRecords:
activity.isEligibleForSearch = true
}
userActivity = activity
}
The reason I have this question is because it is not clear to me when spotlight indexes content in this flow. Since the image fetch completes later than the userActivity = activity , I am not sure if I have to make some call to re-index the content.
This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]