react-native-branch-deep-linking-attribution
react-native-branch-deep-linking-attribution copied to clipboard
[Android] .subscribe returns empty params on foreground.
related to #41
I'm trying to deeplink into in-app content from a push notification that is received when the app is on foreground.
but branch.subscribe
returns empty params on foreground, as I commented on android sdk issue
apparently, the issue seems to be fixed in the newer android sdk releases. so I upgraded it to v3.2.0 but it still returns empty params. If anyone knows what I'm missing or how to fix, please let me know!
Expect it returns
params: { '+clicked_branch_link': true, ...etc }
but it returns params: { }
I'd appreciate if you tell me how to get params on foreground. Thanks
Hallo @jdee I wanna upgrade the android sdk to newer than v3.1.1 because I guess that will fix my issue. https://github.com/BranchMetrics/android-branch-deep-linking-attribution/releases/tag/3.1.1
Added support for push notifications while the application is in the foreground
And I made some changes in build.gradle
file to upgrade, but still foreground deep linking doesn't seem to work. so I'd really appreciate it if you could tell me what I'm missing to upgrade it properly.
https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/releases/tag/v3.0.1
Uses native Branch SDKs 3.2.0 (Android), 0.27.0 (iOS).
Here is the diff that I made to upgrade.
- package.json
- "react-native-branch": "2.3.4",
+ "react-native-branch": "^3.0.1",
- app/build.gradle
dependencies {
- implementation fileTree(dir: "libs", include: ["*.jar"])
api project(':react-native-branch')
- api "io.branch.sdk.android:library:2.+"
+ api "io.branch.sdk.android:library:3.2.+"
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support' &&
(requested.name != 'multidex' && requested.name != 'multidex-instrumentation')) {
project.logger.lifecycle(requested.name)
details.useVersion "${rootProject.ext.supportLibVersion}"
}
if (details.requested.group == 'io.branch.sdk.android') {
- details.useVersion "2.+"
+ details.useVersion "3.2.+"
}
}
}
Let me know if there are any commands to run or any other steps to do! Thank you
@shuzootani As long as you're using react-native-branch >= 3.0.1, you should automatically get version 3.2.0 of the Android SDK. Version 4.0.0 was just released with support for RN 0.60. If you're using RN < 0.60, please continue using react-native-branch@^3.0.1, as you have it.
I haven't used push notifications with Branch before, but I know there are some extra fields to set. See https://github.com/BranchMetrics/android-branch-deep-linking-attribution#deeplink-via-push-notification. I think those correspond to extra fields in the GCM JSON payload if you do a POST, but I'm not sure.
You could try this to see if it helps:
branch.subscribe(({params, error}) => {
const lastParams = await branch.getLatestReferringParams()
// lastParams should == params, but maybe there is a difference here for some reason?
})
@jdee Not helped your code, The same issue in Foreground, I am getting the null params on calling Branch.subscribe in Android.
new Promise(function (resolve, reject) { this.unsubscribeFromBranch = Branch.subscribe(({ error, params }) => { unsubscribeFromBranch(); setTimeout(function () { if (error) { console.info('error', error); } reject(error) }, 5000); resolve(params) }); });
hmm... maybe I'm using Braze SDK and Branch together. so that might cause the issue? I ended up handling foreground deep-linking with fcm event listener and redux. But I'd appreciate it if you let me know any updates on this issue!
@shuzootani I have been stuck on the same issue. Did you find any solution?
@kyo504 I ended up with some tricky workaround, which I'm not sure if it works for you.
but here is what I did.
I'm using firebase FCM to handle notifications.
so when it receives foreground notification, I store the branch-deeplink in redux temporarily. and in branch.subscribe()
, I check redux store if there is any deeplink to open, open branch link again if necessary by calling branch.openURL(deeplink-stored-in-redux-store)
, which triggers branch.subscribe()
again with some params that I need.
like this
// FCM.handleMessageReceived() callback
const handleMessageReceived = (message) => {
const { uri } = message.data
if (uri) {
console.log('new notification received on foreground', message)
store.dispatch(notificationReceived(uri))
}
}
branch.subscribe(({ error, params }) => {
const notification = reduxStore.getState().get('notification')
if (notification.deeplink) {
dispatch(remove opened-deeplink action), otherwise `branch.openURL()` triggers `branch.subscribe` recursively.
branch.openURL(notification.deeplink)
}
})
@shuzootani Thanks for your tip. It didn't fit to me but it gave me some insights to solve my problem.
Any updates?