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

Cold Start #397

Closed
myrsk opened this issue Nov 21, 2017 · 5 comments
Closed

Cold Start #397

myrsk opened this issue Nov 21, 2017 · 5 comments

Comments

@myrsk
Copy link

myrsk commented Nov 21, 2017

When the app is in the background and I open a deeplink, it brings the app up and goes to the page requested.

this.platform.ready().then(() => {
      this.statusBar.overlaysWebView(false);
      this.statusBar.backgroundColorByHexString('#222');

      this.splashScreen.hide();

      this.setRootPage();
      handleBranch();
    });

this.platform.resume.subscribe(() => {
      handleBranch();
    });

const handleBranch = () => {
      // only on devices
      if (!this.platform.is('cordova')) { return }
      const Branch = window['Branch'];
      Branch.initSession(data => {
        if (data['+clicked_branch_link']) {
          // read deep link data on click
          //alert('Deep Link Data: ' + JSON.stringify(data));
          this.nav.push(data['page'],{itemId:data['id']});
        }
      });
    }

However, if i force quit the app, and then click on a deeplink, it opens the app and stays on the root page.

Any ideas?

@thkuberlin
Copy link

did you try to look at the outputs given with Branch.setDebug(true) before your initSession code?

@myrsk
Copy link
Author

myrsk commented Nov 22, 2017

There seems to be no errors.

When i put the line below, i actually get the alert just fine.

alert('Deep Link Data: ' + JSON.stringify(data));

So i presume the following code doesnt execute in the order set. How do i wait for the top before running the second? confused

this.setRootPage();
handleBranch()

@myrsk
Copy link
Author

myrsk commented Nov 22, 2017

Just tried to test it on an android device, and works fine - even on a cold start.

So the issue remains just for ios.

@myrsk
Copy link
Author

myrsk commented Nov 25, 2017

Okay, in case anyone faces the same issue. Just delay branch in this.platform.ready. I have delayed it by a second - since everything is async, I do not think it will have an impact. I have tested it and it works fine.

handleBranch();

@ethanneff
Copy link
Contributor

Hello,

Good find and good solution. It appears this.setRootPage(); is an Ionic method which creates a new instance of the page. This method must have some funky behavior interally which creates a race condition with the Branch initialization.

Another solution besides timeouts would be to place the handleBranch() within the done parameter of setRoot() (docs). However, this depends on which version of the Ionic SDK you are using.

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

3 participants