react-native-branch-deep-linking-attribution
react-native-branch-deep-linking-attribution copied to clipboard
Android only issue with initialising when no network
I use Netinfo to monitor network connectivity and subscribe/unsubscribe to branch when the network connects/disconnects. The code snippet is here:
async componentDidMount() {
const netState = await NetInfo.fetch();
if(netState.isConnected === true){
this.subscribeBranch();
}
this.unsubscribeNetInfo = NetInfo.addEventListener(state => {
if (state.isConnected === false) {
if (this.unsubscribeBranch !== null) {
this.unsubscribeBranch();
}
} else if (
state.isConnected === true
) {
setTimeout(()=>{
this.subscribeBranch();
},6000)
}
});
}
subscribeBranch() {
this.unsubscribeBranch = branch.subscribe(async ({error, params, uri}) => {
if (error) {
console.error('Error from Branch: ' + error);
return;
}
// params will never be null if error is null
if (params['+non_branch_link']) {
const nonBranchUrl = params['+non_branch_link'];
// Route non-Branch URL if appropriate.
return;
}
if (!params['+clicked_branch_link']) {
// Indicates initialization success and some other conditions.
// No link was opened.
return;
}
// A Branch link was opened.
// Route link based on data in params, e.g.
});
}
In Android,
- The app is killed
- I disable all network and start the app
- Since there is no data network and Wifi, branch subscribe is not called and ’No Internet Connection’ screen is displayed
- Now if I enable the Wifi, branch subscribe in the NetInfo callback is called and we get the error seen in screenshot_1 attached with this mail. As you may see from the gist, I also delayed the subscribe call with a timer but to no avail.
- The code in MainActivity.java is here :
@Override
protected void onCreate(Bundle savedInstanceState) {
// Use SplashTheme in AndroidManifest.xml for MainActivity, themes loads before layouts inflate
setTheme(R.style.AppTheme); // Now set the theme from Splash to App before setContentView
setContentView(R.layout.launch_screen); // Then inflate the new view
SplashScreen.show(this, true);
super.onCreate(savedInstanceState);
if (!isTaskRoot()) {
finish();
return;
}
}
// Override onStart, onNewIntent:
@Override
protected void onStart() {
super.onStart();
RNBranchModule.initSession(getIntent().getData(), this);
}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
This happens only for Android and iOS is working fine. I am on React Native: 0.61.5 and react-native-branch: 4.4.0
Did you ever find a workaround for this?
After some more testing it looks like the SDK becomes completely unresponsive if there is any error until the next time the app is foregrounded https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/issues/659
The unsubscribe function also doesn't work. It leaks a reference to your previous callback so two callbacks will be called next time you foreground the app.