06-13-2013 03:17 AM - edited 06-13-2013 03:18 AM
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.
Solved! Go to Solution.
06-18-2013 12:36 AM
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!
06-18-2013 11:41 PM
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.