When I tap on the result of the Core Spotlight search, the app launches, but the function in AppDelegate.swift doesn't get called:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
print("called")
}
which contains a logic for navigating to a specific view controller and loading data.
Some people here seem to recommend using SceneDelegate.swift:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
print("called"
}
but doesn't get called from Core Spotlight, either.
The only functions that seem to be being called are:
func sceneDidBecomeActive(_ scene: UIScene) {}
func sceneWillEnterForeground(_ scene: UIScene) {}
in SceneDelegate.swift, but doesn't have the needed userActivity parameter.
Not strictly the correct answer, this is for SwiftUI, but incase others land here!
Took me ages to find this, so despite being an old question, thought I should add the answer that worked for me!
I found the answer here: https://betterprogramming.pub/implement-core-spotlight-in-a-swiftui-app-859cb703f55d
Rather than an
AppDelegatefunction, it is just added as an modifier to the main content view: