iOS Spotlight indexing seems to be broken on iOS 17?

Content indexed through CSSearchableIndex.default().indexSearchableItems() is no longer searchable from Spotlight.

I created a very small app to demonstrate this. CSSearchableIndex.default().indexSearchableItems() returned no error, yet the result can't be found.

import CoreSpotlight
import SwiftUI

@main
struct testspotlightApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
        .onContinueUserActivity(CSSearchableItemActionType, perform: handleSpotlight)
    }
  }
  func handleSpotlight(_ userActivity: NSUserActivity) {
    print("Found \(userActivity.userInfo?.debugDescription ?? "nothing")")
  }
}
import CoreSpotlight
import SwiftUI

struct ContentView: View {
  @State var result = ""
  var body: some View {
    VStack {
      Text("Hello!")
      Button {
        let attribute = CSSearchableItemAttributeSet(contentType: .text)
        attribute.title = "a page title"
        attribute.contentDescription = "hello this is a page"
        attribute.keywords = ["search", "this", "page", "title"]
        let item = CSSearchableItem(
          uniqueIdentifier: "12345", domainIdentifier: "com.test", attributeSet: attribute)
        CSSearchableIndex.default().indexSearchableItems([item]) { error in
          if let error {
            result = "Failed to index: \(error.localizedDescription)"
          } else {
            result = "Successefully indexed to spotlight. Try searching 'a page title'"
          }
        }
        
      } label: {
        Text("Index a page").font(.title)
      }
      
      Text(result).multilineTextAlignment(.center)
    }
    .padding()
  }
}

Has anyone else seen the same issue?

  • Also I tried to build from both Xcode 14 and Xcode 15 beta. In both cases, it doesn't work on iOS 17 devices.

Add a Comment

Accepted Reply

I finally figured out a way to fix it.

Previously when we create CSSearchableItemAttributeSet when only set its title property. Now with iOS 17, we also need to set displayName property in order for the item to show up.

The code will look like this:

      let attribute = CSSearchableItemAttributeSet(contentType: .item)
      attribute.title = title
      attribute.displayName = title // this is the line that's not required before iOS 17, but necessary now
      let item = CSSearchableItem(uniqueIdentifier: id, domainIdentifier: nil, attributeSet: attribute)
      CSSearchableIndex.default().indexSearchableItems([item])

Replies

Same on our side.. still broken in the latest beta. Not clear if a new API is required or Apple has to fix the actual one 🤷🏻‍♂️

It is broken. Submitted FB12555541 one month ago, no response yet.

  • Hello there! Any updates on the submitted ticked?

  • Hi [@Mr. Brightside](https://developer.apple.com/forums/profile/Mr. Brightside) ! Can you share any more details / any update on this feedback? Curious if there was any acknowledgment that this is an issue, etc. Thanks!

Add a Comment

Thanks @arcangel06 and [@Mr. Brightside](https://developer.apple.com/forums/profile/Mr. Brightside) . It's reassuring to know that we are not alone. But what concerns me is that for some apps, on iOS 17 beta Spotlight Search does work, e.g. on both Venmo and WhatsApp you can search for friends on Spotlight. So I'm a little worried that Apple would consider this as not broken since it works for some apps.

But what concerns me is that for some apps, on iOS 17 beta Spotlight Search does work, e.g. on both Venmo and WhatsApp you can search for friends on Spotlight. So I'm a little worried that Apple would consider this as not broken since it works for some apps.

@baofromsf are you sure WhatsApp and Venmo - on iOS 17 devices - are built with latest Xcode 15 beta?

The problem is related to apps built with latest beta SDK only.

  • @arcangel06 I think WhatsApp and Venmo are built with Xcode 14 since people can't submit apps built with beta Xcode.

    But in my case even building with Xcode 14 (14.3.1), when the app is installed on an iOS 17 device, the spotlight results don't show up.

    What does your code look like? Do you do anything more than creating a CSSearchableItemAttributeSet, then a CSSearchableItem, and then calling CSSearchableIndex.default().indexSearchableItems?

  • @baofromsf I did the same exact things you 've mentioned :) Create CSSearchableItemAttributeSet, map them as CSSearchableItem and then call CSSearchableIndex.default().indexSearchableItems passing the items. :(

  • @arcangel06 [@Mr. Brightside](https://developer.apple.com/forums/profile/Mr. Brightside) I found a workaround: https://developer.apple.com/forums/thread/734996?answerId=763586022#763586022 do you want to try if this works for you as well?

I finally figured out a way to fix it.

Previously when we create CSSearchableItemAttributeSet when only set its title property. Now with iOS 17, we also need to set displayName property in order for the item to show up.

The code will look like this:

      let attribute = CSSearchableItemAttributeSet(contentType: .item)
      attribute.title = title
      attribute.displayName = title // this is the line that's not required before iOS 17, but necessary now
      let item = CSSearchableItem(uniqueIdentifier: id, domainIdentifier: nil, attributeSet: attribute)
      CSSearchableIndex.default().indexSearchableItems([item])

it works [@Mr. Brightside](https://developer.apple.com/forums/profile/Mr. Brightside) :) thank you 🙏🏻

I am facing the exact same problem, proposed workaround works fine but it only let the user search for the words on the displayName field, keywords list is not working for me on iOS 17 :(

I have the same problem. Only the displayName field can be searched, other properties such as keywords、alternateNames、director、comment、information、participants can not be searched on iOS 17. And another problem is that words less than four Chinese can not be searched! Any one knows how to fix it ?

I have filed as FB13205932, would recommend others also file a Feedback and share their ticket numbers in this thread.

  • Thanks for filing FB13205932.

Add a Comment

Same problem. Filed FB13262028.

Filled FB13265642

When this breaks it also breaks the recent contacts within the share window and recent apps that are location based. I've not yet updated to 17.1 and I am doing so currently. Hopefully @baofromsf fix has been implented.. you are such smart people ;-)

My app's indexing also fails on iOS17, here's what I did to make it work again, after looking at the sample code from "Showcase App Data in Spotlight"

  1. Switched the NSCoreDataCoreSpotlightDelegate init code from init(forStoreWith: NSPersistentStoreDescription, model: NSManagedObjectModel) to init(forStoreWith: NSPersistentStoreDescription, coordinator: NSPersistentStoreCoordinator)
  2. Manually calls startSpotlightIndexing() after the above.
  3. Move the initialisation above from before loadPersistentStores to after loadPersistentStores.