UISceneを使ったアプリをSpotlightから開いた時に呼ばれるデリゲートメソッド

iOS 13から追加されたUISceneを使用していると、Spotlightで検索した結果からアプリを開いた時に呼ばれるデリゲートがUIApplicationDelegateからUISceneDelegateに変わります。

import CoreSpotlight

// UISceneDelegate
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    switch userActivity.activityType {
    case CSSearchableItemActionType:
        print("ITEM SELECTED")
    case CSQueryContinuationActionType:
        if let searchQuery = userActivity.userInfo?[CSSearchQueryString] as? String {
            print("From Spotlight => \(searchQuery)")
        }
    default:
        break
    }
}
import CoreSpotlight

// UIApplicationDelegate
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    switch userActivity.activityType {
    case CSSearchableItemActionType:
        print("ITEM SELECTED")
    case CSQueryContinuationActionType:
        if let searchQuery = userActivity.userInfo?[CSSearchQueryString] as? String {
            print("From Spotlight => \(searchQuery)")
        }
    default:
        return false
    }
    return true
}

その他でもUISceneDelegateが使われることになるのでSceneを使用する場合は要確認です。

参考

https://developer.apple.com/videos/play/wwdc2019/212

Migrating your codeで触れられてます。(PDF 50ページあたり)