In-App Routing


When a Branch link is opened, either your app launches or users are taken to the App/Play store to download it. Deep links improve this process by routing users directly to specific content after your app launches. With Branch, this works even if users have to stop and download the app first (a.k.a., "deferred deep links"). Deep links are an incredibly important part of delivering a high-quality user experience.


  • 选项1:在路由回调中建立自定义路由—在打开应用后立即进行路由
  • 选项 2:让 Branch 使用您现有的深度链接路由
  • 选项3:使用 Branch 的简单配置深度链接路由—自动路由


iOS Deferred Deep Linking

With the introduction of iOS 15 and iCloud+ Private Relay, Branch released support for deferred deep linking using NativeLink™

To implement iOS NativeLink™, follow the instructions in our developer documentation.



Inside the deep link handler callback that you register in initSession, you will want to examine the parameters dictionary to determine whether the user opened a Branch link. Below is an example assuming that the links correspond to pictures. Below are some examples from iOS and Android where we're using the pictureId key to route, but you can see more code snippets for the other platforms here.


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

      // initialize the session, setup a deep link handler
      [[Branch getInstance] initSessionWithLaunchOptions:launchOptions
                              andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {

        // start setting up the view controller hierarchy
        UINavigationController *navC = (UINavigationController *)self.window.rootViewController;
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *nextVC;

        // If the key 'pictureId' is present in the deep link dictionary
        // then load the picture screen with the appropriate picture
        NSString *pictureId = [params objectForKey:@"pictureId"];
        if (pictureId) {
          nextVC = [storyboard instantiateViewControllerWithIdentifier:@"PicVC"];
          [nextVC setNextPictureId:pictureId];
        } else {
          nextVC = [storyboard instantiateViewControllerWithIdentifier:@"MainVC"];

        // navigate!
        [navC setViewControllers:@[nextVC] animated:YES];

      return YES;


        public void onStart() {

            Branch.sessionBuilder(this).withCallback(new BranchReferralInitListener(){
                public void onInitFinished(JSONObject referringParams, Branch.BranchError error) {
                    if (error == null) {
                        // params are the deep linked params associated with the link that the user clicked before showing up
                        // params will be empty if no data found
                        String pictureID = referringParams.optString(""picture_id"", """");
                        if (pictureID.equals("""")) {
                            startActivity(new Intent(this, HomeActivity.class));
                        else {
                            Intent i = new Intent(this, ViewerActivity.class);
                            i.putExtra(""picture_id"", pictureID);
                    } else {
                        Log.e(""MyApp"", error.getMessage());

Branch 添加的参数

除了在链接数据 dictionary 中指定的任何自定义 key/值对之外,每次会话初始化时,Branch 还返回一些其他有用的参数。即使用户未点击 Branch Link,每次初始化会话时也将返回这些参数。这是一个列表,以及每个代表什么的描述。

  • ~ 表示分析
  • + 表示 Branch 添加的信息
  • 该数据将无法用于来自 Facebook 或其他自归因平台的深度链接
  • For the curious, $ denotes reserved keywords used for controlling how the Branch service behaves. Read more about control parameters on the Configuring Links page






表示用户是否点击了触发该会话的 Branch Link








驱动安装/打开的链接的完整 URL(如果存在)(例如, / abcde12345)








与链接关联的 Campaign,在链接创建时指定


链接创建位置 ('API', 'Dashboard', 'SDK', 'iOS SDK', 'Android SDK', 或 'Web SDK')




您可以随时通过调用以下方法之一从 Branch singleton 中检索深度链接数据。如果要在提示用户登录后进行深度链接,则可以使用此方法。您可以在此处查看其他平台的代码片段。




NSDictionary *params = [[Branch getInstance] getLatestReferringParams];


JSONObject sessionParams = Branch.getInstance().getLatestReferringParams();


这将返回曾经引用用户的第一组深度链接数据。一旦为给定用户进行了设置 ,就永远无法更新。这对于推荐很有用。


NSDictionary *params = [[Branch getInstance] getFirstReferringParams];


JSONObject installParams = Branch.getInstance().getFirstReferringParams();

选项 2:让 Branch 使用您现有的深度链接路由

If your app already supports deep linking using URI paths, you can populate the $deeplink_path$ios_deeplink_path or $android_deeplink_path link parameters with the URI path of the content to be displayed within the app. When the Branch SDK receives a link containing one of these parameters, it will automatically load the specified URI path.


对 iOS 不完全支持

Universal Links and Spotlight do not support deep linking via URI paths. If you use $deeplink_path or $ios_deeplink_path, you will need to implement some custom logic. Click here for more information.

如何将自定义深度链接路由插入 Branch Link

All of the examples below create links that will cause Branch to display myapp://content/1234 after launch. Please do not add the URI scheme on the $deeplink_path parameters; we automatically append the scheme specified in the Configuration page of the dashboard.

如果您通过附加查询参数重新创建链接,则只需将控制参数附加到 URL。请确保对所有内容进行 URL 编码,否则链接将断开。


使用移动 SDK 时


BranchLinkProperties *linkProperties = [[BranchLinkProperties alloc] init];
linkProperties.feature = @"sharing"; = @"facebook";
[linkProperties addControlParam:@"$deeplink_path" withValue:@"content/1234"];


LinkProperties linkProperties = new LinkProperties()
.addControlParameter("$deeplink_path", "content/1234");


在操作后台 (Dashboard) 创建 Quick Link 时

您可以通过将 key 和值插入深度链接数据(高级)部分来指定单个 Quick Link 的控制参数。

如何使用 Universal Links 或 App Links 链接处理 URI 路径

Because Universal Links, Spotlight and Android App Links do not use URI schemes for deep link routing. If you populate $deeplink_path$ios_deeplink_path or $android_deeplink_path with a URI path, you will need to a bit of additional work to ensure that Branch links route according to your original schema.

  1. 按照应用配置步骤中所述初始化会话。
  2. In the callback function, add some custom code to read the appropriate $deeplink_path parameter in the params
  3. 使用此值来调用现有的路由逻辑,以将用户路由到应用中的正确位置

Now whenever your app launches from a Branch link that has the product_picture key set in its data dictionary, this Activity will be displayed!