I'm using Core Data to save data. Then I wanna add spotlight support.
self.spotlightDelegate = StorageSpotlightDelegate(forStoreWith: description, coordinator: container.persistentStoreCoordinator)
let isSpotlightDisable = UserDefaults.standard.bool(forKey: "isSpotlightDisable")
if !isSpotlightDisable {
self.toggleSpotlightIndexing(enable: true)
}
public func toggleSpotlightIndexing(enable: Bool) {
guard let spotlightDelegate = spotlightDelegate else { return }
if enable {
spotlightDelegate.startSpotlightIndexing()
} else {
spotlightDelegate.stopSpotlightIndexing()
spotlightDelegate.deleteSpotlightIndex { error in
if let error = error {
print(error)
}
}
}
UserDefaults.standard.set(!enable, forKey: "isSpotlightDisable")
}
It works fine on an iOS15 device, but not work on iOS 17&18.
On iOS 18 devices, I can search the data when the first time to added to Core Data. But if I stop spotlight indexing and restart again, the data is never be searched.
How can I to solve this? And I noticed that the problem is also exists in another dictionary app.