question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

createBranchUniversalObject Error (Ionic)

See original GitHub issue

I have succesfully Initialized and setup deeplinking in my Ionic 3 application like so.

const branchInit = () => {
        if (!platform.is('cordova')) { return }
        Branch.initSession( (data) => {
          console.log('Branch Initialized');
          if (data.$deeplink_path) {
            this.logger.logEvent('deeplink', {});
            console.log('Routing Link' + JSON.stringify(data.$deeplink_path));
            this.routeLink(data.$deeplink_path);
          }
        }).then( () => {
          console.log('Branch Init');
        }).catch( (err) => {
          console.log('Branch Init Error: ' + JSON.stringify(err));
        });
      }

      branchInit();
      Branch.setDebug(true);

And deeplinking works fine if I generate a deeplink from the branch dashboard. But when I try and create a deeplink in app, I recieve an error when calling Branch.createBranchUniversalObject that has no information attached.

		let fakeProps = {
			canonicalIdentifier: "123",
			canonicalUrl: "http://example.com/123",
			title: "Content 123",
			contentDescription: "Content 123 " + Date.now(),
			contentImageUrl: "http://lorempixel.com/400/400",
			price: 12.12,
			currency: "GBD",
			contentIndexingMode: "private",
			contentMetadata: {
				"custom": "data",
				"testing": 123,
				"this_is": true
			}
		};

			Branch.createBranchUniversalObject(fakeProps).then(function (res) {
				this.branchUniversalObj = res
				// alert('Response: ' + JSON.stringify(res))
			}).catch(function (err) {
				console.log('Universal Error: ' + JSON.stringify(err));
				alert('Universal Object Error: ' + JSON.stringify(err))
			});

Always throws

"Universal E
rror: {"__zone_symbol__currentTask":{"type":"microTask","state":"notScheduled
","source":"Promise.then","zone":"angular","cancelFn":null,"runCount":0}

Which seems like a pretty non-usefull error message. Any thoughts?

Edit: If this helps, this is my system information.

Cordova CLI: 6.5.0
Ionic Framework Version: 3.3.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.7
ios-deploy version: 1.9.0
ios-sim version: 5.0.8
OS: macOS Sierra
Node Version: v6.1.0
Xcode version: Xcode 8.3.3 Build version 8E3004b

I could provide y’all with a example app, but I would need to link my branch configuration to it so I would need to send it via email.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
captaincolecommented, Jun 29, 2017

Ok, I figured it out.

What was happening was a incorrect reference to “this.branchUniversalObj” in my code

		Branch.createBranchUniversalObject(fakeProps).then(function(res) {
                        // This is where the error was coming from
			this.branchUniversalObj = res
			// alert('Response: ' + JSON.stringify(res))
		}).catch(function (err) {
			console.log('Universal Error: ' + JSON.stringify(err));
			// alert('Universal Object Error: ' + JSON.stringify(err))
		});

So generally, it came down to an issue of order of operations. Because I wanted to generate the Universal object on page load, and then generate the share URL later, I needed to declare a class scoped variable.

export class ResultPage {

	public result: Result;
	public workout: Workout;
	public loader: Loading;
	public branchUniversalObj: any;
...

Then I reference this and set it up. The correct implementation (and what I think you should change your docs to) is to use an arrow function here to keep the reference to “this” the same.

// Working Sample Code
		Branch.createBranchUniversalObject(fakeProps).then((res) => {
			this.branchUniversalObj = res
			// alert('Response: ' + JSON.stringify(res))
		}).catch(function (err) {
			console.log('Universal Error: ' + JSON.stringify(err));
			// alert('Universal Object Error: ' + JSON.stringify(err))
		});

Thanks for the help, your code helped me find this bug.

0reactions
captaincolecommented, Jun 29, 2017

Seeing as Ionic automatically sets up ts parsing you might as well. No harm unless you need to reference the context of the callback for some reason.

Read more comments on GitHub >

github_iconTop Results From Across the Web

branch.io deeplink not working as expected in ionic 3
I have integrated branch.io deeplink in my ionic 3 application. ... createBranchUniversalObject(properties).then(function (res) ...
Read more >
Cordova PhoneGap Ionic - Branch Help
Complete your Branch Dashboard Cordova and Ionic Change the following values to match your ... createBranchUniversalObject(properties).then(function (res) ...
Read more >
branch-cordova-sdk - npm
This is a repository of our open source Cordova | Phonegap | Ionic SDK, ... you can easily get its success and error...
Read more >
BranchIo | Ionic Documentation
BranchIo. Branch.io is an attribution service for deeplinking and invitation links. https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep- ...
Read more >
Deep Linking implementation in phonegap
cordova plugin add https://github.com/BranchMetrics/cordova-ionic-phonegap- ... createBranchUniversalObject({ canonicalIdentifier : 'identifier', title ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found