我正在尝试在我的应用程序中实现本机应用程序,当我扫描QR时,我可以在没有打开URL的情况下触发分支。
这里我注册了分支
componentDidMount() {
this._unsubscribeFromBranch = branch.subscribe(({ error, params }) => {
if (error) {
console.error("Error from Branch: " + error)
return
}
console.log("Branch params: " + JSON.stringify(params));
if (params) {
this.setState({ scan: { ...this.state.scan, glassHash: params.hash } }, () => {
this._getCurrentPosition();
});
}
});
}
当我用Qr扫描它运行onSuccess函数时我想触发这个没有openURL的branch.subscribe。如果我openURL它工作正常但它不是我想要的
onSuccess(e) {
console.log(e);
// here i want to trigger the branch
this.setState({ barcodeText: e.data });
console.log(e);
}
我在关于BranchEvent的react-native-branch-deep-links文档中找到了,但我没有看到任何关于它的例子。 我发现了这个
new BranchEvent("UserScannedItem", buo).logEvent()
但不确定如何实现自定义事件
答案 0 :(得分:2)
来自Branch的Jackie。
分支链接可以正常运行,并在与QR扫描仪一起使用时保留数据,包括动态查询参数(URL后面附带的参数)。如果使用QR代码打开应用程序,则可以使用getLatestReferringParams()检索会话数据。以下是阅读深层链接数据的示例代码段:
branch.subscribe(({ error, params }) => {
if (error) {
console.error('Error from Branch: ' + error)
return
}
// params will never be null if error is null
})
let lastParams = await branch.getLatestReferringParams() // params from last open
let installParams = await branch.getFirstReferringParams() // params from original install
有关使用getLatestReferringParams处理链接打开的更多信息:https://docs.branch.io/pages/apps/react-native/#using-getlatestreferringparams-to-handle-link-opens
关于自定义事件,这里是使用Branch SDK生成标准和自定义事件的示例类:https://github.com/BranchMetrics/react-native-branch-deep-linking/blob/63cfc566ea45a6af0663fc7530c36fdb5dbf75e6/src/BranchEvent.js
如果您仍然遇到问题,请将带有相关分支链接的示例QR代码的屏幕截图直接发送到support@branch.io,我很乐意进行一些测试!
最佳,
济