Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to avoid handling a deep link twice on cordova android application? #358

Closed
jyothimanchena opened this issue Aug 16, 2017 · 7 comments
Closed

Comments

@jyothimanchena
Copy link

jyothimanchena commented Aug 16, 2017

Hi,

I am facing an issue with regards to branch io deep linking.

Environment: I am using
Android Marshmallow SDK, platform: 25
Cordova 7.0.1 and
Branch SDK
"io.branch.sdk": "~2.2.3"
"branch-cordova-sdk": "^2.2.5",

Below are the scenarions in which im facing issue:

Scenario 1: Calling Branch.InitSession in OnResume call back function.
Failed case:
Steps:

  1. Installed the app for the first time. (Did not open the app)
  2. clicked on Branch IO Deep Link,
  3. It opens up the app on my phone, but does not redirect to the url that is specified in the parameters of the Deep Link, as the InitSession is being called twice.
    a) In the OnDeviceReady call back function.
    b) In the OnResume Function ( This is because, since my app is opening for the first time, it request the user for permission, which pauses the application and resumes when user deny's/ approves the permission calling the onresume method).
  4. Second time when the InitSession is invoked from OnResume call back it recives empty parameters from Deep Link and the application does not redirect to the URL as expected.

Scenario 2: If i remove the Branch.InitSession in OnResume call back fucntion.
Success case: The above scenario works well, if remove the InitSession in OnResume function
Failed case:

  1. Installed the app.
  2. Opened the app and let the app be in the background.
  3. Clicked on a Branch IO deep link.
  4. The application does not recieve the deep link data or the parameters to process the information, since the initsession is not avaible in the onresume method.

Can you please let me know how to handle such a scenario, let me know if i need to publish any further information which might help you in finding if i am implementing it in wrong way.

Thanks & Regards,
Jyothi.

@ethanneff
Copy link
Contributor

Hello,

It looks like you have 2 versions of Branch installed:

"io.branch.sdk": "~2.2.3"
"branch-cordova-sdk": "^2.2.5",

io.branch.sdk is our outdated Branch SDK which is no longer supported. I would recommend following this guide to make sure you are only running one version of the Branch SDK. I would also recommend following the integration guide on this Github's readme.

@jyothimanchena
Copy link
Author

Thank you for the response. I really appreciate that.
We were using io.branch.sdk earlier, but currently we are using "branch-cordova-sdk": "^2.2.5".
As suggested, i have ensured removing the older version of io.branch.sdk and tried with branch-cordova-sdk@2.2.5. But still i am facing the same issue in the scenario's(scenario1 and 2) that i have shared in my post.
This is how i am added branch SDK:
cordova plugin add branch-cordova-sdk@2.2.5 --variable BRANCH_KEY=key_live_XXXXXXXX --variable URI_SCHEME=xxxx

Also, I tried with the latest version of branch sdk version 2.6.0 and modified the in config.xml

<branch-config>
    <branch-key value="key_live_xxxxxxxxxxxx" />
    <uri-scheme value="xxxxx" />
    <link-domain value="xxxxx.app.link" />
    <android-prefix value="/U09p" />
</branch-config>

But cordova build android is throwing an error:

Error: BRANCH SDK: Invalid "id" or "ios-CFBundleIdentifier" in in your config.xml. Docs https://goo.gl/GijGKP.

Please let me know if i have missed anything.

@jyothimanchena
Copy link
Author

jyothimanchena commented Aug 18, 2017

I have modified the config.xml to add the latest sdk.
plugin name="branch-cordova-sdk" spec="^2.6.0"

@ethanneff
Copy link
Contributor

ethanneff commented Aug 18, 2017

Hello hello,

Unfortunately, Branch no longer supports installing the SDK from the CLI:

cordova plugin add branch-cordova-sdk@2.2.5 --variable BRANCH_KEY=key_live_XXXXXXXX --variable URI_SCHEME=xxxx

This is a remnant of our old our SDK (io.branch.sdk) which we had to deprecate. The Branch SDK now installs from your config.xml (we had to do this to support all the flavors of Cordova including Ionic Cloud and PhoneGap Build).

<!-- config.xml -->
<plugin name="branch-cordova-sdk" spec="^2.6.0" />

@ethanneff
Copy link
Contributor

The error you are receiving is because Android does not accept hyphens and iOS does not accept underscores as a bundle id (also known as a package name or widget id). This is a restriction of the devices.

If you are reliant on a hyphen or underscore, then you will need to update your config.xml to include something like this:

<widget ios-CFBundleIdentifier="com.eneff.branch.cordovatestbedios" android-packageName="com.eneff.branch.cordovatestbedandroid" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking#testing-optional-app-config

Thanks,

@jyothimanchena
Copy link
Author

jyothimanchena commented Aug 23, 2017

Hi ethan,

Thanks for your response,
As you said before i installed Branch SDK from my config.xml
(<plugin name="branch-cordova-sdk" spec="^2.6.0"/> ),and also i updated my config.xml to include this
(<widget ios-CFBundleIdentifier="com.eneff.branch.cordovatestbedios" android-packageName="com.eneff.branch.cordovatestbedandroid" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> .
But still I'm facing issue in the two scenarios as I mentioned earlier,
Below are the two scenarios

The main issue I'm facing in this case is, initsession gets called twice , once on deviceready and in on resume when my application request access permission for the first time .And when the initsession gets called in on resume, the result data is empty

Below are the scenarions in which im facing issue:

Scenario 1: Calling Branch.InitSession in OnResume call back function.
Failed case:
Steps:

Installed the app for the first time. (Did not open the app)
clicked on Branch IO Deep Link,
It opens up the app on my phone, but does not redirect to the url that is specified in the parameters of the Deep Link, as the InitSession is being called twice.
a) In the OnDeviceReady call back function.
b) In the OnResume Function ( This is because, since my app is opening for the first time, it request the user for permission, which pauses the application and resumes when user deny's/ approves the permission calling the onresume method).
Second time when the InitSession is invoked from OnResume call back it recives empty parameters from Deep Link and the application does not redirect to the URL as expected.

Scenario 2: If i remove the Branch.InitSession in OnResume call back fucntion.
Success case: The above scenario works well, if remove the InitSession in OnResume function
Failed case:

Installed the app.
Opened the app and let the app be in the background.
Clicked on a Branch IO deep link.
The application does not recieve the deep link data or the parameters to process the information, since the initsession is not avaible in the onresume method.

Can you please let me know how to handle such a scenario, let me know if i need to publish any further information which might help you in finding if i am implementing it in wrong way.

Thanks & Regards,
Jyothi.

@ethanneff
Copy link
Contributor

Hello,

Thank you for bringing this to my attention. Yes, the branch.initSession() will be called whenever you ask for device access permission because this functionality is handled on the device level and not the app (which triggers the app delegates again where the branch.initSession() resides at).

Whenever your branch.initSession() gets called twice, does data come back empty both times after a Branch deep link click? If not, you can do something like the following so you will not see the branch.initSession() called twice or come back empty:

Branch.initSession(function(data) {
  if (data['+clicked_branch_link']) {
    // read deep link data on click
    alert('Deep Link Data: ' + JSON.stringify(data));
  }
});

Let me know if this fixes your issues and I'll update the readme guide.

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants