Showcase app data in Spotlight

RSS for tag

Discuss the WWDC21 session Showcase app data in Spotlight.

View Session

Posts under wwdc21-10098 tag

3 Posts
Sort by:
Post not yet marked as solved
0 Replies
241 Views
In the document it says you can define your own custom attribute: The attributes you choose depend on your domain. You can use the properties that Core Spotlight provides in categories that CSSearchableItemAttributeSet defines (such as Media and Documents), or you can define your own. If you want to define a custom attribute, be as specific as possible in your definition and use the contentTypeTree property so that your custom attribute can inherit from a known type. I tried to index a custom attribute with the following code: class mySpotlightDelegate:NSCoreDataCoreSpotlightDelegate { static let myCustomAttr = CSCustomAttributeKey(keyName: "myCustomAttr")! override func attributeSet(for object: NSManagedObject) -> CSSearchableItemAttributeSet? { if let myObject = object as? MyObject { let attributeSet = CSSearchableItemAttributeSet(contentType: .bookmark) attributeSet.title = myObject.name attributeSet.setValue( NSString(string: myObject.myAttr), forCustomKey: mySpotlightDelegate.myCustomAttr ) return attributeSet } return nil } } But later I couldn't either search with the custom attribute nor get the value of that custom attribute in the CSSearchQuery foundItemsHandler. (The search returns nil and when searched with title it was fine, but when I tried to get the value of custom attribute of returned items with item.attributeSet.value(forCustomKey: mySpotlightDelegate.myCustomAttr), the value is always nil) I've read through all official document regarding this and also searched everywhere but can't find an example of this anywhere, execept 2 other developers complaining about this problem. Is this a bug, or I'm doing it wrong? What's the right way to do it?
Posted
by
Post not yet marked as solved
2 Replies
476 Views
I have added the contents of my app to iOS Spotlight via the CSSearchableItemAttributeSet and it is very easy to find them from spotlight in use. I'd like to achieve a similar effect in the app via CSSearchQuery, but I'm currently running into a problem. In the system's spotlight, users can use fuzzy queries to find the information they want. I can't enter Chinese characters in the forum, 'hello' should be Chinese characters for example, if my content is in Chinese, 'hello', users can find the content not only by 'hello' but also by using 'nihao' to find the same content.('nihao' is the Latin pinyin equivalent of the Chinese word 'hello'). However, I am unable to achieve a similar effect in CKSearchQuery. At the moment CKSearchQuery only has [cdwt] four ways, is there any other means to achieve the above query capability. Or perhaps Apple does not have this capability open in CKSearchQuery.
Posted
by
Post not yet marked as solved
0 Replies
545 Views
Hi All, I'm very new to iOS development and Swift UI is my first coding language. I'm trying to link the users search results in Spotlight with the detail view that is stored in Core Data. I can search for users data in spotlight but when I tap on it, it's only appearing in the main view of the app. Is there anyways that I can use .onContinueUserActivity at the launch of the app or is there any different code that I have to use? I've searched for many articles but I couldn't get a solution. It would be good if anyone can share some links or guide here. Thank you. .onContinueUserActivity(DetailView.productUserActivityType) { userActivity in             if let product = try? userActivity.typedPayload(Product.self) {                 selectedProduct = product.id.uuidString             }         } I get this code from Apple's State restoration app but I can't use this with Core Data.
Posted
by