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
Highlighted
Contributor
Posts: 12
Registered: ‎06-04-2013
My Device: Z10
My Carrier: Vodafone
Accepted Solution

Prevent application from loading if user is offline

[ Edited ]

Hi,

 

I was wondering if there was a way to prevent the user from accessing a web app wrapped in webworks if they initiate the app without a data connection.

 

I have added event listeners to the window if a user is in the app and goes offline/comes back online.

 

I would like to stop at the splash screen and display an informative message.

 

I don't have time in my current project to implment offline caching etc so was hoping for this as a quick fix despite hampering the UX.

 

AM using BB10 on a Z10 with latest webworks SDK also.

Retired
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: Prevent application from loading if user is offline

You can try the simple window.navigator.onLine property which returns a boolean representing whether the user is connected to the internet or not.  I'm not entire sure how reliable that API is so you'll have to test it.

 

If it doesn't give you the result you need, there's also the WebWorks extension blackberry.connection.  You can have a gander at the API here.  You can query blackberry.connection.type and if it returns the string constant blackberry.connection.NONE, then the user isn't connected.  There's also a connection change event you can listen to when the connection of the user changes (whether connecting or disconnecting from the internet or changing how they're connected).

 

Hope that helps!

------------------------------
@grahamzibar
-_- zZZ
Retired
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: Prevent application from loading if user is offline

Was this of any help?

------------------------------
@grahamzibar
-_- zZZ
Contributor
Posts: 12
Registered: ‎06-04-2013
My Device: Z10
My Carrier: Vodafone

Re: Prevent application from loading if user is offline

I tried using the navigator object but it did not seem to detect it on first load of the app.

 

Also it did not switch the value when going from offline to online in the app itself so have just left the online/offline detection to the event listeners for now until i have time to figure out a better solution.