Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
mavi2312
Posts: 18
Registered: ‎09-18-2013
My Device: Developer
My Carrier: Non-BlackBerry user
Accepted Solution

WebWorks app not recognizing the Blackberry plugin app

[ Edited ]

Hello! I'm porting an Android webapp to WebWorks. My Android app uses Phonegap, so when I found out that the new WebWorks used it to, it was a great relief. But the problem came when I tried to use the BlackBerry push service, because the application for some strange reason is not recognizing the plugins I installed via console, just as the documentation says http://developer.blackberry.com/html5/apis/beta/blackberry.app.html.

 

Since then I took away everything that belonged to the push service and I installed the com.blackberry.app plugin to test the ways they're supposed to work. So I debugged it in the Web Inspector and got this message.

 

ReferenceError: Can't find variable: blackberry 

 

This error came from this line in my code:

 

console.log("The screen status is: "+blackberry.app.windowState);

 

In my config.xml file I have the line:

 

<feature id="blackberry.app"/>


I'm new at this platform and I'm not sure if the plugins need to be called somewhere inside the html file or the js for it to work. Or is there something else wrong about the way I use the plugins?

 

BTW: my app is using the latest cordova because I'm developing it from the WebWorks SDK 2.0.0.54, but my Android app used Cordova 2.0.0, and this library gets called in the html. So, when I tried to change the cordova file to the latest one, the app didn't work, so I left it where it was.

 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: WebWorks app not recognizing the Blackberry plugin app

Cordova 2.0 is very different from Cordova 3.0; where BlackBerry 10 integration is fully found. If you're using the old Cordova, you'll need to include webworks.js which is packaged with the legacy WebWorks SDK v1.0.

https://developer.blackberry.com/html5/download/

 

If you're going with the legacy SDK, you'll need to include webworks.js (in addition to cordova.js), add the <feature> elements to your config.xml, and wait for the webworksready event to fire before using any BlackBerry APIs.

 

If you are using the most recent Cordova version (recommended), you'll need to include just cordova.js, add the plugins as you have, and wait for the deviceready event to fire before using any BlackBerry APIs.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Contributor
mavi2312
Posts: 18
Registered: ‎09-18-2013
My Device: Developer
My Carrier: Non-BlackBerry user

Re: WebWorks app not recognizing the Blackberry plugin app

I made some changes like calling the cordova 3.2 script before every .js script I use in the index.html file (I'm no longer using the cordova.2.0.0 that I said on the last post). After doing that the app started to work and recognized "blackberry". But the problem is that the deviceready event its not being called every time the app starts, sometimes it gives me this message in the console:

 

deviceready has not fired after 5 seconds.
Channel not fired: onNativeReady
Channel not fired: onPluginsReady
Channel not fired: onCordovaReady
 
I've been investigating this error and in a few pages it said it had to do with the JQM init(); but I'm not sure why it happens. Any ideas?
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: WebWorks app not recognizing the Blackberry plugin app

In the standard Cordova application, the app calls app.initialize as follows (extra code left in to show placement of the call and required scripts):

 

        ...
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>
    </body>
</html>

 

Which is defined in index.js as follows:

 

    initialize: function() {
        this.bindEvents();
    },

 

Which subsequently calls bindEvents

 

    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },

 

And registers the deviceready event listener on the document. This is a Cordova event and will only fire after cordova.js has loaded and initialized.

 

Upon triggering, index.js continues to handle the event here:

 

    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },

 

And we can see that receivedEvent can be used as a central event handler if we so desire.

 

    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }

 

Note that the code inside of receivedEvent is specific to the default sample application.

 

 

If you are customizing the code, it's important not to break the chain. Specifically up to the point of adding the deviceready listener. Of course, there are other ways to get to that point, but if we're seeing issues, it's best to go back to the most basic sample.

 

If Cordova is indicating that it hasn't fired within 5 seconds, there is either a lot of loading going on, or  Cordova did not properly load to the point where it can fire the event.

 

If you connect Web Inspector and then press ctrl+r in Web Inspector to reload the application, does the Console show any additional failures? (This will allow the log to show all output from the very beginning of execution.)

 

Perhaps in the Network panel, are there any resources that failed to load?


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Contributor
mavi2312
Posts: 18
Registered: ‎09-18-2013
My Device: Developer
My Carrier: Non-BlackBerry user

Re: WebWorks app not recognizing the Blackberry plugin app

Hi! Thanks for the reply :smileyhappy: the problem stopped showing when I moved the "addEventeListener('deviceready',function,false)" from index.js and put it in index.html as a script (like the app.initialize() that you showed me). After that deviceready does get fired and the blackberry.app plugin seems to work fine :smileyhappy: I'll keep in mind what you said for future apps.

 

I still have other problems but I'll start an other thread to ask for help with that. 

Please use plain text.