我一直在 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"]