0

如何从 userActivity 在我的 UserActionManager 类中显示视图控制器?

我正在使用通用链接并设置了 apple-app-site-association 文件。

当我发现 userActivity.webPageURL.lastPathComponent 等于“注册”时,我想推送到 RegistrationViewController。

目前,我创建了一个单独的单例,称为 UserActionManager,我想在其中处理 lastPathComponents 并呈现正确的视图控制器。

在 UserActionManager 中我可以成功命中handleRegistrationUserActivity,但需要添加逻辑或协议来显示相关的 ViewController。

应用委托:

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

        guard let url = userActivity.webpageURL, userActivity.activityType == NSUserActivityTypeBrowsingWeb else {
            return false
        }

        UserActionManager.shared.handleUserActivity(from: url)

        return true
 }

用户操作管理器:

class UserActionManager {

    // MARK: - Singleton

    static let shared = UserActionManager()

    func handleUserActivity(from url: URL) {

        switch url.lastPathComponent {

        case "registration":
            handleRegistrationUserActivity()
        default:
            break
        }
    }

    private func handleRegistrationUserActivity() {

       // TODO: Set the root navigation controller to RegistrationViewController()
    }
}
4

0 回答 0