Here is the goal:
A farmer has a smartphone and goes into his barn to take inventory with the app. Sometimes his phone does not get internet connection in the barn, so the app needs to work offline, store data offline, and then sync it to the cloud once it is reconnected.
The farmer should also have to only login and register the app once, and then each time they open the app, it should just open to the home screen and not ask for login info ever again. How exactly could this be done?
I am using Meteor to make the app, and Meteor's built in Cordova to package the app. I have seen GroundDB: https://github.com/GroundMeteor/db
As far as I can tell in the docs, I know how to create a local collection and use collection.insert to add data to that collection.
But I am lost as to how to code the app to open on the phone without needing internet, and detecting if internet is present or not?
Then how do I detect if internet has come back, and then sync all the data stored in offline mode?
If someone can help lay out how this would work that would be greatly appreciated!
With Meteor you should use Meteor.status() which return a object of this form :
Object {status: "connected", connected: true, retryCount: 0}
connected will be obviously false if you lost the connection.
It's better than the jQuery or cordova approach because it will handle lost of connection with the meteor server thus also server or network failure not only the internet status.
Use code like this to detect offline/online
jQuery(window).on('offline', function (e) {
console.log('offline');
}).on('online', function (e) {
console.log('online');
});
You could also combine it with this plugin https://github.com/apache/cordova-plugin-network-information/blob/master/doc/index.md to determine more information about the networks status if required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With