2016-11-23 37 views
1

点击邀请链接后,我正在使用分支将用户重定向到我的应用的特定视图。它的工作原理除了我需要他们在他们登录后才重定向,而不是像现在这样。 从我能告诉我没有方法在我的初始视图控制器被点击分支链接后调用,所有的设置都必须在AppDelegate上完成。 下面是一些我的AppDelegate相关的代码:只有在用户登录后才能重定向Branch.io

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    Branch.getInstance().initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: { params, error in 
     guard error == nil else { return } 
     guard let userDidClick = params["+clicked_branch_link"] as? Bool else { return } 
     if userDidClick { 
      let branch = Branch.getInstance() 
      branch?.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: { params, error in 
       if error == nil { 
        var controller = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "DetailViewController") 

        branch?.registerDeepLinkController(controller, forKey: "valid_link") 
        branch?.initSession(launchOptions: launchOptions, automaticallyDisplayDeepLinkController: true) 

        print("prm: \(params)") 
       } 
      })  } 
    }) 
... 

,像它应该,但我需要它后才可登录重定向重定向到DetailViewController。 感谢您提前提供任何帮助。

回答

1

亚历克斯从分支这里:这是完全有可能的。您目前正在使用我们的automatic routing implementation,它简化了一些东西,但没有足够的细节来处理这个用例。相反,您需要构建一个custom link routing method来存储链接数据,直到登录过程完成。

编辑:通用实现:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    let branch: Branch = Branch.getInstance() 
     branch.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: {params, error in 

     // If the key 'valid_link' is present in the deep link dictionary 
     if error == nil && params["+clicked_branch_link"] != nil && params["valid_link"] != nil { 

      // assign valid_link to a variable 

     } 
    return true 
} 

// perform your login process, and pass the valid_link variable through to the post-login viewcontroller for display 
+0

能否请您详细说明与任何样品或解释你的答案。 –

+0

没有OP的认证流程的完整细节,没有。查看通用方法的更新回答 –

+0

感谢您的帮助到目前为止,您可以请代码帮助我viewController也登录后,意味着该怎么做。 –