2

我一直在 Xcode 8、swift、iOS9.3 中使用 Branch SDK。

在创建链接并通过 Airdrop 时,添加的参数未进入“params 变量:

branch.initSession(launchOptions: launchOptions, isReferrable: true, andRegisterDeepLinkHandler: {(params : [AnyHashable : Any]?, error) -> Void in

而打印“参数”它的打印:

 ▿ Optional<Dictionary<AnyHashable, Any>>
  ▿ some : 2 elements
    ▿ 0 : 2 elements
      ▿ .0 : AnyHashable("+clicked_branch_link")
        - value : "+clicked_branch_link"
      - .1 : 0
    ▿ 1 : 2 elements
      ▿ .0 : AnyHashable("+is_first_session")
        - value : "+is_first_session"
      - .1 : 0

我创建的链接:

 branchUniversalObject = BranchUniversalObject(canonicalIdentifier: "item/1")
        branchUniversalObject.title = "Meet Mr. Squiggles"
        branchUniversalObject.contentDescription = "Your friend Josh has invited you to meet his awesome monster, Mr. Squiggles!"
        branchUniversalObject.imageUrl = "https://example.com/monster-pic-12345.png"
        branchUniversalObject.addMetadataKey("userId", value: "12345")
        branchUniversalObject.addMetadataKey("userName", value: "Josh")
        branchUniversalObject.addMetadataKey("monsterName", value: "Mr. Squiggles")
        branchUniversalObject.addMetadataKey("product_picture", value: "Mr. Squiggles product_picture")

        branchUniversalObject.automaticallyListOnSpotlight = true
        branchUniversalObject.userCompletedAction(BNCRegisterViewEvent)
        linkProperties = BranchLinkProperties()
        linkProperties.feature = "share"
        linkProperties.addControlParam("$desktop_url", withValue: "http://example.com/home")
        linkProperties.addControlParam("$ios_url", withValue: "http://example.com/ios")

branchUniversalObject.getShortUrl(with: linkProperties,  andCallback: { (optUrl: String?, error: Error?) in
            if error == nil, let url = optUrl {
                print("got my Branch link to share: %@", url)
                DispatchQueue.main.async {

                    self.branchUniversalObject.showShareSheet(with: self.linkProperties,
                                                              andShareText: "Super amazing thing I want to share!",
                                                              from: self) { (activity: String?, success: Bool) in
                                                                print("done showing share sheet! : \(success)")
                    }
                }
            }
        })

当应用程序通过 DeepLink 打开时,如何获取添加的 metaDataKey 作为参数,例如:params["product_picture"]

4

1 回答 1

0

来自 Branch 的 Alex here:+clicked_branch_link: 0参数表示 SDK 未检测到该设备的任何链接。这就是您没有取回元数据的原因。

仅当您通过 AirDrop 共享链接时才会出现这种情况?您能否尝试通过 Notes 或 Messages 打开链接,看看您的元数据是否按预期返回?

于 2016-10-07T17:29:15.390 回答