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
Developer
Boliver15
Posts: 25
Registered: ‎04-30-2011
My Device: Z10
My Carrier: AT&T

How to create an app that checks a server

I'm creating an html5 app and I want to reguarly update the app with an element of news content. How can I make this possible without having the user constantly updating the app to get the latest info.

 

I heard that I can point the app to a server and have it constantly check for the latest version. Could someone point me in the right direction to do this please!

 

Thanks in advance

Please use plain text.
Developer
supraking
Posts: 99
Registered: ‎10-04-2010
My Device: Not Specified

Re: How to create an app that checks a server

To be clear, do you only want it to update while the app is open and running, or when it's closed (as a background service, of sorts)? For example, you close Twitter but can configure it to refresh in the background and notify you of updates. Not sure if this is possible with WebWorks apps, perhaps someone can chime in?

 

Take a look at the API reference for push, maybe you'll find some more info in there.

 

https://bdsc.webapps.blackberry.com/html5/apis/blackberry.push.html

Please use plain text.
Developer
Boliver15
Posts: 25
Registered: ‎04-30-2011
My Device: Z10
My Carrier: AT&T

Re: How to create an app that checks a server

I just want it to refresh when opened. Check for the latest updates . I do not want it to refresh in the background 

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

Re: How to create an app that checks a server

Hello all,

 

In order to perform an action when your application loads, you can register an event listener. For instance:

 

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <!-- Put your HTML stuff here -->
        <script type="text/javascript">
            function ready() {
                // Do stuff here on load.
                window.removeEventListener("DOMContentLoaded", ready, false);
            }
            window.addEventListener("DOMContentLoaded", ready, false);
        </script>
    </body>
</html>

 Basically, we define the ready function inside our script, but it doesn't get executed until the DOMContentLoaded event is triggered, which we start listening for after we define the ready function. Once we perform all of our actions, we unregister the listener to free up resources.

 

In place of // Do stuff here on load. you could leverage an XMLHttpRequest object to communicate with your backend server; the server would then respond with any specific data.

 

You would need to format your request, and subsequent response data in a way that would be meaningful to your application.


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.
New Developer
seyz4all
Posts: 11
Registered: ‎03-10-2012
My Device: Bold 3
My Carrier: Airtel Nigeria

Re: How to create an app that checks a server

I have created a webworks app that does that.

 

My app gets news from a RSS Feed.

 

I created a function that clears cache and refereshes the page as soon as the page loads, so that you would have the latest news.

 

But in your case you want to get your data from a database hosted remotely, am i correct ?

 

Signify so i that i can help you out with this.

Please use plain text.
Developer
Boliver15
Posts: 25
Registered: ‎04-30-2011
My Device: Z10
My Carrier: AT&T

Re: How to create an app that checks a server

That would be actually be perfect. All it would need to do is get information from an RSS feed.

How can I go about this?

Thanks for all the help!
Please use plain text.
New Developer
seyz4all
Posts: 11
Registered: ‎03-10-2012
My Device: Bold 3
My Carrier: Airtel Nigeria

Re: How to create an app that checks a server

Checkout the zip file, i have attached my working solution here. I hope this helps you.

 

Changes you can make

 

test.html

1. On line 38 and 45 change the url of the feeds to your own feed.

 

2. On line 85, you can set the delay time

 

3. On line 89, change the " if(!online) {   to if (!blackberry.system.hasDataCoverage()) { ", in order for it to check for internet connection on the device.

 

The if(!online) works for your Desktop web browser, so you have to change it to the one above for it to work. you can check the file i commented it there.

 

4. <meta http-equiv="Cache-control" content="no-cache"> is located at the top in the head, this makes sure the current page does not store cache.

 

You can also check the RSS plugin script to edit. (FeedEk.js)

 

There is also a blink jquery script for loading text blinking when loading.

 

If you need any assistance, just holla

Please use plain text.
Developer
Boliver15
Posts: 25
Registered: ‎04-30-2011
My Device: Z10
My Carrier: AT&T

Re: How to create an app that checks a server

Thank You for the file!

 

How did you learn about this "xmlhttprequest" function?

Please use plain text.
New Developer
seyz4all
Posts: 11
Registered: ‎03-10-2012
My Device: Bold 3
My Carrier: Airtel Nigeria

Re: How to create an app that checks a server

Actually its javascript function used to fetch data remotely...were u able to make use of the script?
Please use plain text.
Developer
Boliver15
Posts: 25
Registered: ‎04-30-2011
My Device: Z10
My Carrier: AT&T

Re: How to create an app that checks a server

Yes... I changed the lines that you told me to change and it all worked perfectly. I am adding a few things to my app and I shoul be able to test it soon.

 

Thanks for the help.

 

Please use plain text.