Start a new topic

Cannot Communicate Between ARchitect World and Cordova/Phonegap plugin

I have integrated the plugin from https://github.com/Wikitude/wikitude-cordova-plugin into an angular/ionic application. I am using the plugin with this ionic app https://github.com/pbreuss/wikitude-ionic-2-starter-app. The ARchitect world works great as expected while I'm in the AR camera view, however I cannot communicate between the Architect World and my cordova app. I've reviewed the article here, http://www.wikitude.com/external/doc/documentation/latest/phonegap/setupguidecordovacli.html#adding-communication-between-cordova-and-architect and cannot get it to work. I am testing on an iPad mini running iOS version 11.1. Here is what i've tried.


Solution 1:

inside interactivity.js file


 goBack: function() {

     alert("BYE");

        document.location = "architectsdk://back";

    }


inside cordova/ionic ar-view.ts file


WikitudePlugin.setOnUrlInvokeCallback(function() {

      alert("HI");

    });


Result: The alert for BYE is triggered. Alert for setOnUrlInvokeCallback is NOT triggered.


Solution 2:

inside interactivity.js file

 goBack: function() {

     alert("BYE");

      AR.platform.sendJSONObject({

         action: "back"

      });

}


inside cordova/ionic ar-view.ts file


WikitudePlugin.setJSONObjectReceivedCallback(function() {

      alert("HI");

    });


Result: The alert for BYE is triggered. Alert for setJSONObjectReceivedCallback is NOT triggered.


Wikitude Cordova plugin version = 7.1.0

Ionic version = 3.0.1

My questions are:

1. Why can't I communicate between the AR World view and my cordova/ionic app? 

2. Can you please advise on the next steps?


1 person has this problem

Hello Danika,



we do have two sample worlds that use the AR.platform.sendJSONObject function: Displaying Native Detail Screen and Capture Screen Bonus. Would you mind trying these samples and checking whether they work for you?


I'd like you to try them from the Cordova sample app on the device you are using and, should they work, try to integrate them into your Angular/Ionic app.



- Daniel


Hi Daniel. I did get this working. The issue was I thought it was not working because it takes multiple clicks and a long timeout for the plugin to call either URLCallback or JSONReceived functions. I'm getting the alerts immediately, however the onJSONObjectReceived takes anywhere from 10 - 30 seconds to respond. Sometimes I have to click it 2-3 times before it will respond at all, all the while I get the alert each time the DOM element is clicked. Not sure if this is related, but I'm getting this message in the Xcode console, 2017-11-10 23:22:18.092716-0600 MyApp[5870:2181189] THREAD WARNING: ['WikitudePlugin'] took '420.012939' ms. Plugin should use a background thread. Do you know of any issues where the clicks are taking a long time to respond?

I ended up fixing all of my issues. There is still an issue where setOnUrlInvokeCallback and setJSONObjectReceivedCallback get triggered multiple times. Every times I navigate to the AR View, then trigger one of these functions, they are triggered the same amount of times I have gone to AR View. For example, First time open of AR View -> setOnUrlInvokeCallback is called once. Call WikitudePlugin.show() to show the AR View for 2nd time -> setOnUrlInvokeCallback is called twice. Call WikitudePlugin.show() to show the AR View for 3nd time -> setOnUrlInvokeCallback is called 3 times. I did put in a workout, however i'm still not actually sure why this happens. Thanks for all of your help!

Hello Danika,


We are having a similar issue as the original one (Clicking multiple times on a button inside the AR view before it sends data to the app).


Could you tell us how you managed to fix the issue?

Hello, I have the same problem, sendJSONObject does not work well, could you help me?
Login or Signup to post a comment