首页 > 解决方案 > 在 AppDelegate.swift 中没有调用 userActivity 函数

问题描述

当我点击 Core Spotlight 搜索的结果时,应用程序会启动,但AppDelegate.swift不会调用其中的函数:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
  print("called")
}

它包含用于导航到特定视图控制器和加载数据的逻辑。

这里的一些人似乎建议使用SceneDelegate.swift

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
 print("called"
}

但也不会从 Core Spotlight 中调用。

似乎被调用的唯一函数是:

func sceneDidBecomeActive(_ scene: UIScene) {}
func sceneWillEnterForeground(_ scene: UIScene) {}

in SceneDelegate.swift,但没有所需的userActivity参数。

标签: iosswiftappdelegatespotlight

解决方案


推荐阅读