我在 Cordova 框架中使用 React.js 應用程式。
由于檔案不是很清楚,我想了解如何在我的應用程式中呼叫 Branch.io 偵聽器,以便我可以捕獲單擊 Branch.io 鏈接的位置、點擊者以及點擊的確切 URL。必須有一種方法可以從 React 本身呼叫 Branch.io 事件(否則,你怎么能在應用程式中監聽事件?)。我在我的index.js檔案中嘗試了以下內容,但沒有成功,因為 React 應用程式的構建失敗(因為 cordova 僅在運行時可用)。
import {Branch} from "branch-cordova-sdk"
任何幫助,將不勝感激!提前致謝!
uj5u.com熱心網友回復:
對于到達此頁面的其他任何人:
如果您嘗試在 React.js 應用程式(不是 React 本機)中從 Branch.io 生成和訪問分支,并且已將其嵌入到 Cordova 應用程式中,則必須遵循以下檔案:https ://help.branch.io /developers-hub/docs/web-basic-integration
作為快速要點:
- 如檔案中所述,您必須呼叫
index.html檔案中的分支:
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<script>
// load Branch
(function(b,r,a,n,c,h,_,s,d,k){if(!b[n]||!b[n]._q){for(;s<_.length;)c(h,_[s ]);d=r.createElement(a);d.async=1;d.src="https://cdn.branch.io/branch-latest.min.js";k=r.getElementsByTagName(a)[0];k.parentNode.insertBefore(d,k);b[n]=h}})(window,document,"script","branch",function(b,r){b[r]=function(){b._q.push([r,arguments])}},{_q:[],_v:1},"addListener applyCode autoAppIndex banner closeBanner closeJourney creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setBranchViewData setIdentity track validateCode trackCommerceEvent logEvent disableTracking".split(" "), 0);
// init Branch
branch.init('key_live_YOUR_KEY_GOES_HERE');
</script>
</head>
<body>
</body>
</html>
- 然后,在您的 React.js 應用程式上,直接添加分支偵聽器:
function onResume() {
let branch = window.branch;
// Whatever else you want to do when you receive your branch information.
}
只需從那里定義你想對你的分支做什么。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/446987.html
