Post

Replies

Boosts

Views

Activity

Reply to Spotlight search by keywords setuped in NSUserActivity doesn't work
My previous comment has wrong format. I can't change it, so I'll write the new one. I've tried to setup feature in another way - using CSSearchableItemAttributeSet and CSSearchableItem. This is my code: func save(keywords: [String]) { guard let bundleId = Bundle.main.bundleIdentifier else { return } let items = keywords.map { let attributeSet = CSSearchableItemAttributeSet(itemContentType: UTType.plainText.identifier) if #available(iOS 18.0, *) { attributeSet.title = $0 attributeSet.displayName = $0 } else { attributeSet.title = $0 attributeSet.displayName = self.appName } return CSSearchableItem( uniqueIdentifier: "\(bundleId).spotlight.\($0)", domainIdentifier: "\(bundleId).spotlight", attributeSet: attributeSet ) } CSSearchableIndex.default().indexSearchableItems(items) { error in if let error = error { print("Spotlight indexing error: \(error.localizedDescription)") } else { print("Spotlight keywords indexed successfully.") } } } Take a look at the code block if #available(iOS 18.0, *). With this code search is working, but not in the way I need - spotlight search displays a couple variants if they are similar and that is understandable, because I set attributeSet.displayName = $0 as one of possible keywords. But if I remove block if #available(iOS 18.0, *) { and leave just func save(keywords: [String]) { guard let bundleId = Bundle.main.bundleIdentifier else { return } let items = keywords.map { let attributeSet = CSSearchableItemAttributeSet(itemContentType: UTType.plainText.identifier) attributeSet.title = $0 attributeSet.displayName = self.appName return CSSearchableItem( uniqueIdentifier: "\(bundleId).spotlight.\($0)", domainIdentifier: "\(bundleId).spotlight", attributeSet: attributeSet ) } CSSearchableIndex.default().indexSearchableItems(items) { error in if let error = error { print("Spotlight indexing error: \(error.localizedDescription)") } else { print("Spotlight keywords indexed successfully.") } } } It won't be working on iOS 18.x versions, but will work on versions lower. Any thoughts? I'll add information to my FB
Topic: App & System Services SubTopic: General Tags:
Mar ’25
Reply to Spotlight search by keywords setuped in NSUserActivity doesn't work
So, I've tried to setup feature in another way - using CSSearchableItemAttributeSet and CSSearchableItem. This is my code: func save(keywords: [String]) { guard let bundleId = Bundle.main.bundleIdentifier else { return } let items = keywords.map { let attributeSet = CSSearchableItemAttributeSet(itemContentType: UTType.plainText.identifier) if #available(iOS 18.0, *) { attributeSet.title = $0 attributeSet.displayName = $0 } else { attributeSet.title = $0 attributeSet.displayName = self.appName } return CSSearchableItem( uniqueIdentifier: "\(bundleId).spotlight.\($0)", domainIdentifier: "\(bundleId).spotlight", attributeSet: attributeSet ) } CSSearchableIndex.default().indexSearchableItems(items) { error in if let error = error { print("Spotlight indexing error: \(error.localizedDescription)") } else { print("Spotlight keywords indexed successfully.") } } } Take a look at the code block `if #available(iOS 18.0, *)`. With this code search is working, but not in the way I need - spotlight search displays a couple variants if they are similar and that is understandable, because I set `attributeSet.displayName = $0` as one of possible keywords. But if I remove block `if #available(iOS 18.0, *) {` and leave just ```swift func save(keywords: [String]) { guard let bundleId = Bundle.main.bundleIdentifier else { return } let items = keywords.map { let attributeSet = CSSearchableItemAttributeSet(itemContentType: UTType.plainText.identifier) attributeSet.title = $0 attributeSet.displayName = self.appName return CSSearchableItem( uniqueIdentifier: "\(bundleId).spotlight.\($0)", domainIdentifier: "\(bundleId).spotlight", attributeSet: attributeSet ) } CSSearchableIndex.default().indexSearchableItems(items) { error in if let error = error { print("Spotlight indexing error: \(error.localizedDescription)") } else { print("Spotlight keywords indexed successfully.") } } } It won't be working on iOS 18.x versions, but will work on versions lower. Any thoughts?
Topic: App & System Services SubTopic: General Tags:
Mar ’25
Reply to Spotlight search by keywords setuped in NSUserActivity doesn't work
Thanks for your reply! I think that we have miscommunication a bit. I want to see my app in Spotlight search results by entering specific keywords, that I setup in activity.keywords = Set(keywords). But for now I just can find my app by name. I didn't find any changes related to NSUserActivity and iOS 18 (in earlier versions it works ok) so I decided to describe problem here. Posted bug report - FB17023996
Topic: App & System Services SubTopic: General Tags:
Mar ’25