kevinstumpf / react-native-branch

Native Wrapper around Branch Metrics native SDKs
MIT License
20 stars 12 forks source link

How to listen for links #7

Closed rt2zz closed 8 years ago

rt2zz commented 8 years ago

My implementation right now (iOS) listens looks something like this:

componentDidMount(){
  Linking.addEventListener('url', this.processBranch)
  Linking.getInitialURL().then(this.processBranch)
}

processBranch(){
    branch.getLatestReferringParams((params) => {
      console.log('branch params:', params)
    })
}

The problem is I am getting the stale params from the last link instead of the current link. If I for example setTimeout 1000 before calling getLatestReferringParams then I get the current link.

This makes sense as the sdk I imagine needs to make an async call to resolve the uri into a dictionary of params. If this is the case, how can I listen for some sort of "inbound link" event?

kevinstumpf commented 8 years ago

How would you do it if you were to implement it natively? If the native SDK supports this use case we can probably easily expose it to React Native.

Without having dug deeper into it, a very hacky but working solution would be to continuously (setTimeout(.., 100)) check for the latestReferringParams and compare them to the stale dictionary. If the params are different, you received the new one.

On Wed, Mar 30, 2016 at 1:48 PM, Zack Story notifications@github.com wrote:

My implementation right now (iOS) listens looks something like this:

componentDidMount(){ Linking.addEventListener('url', this.processBranch) Linking.getInitialURL().then(this.processBranch) } processBranch(){ branch.getLatestReferringParams((params) => { console.log('branch params:', params) }) }

The problem is I am getting the stale params from the last link instead of the current link. If I for example setTimeout 1000 before calling getLatestReferringParams then I get the current link.

This makes sense as the sdk I imagine needs to make an async call to resolve the uri into a dictionary of params. If this is the case, how can I listen for some sort of "inbound link" event?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/DispatcherInc/react-native-branch/issues/7

rt2zz commented 8 years ago

@kevinstumpf are you using this in an app? I guess my confusion is that I see no way to get utility out of the module without having this sort of listener. While polling could very well work, presumably it would be nice to have a first class solution to (what I assume is) the primary use case of the module.

I will submit a PR, I think that will help communicate my thoughts. Thanks for the great work!

kevinstumpf commented 8 years ago

Hey @rt2zz -- sorry I didn't see your question until just now.

Please refer to https://github.com/BranchMetrics/React-Native-Deep-Linking-SDK -- Our friends at Branch took this repo over.

(To answer your question: We are using this implementation in our app. We built it mainly for the purpose of tracking installs by campaign and pre-populating a driver's sign-up form. Hence we didn't wrap the rest of the Branch functionality, including the feature you asked for)