如何通过通用链接userActivity显示视图控制器?

时间:2019-12-21 04:04:55

标签: swift ios-universal-links nsuseractivity

如何通过userActivity在UserActionManager类中显示视图控制器?

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

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

当前,我已经创建了一个名为UserActionManager的单独的单例,我想在其中处理lastPathComponents并提供正确的视图控制器。

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

AppDelegate:

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
 }

UserActionManager:

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()
    }
}

0 个答案:

没有答案