我在初始化 react-native-branch 5.0.0 SDK 時遇到問題。在主 App 組件的 useEffect 中呼叫 Branch.subscribe() 后:
useEffect(() => {
Branch.subscribe(({ error, response }) => {
console.log(error, "error");
console.log(response, "response");
});
}, []);
控制臺記錄了以下錯誤
Trouble initializing Branch. Branch API Error: Please enter your branch_key in your project's manifest file first
我已按照檔案中的步驟安裝和配置 SDK,但我不知道自己出了什么問題。
這是我的 AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.****.*********">
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
...
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="myappuri" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch App Links -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="myactualappname.app.link" />
</intent-filter>
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_*********"/>
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_*******"/>
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
...
</activity>
</manifest>
在 MainActivity 我有:
import io.branch.rnbranch.*;
import android.content.Intent;
...
public class MainActivity extends ReactActivity {
// Override onStart, onNewIntent:
@Override
protected void onStart() {
super.onStart();
RNBranchModule.initSession(getIntent().getData(), this);
}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent != null &&
intent.hasExtra("branch_force_new_session") &&
intent.getBooleanExtra("branch_force_new_session",false)) {
RNBranchModule.onNewIntent(intent);
}
}
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "main";
}
}
和 MainApplication
...
import io.branch.rnbranch.RNBranchModule;
public class MainApplication extends Application implements ReactApplication {
...
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
ApplicationLifecycleDispatcher.onApplicationCreate(this);
RNBranchModule.getAutoInstance(this);
}
...
}
我嘗試在儀表板中重置 branch_key,但結果是一樣的。
uj5u.com熱心網友回復:
首先,清單中缺少“應用程式”標簽。其次,分支鍵應該在“活動”標簽之外。請按照以下網址中的說明進行操作,您的應用程式將正常運行。
https://help.branch.io/developers-hub/docs/android-basic-integration
以下是您的清單應如何顯示:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.****.*********">
<application
android:allowBackup="true"
android:name="com.eneff.branch.example.android.CustomApplicationClass"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- Launcher Activity to handle incoming Branch intents -->
<activity
android:name=".LauncherActivity"
android:launchMode="singleTask"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="yourapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch App Links -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="example.app.link" />
<!-- example-alternate domain is required for App Links when the Journeys/Web SDK and Deepviews are used inside your website. -->
<data android:scheme="https" android:host="example-alternate.app.link" />
</intent-filter>
</activity>
<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_*********"/>
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_*******"/>
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
</application>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/454505.html
上一篇:1單擊后如何禁用按鈕?
下一篇:在反應本機組件中更新狀態的問題
